Free Java Quiz Questions With Answers – Prepare Yourself For Interviews
Free Java courses with 37 real-time projects - Learn Java
These Java quiz questions will brush up your concepts of java and prepare you to face Java interview. This Java quiz contains multiple choice questions for java.
Once this quiz is completed, do attempt other java quizzes as well from the series of 7 java quizzes:
- Java Quiz – 2
- Java Quiz – 3
- Java Quiz – 4
- Java Quiz – 5
So, let’s start exploring Java Quiz Questions.
Quiz Summary
0 of 19 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 19 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
- Question 1 of 19
1. Question
Which Set class should be most popular in a multi-threading environment, considering performance constraint?
CorrectIncorrect - Question 2 of 19
2. Question
Which Map class should be most popular in a multi-threading environment, considering performance constraint?
CorrectIncorrect - Question 3 of 19
3. Question
Which allows the removal of elements from a collection?
CorrectIncorrect - Question 4 of 19
4. Question
What will be the output of given code
import java. util.Arrays;
import java. util.Comparator;
class Sorting implements Comparator
{
public int compare(Integer o1, Integer o2)
{
return o2. compareTo(o1);
}
}
public class abc {
public static void main (String…a)
{
Integer intArray[]= {2,3,1};
Arrays.sort(intArray, new Sorting());
for(int i: intArray)
{
System. out. print(i+””);
}
}
}CorrectIncorrect - Question 5 of 19
5. Question
What will be the output of given code
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;public class ConcurrentSkipListMapTest {
public static void main (String args)
{
Set set = new TreeSet();
set.add(1);
set.add(“2”);
set.add(3);Iterator iterator = set.iterator();
while (iterator. hasNext())
{
System. out. print(iterator. next()+””);
}
}}
CorrectIncorrect - Question 6 of 19
6. Question
What will be the output of given code
import java.util.ArrayList;
import java.util. Iterator;
import java.util. List;public class ArrayListTest {
public static void main (String args[])
{
List<String> arrayList = new ArrayList<String>();arrayList.add(“a”);
arrayList.add(“b”);Iterator<String> iterator = arrayList.iterator();
while (iterator.hasNext())
{
System.out.println(iterator.next());
arrayList.add(“c”);
}
}
}CorrectIncorrect - Question 7 of 19
7. Question
What will be the output of given code
import java.util.HashSet;
import java.util.Set;
public class HashSetTest
{
public static void main (String args[])
{
Set hashSet = new HashSet();
hashSet.add(“1”);
hashSet.add(1);
hashSet.add(null);
hashSet.add(“null”);
System.out.println(hashSet);
}}
CorrectIncorrect - Question 8 of 19
8. Question
What will be the output of given code
mport java.util.IdentityHashMap;
import java.util.Map;public class MyClass
{
public static void main(String args[])
{
Map<String,String> identityHashMap = new IdentityHashMap<String,String>();
identityHashMap.put(new String(“a”),”audi”);
identityHashMap.put(new String(“a”),”ferrari”);
System.out.println(identityHashMap);
}
}CorrectIncorrect - Question 9 of 19
9. Question
What will be the output of given code
import java.util.HashMap;
import java.util.Map;public class MyClass
{
public static void main(String args[])
{
Map<String,String> hashMap = new HashMap<String,String>();
hashMap.put(new String(“a”),”audi”);
hashMap.put(new String(“a”),”ferrari”);
System.out.println(hashMap);
}
}CorrectIncorrect - Question 10 of 19
10. Question
Which permits the removal of elements from a collection?
CorrectIncorrect - Question 11 of 19
11. Question
The Comparator interface contains the method?
CorrectIncorrect - Question 12 of 19
12. Question
Which of those is synchronized?
CorrectIncorrect - Question 13 of 19
13. Question
Which offers the best performance?
CorrectIncorrect - Question 14 of 19
14. Question
Which of these is the most popularly used class as a key in a HashMap?
CorrectIncorrect - Question 15 of 19
15. Question
What should we use when add and remove operations are more frequent than get operations
CorrectIncorrect - Question 16 of 19
16. Question
Iterator returned by ArrayList is?
CorrectIncorrect - Question 17 of 19
17. Question
Iterator returned by LinkedList is?
CorrectIncorrect - Question 18 of 19
18. Question
Iterator returned by CopyOnWriteArrayList is?
CorrectIncorrect - Question 19 of 19
19. Question
Iterator returned by HashMap on key, value and entry are?
CorrectIncorrect
Here we come to the end of the Java Quiz. Hope you enjoyed the quiz!!!
Do share your feedback and score in the comments section.
You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google
For question number 10 the answer and options are not valid.
Hey Saravanan,
Thanks for connecting to DataFlair, the que.10 and its answer is verified by our experts, which is absolutely correct. You can run the code in Java and get the answer {a=ferrari}.
Hope, it helps!
Hi,
Question 3( answer: neither enumerator nor iterator can remove an element from collection) and 10 (answer: iterator can remove elements from collection) answer contradict each other.
DataFlair Team {a=ferrari} its Q.9 and Saravanan K had said about Q.10 almost same was asked by Lovely
Q.5 What will be the output of the following code . do you test this code ? it throws an exception.
Hey
yeas iterator is right answer in both questions