1. Difference between Array list and Vector in Java?
- Both use same data structure to store the elements that is
array.
- Array list is not synchronized; multiple threads can use
the array list. So it has best performance.
-Vector is synchronized; one thread can access the vector at
a time.
- Vector will grow double its size.
- Array list grow half of its size.
2. Differences between Hash Map and Hash table?
- Hash map store the
elements in form of key and value pair.
- Hash table store the elements in form of key
and value pair.
- Hash map and Hash table does not maintain any
insertion order.
- Hash map allow single null key and multiple null value.
- Hash table does not allow single null key and value.
- Hash Map is not synchronized but hash table is
synchronized
3. What is linked hash map?
- Linked hash map is
same as Hash map instead it maintain insertion order.
4. What is difference between Hash Map and Tree Map?
- Hash map allow
single null key and multiple null value.
- Hash map does not
maintain insertion order.
- Tree map store the
elements in ascending order.
- Tree map does not allow null key and value.
5. Difference between Lists, set and map?
- List allow
duplicate values where are set allow unique elements.
- List maintains
insertion order, based on the implementation set maintains insertion order.
- List is index basis
where has set is not index basis.
- Map store the
elements based on key and value pair.
6. Java Access modifiers?
Access
Modifiers
|
Same Class
|
Same Package
|
Subclass
|
Other packages
|
public
|
Y
|
Y
|
Y
|
Y
|
protected
|
Y
|
Y
|
Y
|
N
|
no access modifier
|
Y
|
Y
|
N
|
N
|
private
|
Y
|
N
|
N
|
N
|
7. What is Exception handling?
The exception handling in java is one of the powerful
mechanisms to handle the runtime errors so that normal flow of the
application can be maintained.
8. Types of Exceptions?
- Checked Exceptions
that occurs at run time.
- Unchecked
Exceptions
9. String, StringBuffeer, StringBuilder:
String:
a. Strings are immutable, so we can't change the value(Final class).
b. Strings are Synchronous so thread safety.
StringBuffer:
a. We can change the value of Stingbuffer object.
b. StringBuffer is Synchronous so thread safety is guarantee because of this performance is slow.
StringBuilder:
a. It is same as a string buffer except the asynchronous character(No thread safety.).
b. For single threaded concepts we can go with the String builder.
9. String, StringBuffeer, StringBuilder:
String:
a. Strings are immutable, so we can't change the value(Final class).
b. Strings are Synchronous so thread safety.
StringBuffer:
a. We can change the value of Stingbuffer object.
b. StringBuffer is Synchronous so thread safety is guarantee because of this performance is slow.
StringBuilder:
a. It is same as a string buffer except the asynchronous character(No thread safety.).
b. For single threaded concepts we can go with the String builder.
Comments
Post a Comment