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 cover all the important questions of the topics mentioned above.|Core Java Interview Questions On wrapper classes and the collection framework|
These core Java interview questions are a great help to remember all the important highlights and important topics from each Java chapter.|Core Java Interview Questions On wrapper classes and the collection framework|
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 types into objects and this is needed on the internet to communicate between two applications.
The classes are 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?
Character class
What is boxing?
Converting primitive data types 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 the parseint() method?
Ideally, a string with an integer value should be passed to the 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 to other objects.
Can you store a primitive data type in a collection?
No, collections store only objects.
What is the difference between an iterator and a list iterator?
Both are useful for retrieving elements from a collection. The iterator can retrieve the elements only in a forward direction.
But the 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 an iterator and an enumeration?
Both are useful for retrieving elements from a collection. Iterator has methods whose names are easy to follow and enumeration methods are difficult to remember.
Also, the iterator has the option to remove elements from the collection which is not available in an enumeration.
So, an iterator is preferred to enumerate.
What is autoboxing?
Converting a primitive data type into an object form automatically is called ‘autoboxing’ and is done in generic types.
What is the difference between an ArrayList and a vector?
The difference between ArrayList and vector is given below.
The ArrayList object is not synchronized by default.
The 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 a 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 a hashmap and a hashtable?
The difference between a hashmap and a hashtable is given below.
The HashMap object is not synchronized by default.
The Hashtable object is synchronized by default.
In the case of a single thread, using a hashmap is faster than a hashtable.
In the case of multiple threads, using a hashtable is advisable, with a single thread hashtable becoming slow.
Hashmap allows null keys and null values to be stored.
Hashtable does not allow null keys or values.
The iterator in the hashmap table is fail-fast. This means the iterator will produce an exception if concurrent updates are made to the hashmap.
Enumeration for the hashtable is not fail-fast. This means that even if concurrent updations are done to the hashtable, there will not be any incorrect results produced by the enumeration.
Can you make the hashmap synchronized?
Yes, we can make hashmap object synchronized using the synchronized map() method as shown here:
Collection.synchronized map(New HashMap());
What is the difference between a set and a list?
The difference between the set and the 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. The list preserves the order of elements in which they are entered.
The 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 the 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 on this topic.
These Core Java interview questions could be a great help in your college viva, academic study, and any job interview.
You can also go through a few more amazing blog links related to core Java interview questions:
Core Java Interview Questions Part 1
Core Java Interview Questions Part 2
Core Java Interview Questions Part 3
Core Java Interview Questions Part 4
Core Java Interview Questions Part 5
Core Java Interview Questions Part 6
Core Java Interview Questions Part 7
Core Java Interview Questions Part 8
Core Java Interview Questions Part 9
Core Java Interview Questions Part 10
Core Java Interview Questions Part 11
Core Java Interview Questions Part 12
Core Java Interview Questions Part 13
Core Java Interview Questions Part 14
Core Java Interview Questions Part 15
Core Java Interview Questions Part 16
Core Java Interview Questions Part 17
Core Java Interview Questions Part 18
Core Java Interview Questions Part 19
Core Java Interview Questions Part 20
Core Java Interview Questions Part 21
JVM In Hindi: Java Virtual Machine
C ++ और Java में अंतर हिंदी में…
In the case of any queries, you can write to us at a5theorys@gmail.com we will get back to you ASAP.
Hope! you would have enjoyed this post about Core Java Interview Questions On wrapper classes and the collection framework.
Please feel free to give your important feedback in the comment section below.|Core Java Interview Questions On wrapper classes and the collection framework|
Have a great time!