Here is a collection of frequently asked java questions in technical interviews. All Java questions are provided with appropriate answers. If you find any answer is not correct, do comment in the comments section (scroll down).
Note: Click the question or click on the arrow to see the answer for a question.
Question and Answers
String s1 = new String("hello");
String s2 = new String("hello");
If we compare s1 and s2 as s1==s2, it evaluates to false as s1 and s2 reference separate memory locations (objects). To compare the string content we have to write s1.equals(s2). It evaluates to true.
In the above example mypack is the name of our package.