0% found this document useful (0 votes)
4 views2 pages

R 39

The document contains a series of core Java interview questions and answers, covering topics such as the Object class, String vs. StringBuffer, and the Collection API. Key differences between various Java collections and data structures, such as ArrayList and Vector, as well as Hashtable and HashMap, are also discussed. Additionally, it highlights the importance of using the 'equals()' method for comparing strings over the '==' operator.

Uploaded by

swoobhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

R 39

The document contains a series of core Java interview questions and answers, covering topics such as the Object class, String vs. StringBuffer, and the Collection API. Key differences between various Java collections and data structures, such as ArrayList and Vector, as well as Hashtable and HashMap, are also discussed. Additionally, it highlights the importance of using the 'equals()' method for comparing strings over the '==' operator.

Uploaded by

swoobhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Core Java Interview Question Page 32

java.lang & java.util Packages

Question: What is the ultimate ancestor of all java classes

Answer: Object class is the ancestor of all the java classes

Question: What are important methods of Object class

Answer: wait(), notify(), notifyAll(), equals(), toString().

Question: What is the difference between �= =� and �equals()�

Answer: �= =� does shallow comparison, It retuns true if the two object points to
the same address in the memory, i.e if the same the same reference
�equals()� does deep comparison, it checks if the values of the data in the object
are same

Question: What would you use to compare two String variables - the operator == or
the method equals()?

Answer: I'd use the method equals() to compare the values of the Strings and the ==
to check if two variables point at the same instance of a String object

Question: Give example of a final class

Answer: Math class is final class and hence cannot be extended

Question: What is the difference between String and StringBuffer

Answer: String is an immutable class, i.e you cannot change the values of that
class

Example:

String str = �java�; // address in memory say 12345


And now if you assign a new value to the variable str then
str = �core java�; then the value of the variable at address 12345 will not change
but a new memory is allocated for this variable say 54321
So in the memory address 12345 will have value �java�
And the memory address 54321 will have value �core java� and the variable str will
now be pointing to address 54321 in memory

StringBuffer can be modified dynamically


Example:
StringBuffer strt =�java� // address in memory is say 12345
And now if you assign a new value to the variable str then
Str = �core java�; then value in the address of memory will get replaced, a new
memory address is not allocated in this case.

Question: What will be the result if you compare StringBuffer with String if both
have same values

Answer: It will return false as you cannot compare String with StringBuffer

Question: What is Collection API


Answer: The Collection API is a set of classes and interfaces that support
operation on collections of objects. These classes and interfaces are more
flexible, more powerful, and more regular than the vectors, arrays, and hashtables
if effectively replaces.
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.

Question: What are different types of collections

Answer: A collection has no special order and does not reject duplicates
A list is ordered and does not reject duplicates
A set has no special order but rejects duplicates
A map supports searching on a key field, values of which must be unique

Question: Tell me something about Arrays

Answer: Arrays are fast to access, but are inefficient if the number of elements
grow and if you have to insert or delete an element

Question: Difference between ArrayList and Vector

Answer: Vector methods are synchronized while ArrayList methods are not

Question: Iterator a Class or Interface? What is its use?

Answer: Iterator is an interface which is used to step through the elements of a


Collection

Question: Difference between Hashtable and HashMap

Answer: Hashtable does not store null value, while HashMap does
Hashtable is synchronized, while HashMap is not

You might also like