Posts

Showing posts with the label Java interview Questions and Answers

String based Java Interview questions and answers

Image
Difference between String, String Builder, and String Buffer. Ans: String:  String variables are stored in “constant string pool”. Once the string reference changes the old value that exists in the “constant string pool”, it cannot be erased. Example: String name = “book”; Constant string pool . If the name value has changed from “book” to “pen”. Constant string pool Then the older value retains in the constant string pool. String Buffer: Here string values are stored in a stack. If the values are changed then the new value replaces the older value. The string buffer is synchronized which is thread-safe. Performance is slower than the String Builder. Example: String Buffer name =”book”; Once the name value has been changed to “pen” then the “book” is erased in the stack. String Builder: This is same as String Buffer except for the String Builder which is not threaded safety that is not synchronized. So obviously performance is fast.

Oops based Java Interview Questions and Answers

Image
Class and Object : constructor, local and instance variable,  What do you mean by Constructor? Ans: The points given below explain what a Constructor is in detail: When a new object is created in a program a constructor gets invoked corresponding to the class. The constructor is a method which has the same name as class name. If a user doesn’t create a constructor implicitly a default constructor will be created. The constructor can be overloaded. If the user created a constructor with a parameter then he should create another constructor explicitly without a parameter. What is meant by Local variable and Instance variable? Ans: Local variables  are defined in the method and scope of the variables that have existed inside the method itself. An instance variable  is defined inside the class and outside the method and scope of the variables exist throughout the class. What is a Class? Ans:  All Java codes are defined in a class. A Class has vari...