VOOZH about

URL: https://data-flair.training/blogs/java-quiz/

⇱ Top 25 Java Quiz Questions - A Small Test to Build Your Knowledge - DataFlair


Skip to content

Top 25 Java Quiz Questions – A Small Test to Build Your Knowledge

by DataFlair Team

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

As you progress in your Java development journey, solidifying your understanding of core concepts and functionalities is paramount. Regular self-assessment is crucial for identifying areas of strength and weakness, allowing you to tailor your learning and ensure well-rounded knowledge.

Java quiz questions offer an excellent platform for such self-assessment, providing a focused and engaging way to test your Java skills.

This blog post presents a set of 25 multiple-choice Java quiz questions encompassing various aspects of the language. These questions delve into fundamental syntax, data structures, object-oriented programming (OOP) principles, and commonly used libraries. By actively engaging with this quiz, you can gain valuable insights into your current level of Java comprehension.

Here, we are providing you with some multiple choice questions of Java with answers. This java quiz will help you to brush up Java concepts.

Do not forget to check other java quizzes as well from the series of 7 Java Quizzes.

So let’s start the quiz!!!

Time limit: 0

Quiz Summary

0 of 23 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

Quiz complete. Results are being recorded.

Results

0 of 23 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

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 23
    1. Question

    What will be the output of the following code
    import java.util.Arrays;
    import java.util.Comparator;
    public class ComparatorTest {
    public static void main(String args[])
    {
    String[] ar= {“c”,”d”,”b”,”a”,”e”};
    InnerClass in=new InnerClass();
    Arrays.parallelSort(ar, in);
    for(String str : ar)
    System.out.println(str +””);
    System.out.println(Arrays.binarySearch(ar, “b”));
    }
    static class InnerClass implements Comparator<String>
    {
    public int compare(String s1, String s2)
    {
    return s2.compareTo(s1);
    }
    }
    }

    Correct
    Incorrect
  2. Question 2 of 23
    2. Question

    What will be the output of the following code
    import java.util.LinkedHashSet;
    import java.util.Set;
    public class LinkedHashSetTest {
    public static void main (String args[])
    {
    Set s=new LinkedHashSet();
    s.add(“1”);
    s.add(1);
    s.add(3);
    s.add(2);
    System.out.println(s);
    }
    }

    Correct
    Incorrect
  3. Question 3 of 23
    3. Question

    What will be the output of the following code
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    class Employee implements Comparator{
    String name;
    String id;
    public Employee()
    {}
    public Employee(String name, String id)
    {
    this.name=name;
    this.id=id;
    }
    @Override
    public int compare(Employee obj1, Employee obj2) {
    return obj2.name.compareTo(obj1.name);
    }
    @Override
    public String toString() {
    return “{“+”name “+name+”, id ” + id+’}’;
    }
    }
    public class ComparatorUsage {
    public static void main(String args[])
    {
    Employee emp1=new Employee(“sam”,”4″);
    Employee emp2=new Employee(“amy”,”2″);
    ArrayList<Employee> list=new ArrayList<Employee>();
    list.add(emp1);
    list.add(emp2);
    Collections.sort(list,new Employee());
    System.out.println(list);
    }

    }

    Correct
    Incorrect
  4. Question 4 of 23
    4. Question

    What will be the output of the following code
    import java.util.ArrayList;
    import java.util.List;
    public class ListDemo {

    public static void main (String args[])
    {
    List<Integer> list=new ArrayList<Integer>();
    list.add(2);
    list.add(3);
    m(list);
    public static void m(List<Number> list) {
    System.out.println(list);
    }
    }

    }

    Correct
    Incorrect
  5. Question 5 of 23
    5. Question

    Which of those doesn’t have an index based structure?

    Correct
    Incorrect
  6. Question 6 of 23
    6. Question

    java.util.Collections is a:

    Correct
    Incorrect
  7. Question 7 of 23
    7. Question

    Methods such as reverse, shuffle are offered in:

    Correct
    Incorrect
  8. Question 8 of 23
    8. Question

    Which of those allows duplicate elements?

    Correct
    Incorrect
  9. Question 9 of 23
    9. Question

    Which allows the storage of a null key and null values?

    Correct
    Incorrect
  10. Question 10 of 23
    10. Question

    What will be the output of the following code
    import java.util.HashMap;
    import java.util.Map;
    public class HashMapTest {
    public static void main(String args[])
    {
    Map<Integer,String> hashMap=new HashMap<Integer,String>();
    hashMap.put(11,”animesh”);
    hashMap.put(2,”ayushi”);
    hashMap.put(7,”renuka”);
    hashMap.put(9,”shivashish”);
    hashMap.put(null,”null”);
    System.out.println(hashMap.size());
    System.out.println(hashMap);
    }

    }

    Correct
    Incorrect
  11. Question 11 of 23
    11. Question

    What will be the output of the following code
    import java.util.Iterator;
    import java.util.Vector;

    public class VectorTest {
    public static void main(String args[])
    {
    Vector<String> vector= new Vector<String>();
    vector.add(“1”);
    vector.add(“2”);

    Iterator<String> iterator=vector.iterator();
    while(iterator.hasNext())
    {

    System.out.println(iterator.next());
    }
    }
    }

    Correct
    Incorrect
  12. Question 12 of 23
    12. Question

    What will be the output of the following code
    import java.util.ArrayList;
    import java.util.List;

    public class MyClass {
    public static void main (String args[])
    {
    //Insert Here
    List<String> list=new ArrayList<String>();
    list.add(“a”);
    list.add(“b”);
    l.add(list);

    }
    }

    Correct
    Incorrect
  13. Question 13 of 23
    13. Question

    What will be the output of the following code
    import java.util.ArrayList;
    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”);
    arrayList.add(“c”);

    System.out.println();
    arrayList.add(1,”d”);
    System.out.println(arrayList);
    }

    }

    Correct
    Incorrect
  14. Question 14 of 23
    14. Question

    What will be the output of the following code
    import java.util.List;

    public class ArrayListTest {
    public static void main(String args[])
    {
    List<String> arrayList=new ArrayList<String>();

    arrayList.add(“a”);
    arrayList.add(“a”);
    arrayList.clear();
    arrayList.add(“b”);
    arrayList.add(“b”);

    System.out.println(arrayList.size());
    }

    }

    Correct
    Incorrect
  15. Question 15 of 23
    15. Question

    What will be the output of the following code
    import java.util.Map;
    import java.util.TreeMap;

    public class TreeMapTest {

    public static void main (String args[])
    {
    Map<Integer,String> m= new TreeMap<Integer,String>();
    m.put(11, “audi”);
    m.put(null, null);
    m.put(11,”bmw”);
    m.put(null,”fer”);

    System.out.println(m.size());
    System.out.println(m);
    }
    }

    Correct
    Incorrect
  16. Question 16 of 23
    16. Question

    What will be the output of the following code
    class PrintValue
    {
    <t> void display(t obj[])
    {
    for(t i:obj)
    {
    System.out.println(i+” “);
    }
    }
    }
    public class MyClass {
    public static void main(String…args)
    {
    Abc obj1=new Abc();

    Integer i[]= {1,2};
    obj1.display(i);

    Double d[]= {1.1,2.2};
    obj1.display(d);
    }
    }

    Correct
    Incorrect
  17. Question 17 of 23
    17. Question

    What will be the output of the following code
    import java.util.ArrayList;
    import java.util.List;

    public class MyClass {
    public static void main (String args[])
    {
    List<Integer> list=new ArrayList<Integer>();
    list.add(2);
    list.add(3);
    System.out.println(sum(list));

    }
    public static double sum(List<? extends Number> list)
    {
    double sum=0;
    for(Number num:list)
    {
    sum+=num.doubleValue();
    }
    return sum;
    }
    }

    Correct
    Incorrect
  18. Question 18 of 23
    18. Question

    What will be the output of the following code
    import java.util.Comparator;

    public class SortSet {
    public static void main(String…a)
    {
    Set<Integer> treeSet=new TreeSet(new Comparator<Integer>()
    {
    public int compareTo(Integer o1,Integer o2)
    {
    return o2.compareTo(o1);
    }
    });
    treeSet.add(3);
    treeSet.add(1);
    treeSet.add(2);
    System.out.println(treeSet);

    }

    }

    Correct
    Incorrect
  19. Question 19 of 23
    19. Question

    What will be the output of the following code
    import java.util.Collection;
    import java.util.HashSet;
    import java.util.Set;
    import java.util.TreeSet;

    public class SortSet {
    public static void main(String…a)
    {
    Collection<Integer> collection = new HashSet<Integer>();
    collection.add(3);
    collection.add(1);
    collection.add(2); {

    Set<Integer> treeSet=new TreeSet<Integer>(collection);
    System.out.println(treeSet);

    }
    }
    }

    Correct
    Incorrect
  20. Question 20 of 23
    20. Question

    Which interface should be implemented for sorting on basis of many criteria’s?

    Correct
    Incorrect
  21. Question 21 of 23
    21. Question

    What will be the output of the following code
    import java.util.Comparator;
    import java.util.Map;
    import java.util.TreeMap;
    public class SortMap {

    public static void main(String…a)
    {
    Map<Integer,Integer> treeMap = new TreeMap<Integer,Integer>(new Comparator<Integer>()
    {
    public int compare(Integer o1,Integer o2)
    {
    return o2.compareTo(o1);
    }
    });
    treeMap.put(4,1);
    treeMap.put(2,1);
    treeMap.put(3,1);{

    System.out.println(treeMap);

    }
    }
    }

    Correct
    Incorrect
  22. Question 22 of 23
    22. Question

    What will be the output of the following code
    import java.util.List;
    import java.util.ArrayList;

    public class MyClass {

    public static void main(String…a)
    {
    List<Integer> l = new ArrayList<Integer>();
    l.add(2);
    m(1);
    }
    static void m(List<? super Double> l)
    {
    System.out.println(l.get(0));
    System.out.println(l.get(1));
    }
    }

    Correct
    Incorrect
  23. Question 23 of 23
    23. Question

    In ConcurrentHashMap – once thread locks one segment for updation it doesn’t allow the other thread to perform updations in the same segment till lock isn’t released on the segment

    Correct
    Incorrect

