Java Expertise Quiz Quiz

  1. Method Overriding and Exceptions

    When overriding a method, can you broaden the scope of exceptions if the original method declares checked exceptions?

    1. Yes, you can broaden the scope of checked exceptions during method overriding.
    2. No, you cannot broaden the scope of checked exceptions during method overriding.
    3. Yes, but only for RuntimeExceptions.
    4. It depends on the compiler settings.
    5. Only if the superclass method doesn't declare any exceptions.
  2. Thread Access to Methods

    If one thread is accessing a synchronized method m1 of an object, can another thread access a non-synchronized method m2 on the same object concurrently?

    1. No, it cannot because the object is locked.
    2. Yes, it can as m2 does not require a lock.
    3. Yes, but only if m2 is static.
    4. No, only if m1 releases the lock first.
    5. It depends on thread priorities.
  3. HashMap and Custom Objects

    If you use a custom object as a key in a HashMap and then modify the object's attributes after it's been added, what happens when you try to retrieve the object using the modified key?

    1. It will successfully retrieve the value associated with the key.
    2. It will return null.
    3. It will throw an exception.
    4. It will retrieve a different entry in the map.
    5. It will create a new entry in the map.
  4. Garbage Collection Tuning

    How does the NewRatio parameter affect garbage collection in Java?

    1. It controls the frequency of full GCs.
    2. It determines the size ratio between the young and old generations.
    3. It specifies the minimum heap size.
    4. It sets the maximum heap size.
    5. It enables or disables garbage collection.
  5. ConcurrentHashMap vs. SynchronizedMap

    What is the primary difference between using Collections.synchronizedMap and ConcurrentHashMap for making a map thread-safe?

    1. Collections.synchronizedMap provides better performance.
    2. ConcurrentHashMap locks the entire map object, while Collections.synchronizedMap locks only part of it.
    3. Collections.synchronizedMap locks the entire map object, while ConcurrentHashMap locks only a segment of the map.
    4. ConcurrentHashMap is only suitable for read-only operations.
    5. There is no difference; they are interchangeable.
  6. Iterator and Concurrent Modification

    What exception is thrown when you attempt to modify a HashMap while iterating over it using an iterator?

    1. NullPointerException
    2. IllegalArgumentException
    3. ConcurrentModificationException
    4. IOException
    5. IndexOutOfBoundsException
  7. Singleton Design Pattern

    What is double-checked locking in the Singleton design pattern used for?

    1. To ensure only one thread can access the singleton instance.
    2. To make the singleton class immutable.
    3. To improve performance by caching the singleton instance.
    4. To make the Singleton thread-safe.
    5. To prevent class loading issues.
  8. Java 8 Enhancements

    Which of the following is a major feature introduced in Java 8?

    1. Generics
    2. Annotations
    3. Lambada Expressions
    4. Reflection
    5. Multi-threading
  9. Memory Leak Analysis

    Which tool can be used to analyze a Java application for memory leaks?

    1. JConsole
    2. JVisualVM
    3. Eclipse Memory Analyzer Tool
    4. JProfiler
    5. All of the above
  10. Method Overloading

    Can two methods in the same class have the same name and parameters but different return types in Java?

    1. Yes, method overloading supports different return types.
    2. No, method overloading only supports different parameter lists.
    3. Yes, if the methods have different access modifiers.
    4. No, the compiler will throw an error due to ambiguous method signatures.
    5. Yes, but only if one method is static and the other is not.