Hello Friends, In this Blog Post I am going to let you know about a few more interview questions of core java related to wrapper classes and the collection framework.
Core java interview questions covers all the important questions of the topics mentioned above.
These core java interview questions is a great help to remember all the important highlights and important topics from each java chapter.
These interview questions will surely help to understand a few very confusing concepts in java.
Why do we need wrapper classes in java?
They convert primitive data type into objects and this is needed on the internet to communicate between two applications.
The classes in java. util package handles only objects and hence wrapper classes help in this case also.
Which of the wrapper classes contains only one constructor? OR Which of the wrapper classes does not contain a constructor with string as a parameter?
What is boxing?
Converting primitive data type into an object is called boxing.
What is unboxing?
Converting an object into its corresponding primitive datatype is called unboxing.
What happens if a string like “hello” is passed to parseint() method?
Ideally, a string with an integer value should be passed to parseint() method. So, on passing “hello”, an exception called ‘NumberFormatException’ occurs since the parseint() method can not convert this given string “hello” into an integer value.
Does a collection object-store copies of other objects or their references?
A collection object stores reference of other objects.
Can you store a primitive data type into a collection?
No, collections store only objects.
What is the difference between iterator and listiterator?
Both are useful to retrieve elements from a collection. Iterator can retrieve the elements only in a forward direction. But list iterator can retrieve the elements in forwarding and backward direction also. So list iterator is preferred to an iterator.
What is the difference between iterator and enumeration?
Both are useful to retrieve elements from a collection. Iterator has methods whose names are easy to follow and enumeration methods are difficult to remember. Also, iterator has an option to remove elements from the collection which is not available in an enumeration. So, an iterator is preferred to enumeration.
What is auto boxing?
Converting a primitive data type into an object form automatically is called ‘autoboxing’ is done in generic types.
What is the difference between ArrayList and vector?
The difference between arraylist and vector is given below.
ArrayList object is not synchronized by default.
Vector object is synchronized by default.
In the case of a single thread, using ArrayList is faster than the vector.
In the case of multiple threads, using vector is advisable. With a single thread, the vector becomes slow.
Array list increases its size every time by 50 percent(half).
vector increases its size every time by doubling it.
Can you synchronize the ArrayList object?
Yes, we can use synchronizedlist() method to synchronize the arraylist, as: collections, synchronizedList(New ArrayList());
What is the load factor for a hashmap or hash table?
It is 0.75.
What is the difference between hashmap and hashtable?
The difference between a hashmap and a hashtable is given below.
The HashMap object is not synchronized by default.
Hashtable object is synchronized by default.
In case of a single thread, using hashmap is faster than a hashtable.
In case of multiple threads, using hashtable is advisable, with a single thread hashtable becomes slow.
Hashmap allows null keys and null values to be stored.
Hashtable does not allow null keys or values.
Iterator in the hashmap table is fail-fast. This means iterator will produce an exception if concurrent updates are made to the hashmap.
Enumeration for the hashtable is not fail-fast. This means even if concurrent updations are done to hashtable, there will not be any incorrect results produced by the enumeration.
Can you make hashmap synchronized?
Yes, we can make hashmap object synchronized using synchronizedMap() method as shown here:
What is the difference between set and list?
The difference between set and list is given below.
A set represents a collection of elements. The order of the elements may change in the set.
A list represents an ordered collection of elements. List preserves the order of elements in which they are entered.
Set will not allow duplicate values to be stored
The list will allow duplicate values.
Accessing elements by their index(position number) is not possible in case of sets.
Accessing elements by an index is possible in lists.
Sets will not allow null elements.
Lists allow null elements to be stored.
So this was all about the Core java interview questions in this topic.
These Core java interview questions could be a great help in your college viva, academic study, and any job interview.
In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.
Hope! you would have enjoyed this post about Core Java Interview Questions Part 15/wrapper classes and the collection framework.
Please feel free to give your important feedbacks in the comment section below.
Have a great time!