Summary:

While attempting the quiz, strive to answer each question to the best of your ability. For questions you answer correctly, you can reinforce your understanding of those specific topics.

Conversely, questions that pose a challenge pinpoint areas requiring further exploration. Don’t be discouraged by encountering difficult questions; instead, view them as opportunities to target your learning efforts.

The answer key provided after the quiz allows you to verify your responses and identify any misconceptions. For incorrect answers, revisit the corresponding Java concepts in your learning materials or online tutorials. By dedicating focused study time to these areas, you can effectively address any knowledge gaps and solidify your overall Java foundation.

Remember, the goal of this quiz is not to achieve a perfect score but to gain valuable insights into your Java proficiency. By actively engaging with these questions, identifying areas for improvement, and dedicating time to targeted learning, you can take significant strides towards mastering Java and achieving your development goals.

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

👁 courses

Tags: best java Quiz Questionsfree java quizJava MCQ'sJava Mock testjava multiple choice questionsJava Quiz Questionsonline Java Testonline practice set of JavaQuiz questions for Javatop 25 Quiz questions for Javatop Java Quiz Questions

DataFlair Team

DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.

27 Responses

  1. 👁 Image
    Akila T says:

    I’m not getting my score. Help please.

    • 👁 Image
      DataFlair Team says:

      Hi Akila,
      Thanks for taking this Java Quiz. We have checked the Quiz and all its settings, everything is working fine. Please ensure you filled all the answers (mandatory), and after submitting your email id, you will get your score on the screen with the answers you have provided.
      Regards,
      DataFlair

  2. 👁 Image
    Ajith says:

    is that the 14th question’s answer is correct? can you explain to me why?

  3. 👁 Image
    ancy says:

    can you explain how did you get the answer to the 14th question?

  4. 👁 Image
    Bhuvaneswari says:

    in that program they have cleared thelist in the 4th line list clear()
    so the actuall initial values are totally washed out then the further values are stored.so that the size is 2 i guess

  5. 👁 Image
    sanjay.b says:

    nice skills to build our knowledge

  6. 👁 Image
    Aka Ace says:

    4th question : Answer is Runtime exception

  7. 👁 Image
    anil says:

    Answer for problem 4 is incorrect

  8. 👁 Image
    Swarna Sukanta says:

    Please let me know the answer of question no 21.

  9. 👁 Image
    Vishal says:

    consider one question as 1 marks

  10. 👁 Image
    Janice M. Garcia says:

    Most application software programmer will not need to use the Comparator.compare() to see if they are equal, especially with Strings. You use equal() with Strings. compareTo() =0 does not imply equality in all cases!!! The only time to use this would be for creating a Dictionary of words sorted in ascending order. A

  11. 👁 Image
    nabita waluka says:

    Hi, i am happy with our quiz questions and everything works well. its very helpful but i suggest that you and an explanations to the correct answers for many learners like me to understand fully.
    i thank you

  12. 👁 Image
    Zikrillo Islomov says:

    Q10,
    output will be different it is incorrect

  13. 👁 Image
    sadak abdulle says:

    sadak abdullahi rage I want more quiz of java

  14. 👁 Image
    Chaitra says:

    10th Answer look like
    5{null=null, 2=ayushi, 7= renuka, 9…., 11…}

  15. 👁 Image
    Bongani Mguni says:

    for question 4 its compile exception because the java generics are not covariant meaning evn if integers is a subtype of numbers its does not mean list type integers is a subtype of list type
    numbers

  16. 👁 Image
    Phumelele Miya says:

    Awesomeness 👌

  17. 👁 Image
    Phumelele Miya says:

    Already passed

  18. 👁 Image
    sureshreddy mallakuntla says:

    is that the 4th question answer is correct? can you explain to me How.

  19. 👁 Image
    Gozde Apak says:

    2th question : [1,3,2]

  20. 👁 Image
    preksha bhalani says:

    16. Question
    What will be the output of the following code
    class PrintValue
    {
    void display(t obj[])
    {
    for(t i:obj)
    {
    System.out.println(i+” “);
    }
    }
    }
    public class MyClass {
    public static void main(String…args)
    {
    Abc obj1=new Abc();

    Integer i[]= {1,2};
    obj1.display(i);

    Double d[]= {1.1,2.2};
    obj1.display(d);
    }
    }

    It should give the error because of the class name PrintValue and we are calling Abc

  21. 👁 Image
    Rahul Kumar Sah says:

    in the 2nd question LinkedHashSet remove the duplicate buy in the answer duplicate output give how

  22. 👁 Image
    abel says:

    I don’t really get it. Description says “various aspects of Java” but all I see in these seven quizzes are Tree, Hash, Map, Set, Vector,… Where are all the more “core” stuff, methods, strings, arrays, flow control, core algorithms like swapping elements in array or string manipulations, etc.?

Leave a Reply Cancel reply

Java Tutorials