Skills101
← Java — Advanced

Java Advanced — Test 1

15 questions22 minPass: 60%+40 XP on first passFree sample test

15 questions · 22 minutes · advanced level, with an explanation for every answer.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What is the output?

    Map<String, Integer> m = new TreeMap<>(Comparator.reverseOrder());
    m.put("b", 2); m.put("a", 1); m.put("c", 3);
    m.merge("a", 10, Integer::sum);
    System.out.println(m);
    
  2. Question 2

    What is the output?

    Integer a = 127, b = 127, c = 128, d = 128;
    System.out.println((a == b) + " " + (c == d) + " " + c.equals(d));
    
  3. Question 3

    What is the output?

    Optional<String> o = Optional.of("skills").filter(s -> s.startsWith("x"));
    System.out.println(o.isPresent() + " " + o.map(String::length).orElse(-1) + " " + Optional.ofNullable(null).orElse("none"));
    
  4. Question 4

    What is the output?

    String s1 = "skills";
    String s2 = "skil" + "ls";
    String part = "skil";
    String s3 = part + "ls";
    System.out.println((s1 == s2) + " " + (s1 == s3) + " " + (s1 == s3.intern()));
    
  5. Question 5

    What is the output?

    List<Integer> list = new ArrayList<>(List.of(1, 2, 3, 4, 5, 6));
    list.removeIf(n -> n % 2 == 0);
    Iterator<Integer> it = list.iterator();
    int s = 0;
    while (it.hasNext()) { int v = it.next(); if (v == 3) it.remove(); else s += v; }
    System.out.println(list + " " + s);
    
  6. Question 6

    What does the volatile keyword guarantee?

  7. Question 7

    What is the output?

    class Main {
        static String s = "";
        static { s += "S"; }
        { s += "I"; }
        Main() { s += "C"; }
        public static void main(String[] args) {
            new Main(); new Main();
            System.out.println(s);
        }
    }
    
  8. Question 8

    What is the output?

    List<String> names = List.of("Riya", "Aman", "Kabir", "Ana", "Rohit");
    String r = names.stream().filter(n -> n.length() > 3).map(String::toUpperCase).sorted().collect(Collectors.joining(","));
    System.out.println(r);
    
  9. Question 9

    What is the output?

    Map<Boolean, List<Integer>> p = IntStream.rangeClosed(1, 8).boxed().collect(Collectors.partitioningBy(n -> n % 3 == 0));
    System.out.println(p.get(true) + " " + p.get(false).size());
    
  10. Question 10

    How does a HashMap handle two keys with the same bucket (Java 8+)?

  11. Question 11

    What is the difference between Runnable and Callable?

  12. Question 12

    Which garbage-collection statement is true?

  13. Question 13

    What is the output?

    class P { P() { show(); } void show() { System.out.print("P "); } }
    class Q extends P {
        int v = 5;
        void show() { System.out.print("Q" + v + " "); }
    }
    public class Main { public static void main(String[] args) { new Q().show(); } }
    
  14. Question 14

    What is the output?

    class Main {
        static int count = 0;
        public static void main(String[] args) throws Exception {
            Thread[] ts = new Thread[4];
            for (int i = 0; i < 4; i++) {
                ts[i] = new Thread(() -> { for (int k = 0; k < 1000; k++) inc(); });
                ts[i].start();
            }
            for (Thread t : ts) t.join();
            System.out.println(count);
        }
        static synchronized void inc() { count++; }
    }
    
  15. Question 15

    Why is String immutable in Java?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →