11.4 Recognizing Common Java SE 8 Exam Exceptions

Key Takeaways

  • Integer division or modulo by zero throws ArithmeticException, whereas floating-point division by zero produces Infinity, -Infinity, or NaN without throwing

  • NumberFormatException extends IllegalArgumentException, and StringIndexOutOfBoundsException and ArrayIndexOutOfBoundsException both extend IndexOutOfBoundsException

  • If an initiating class initializer fails with a non-Error throwable, Java normally wraps it in ExceptionInInitializerError. An Error from that initializer propagates directly.

  • DateTimeParseException extends DateTimeException, which extends RuntimeException. Both are unchecked. java.text.ParseException is checked.

  • Class.forName can report a missing class with checked ClassNotFoundException. JVM linkage or an earlier failed class initialization can lead to unchecked NoClassDefFoundError.

Last updated: November 2026

Recognizing Common Java SE 8 Exam Exceptions

Independent prep covering the standard-exception recognition objective of Official Domain 8 (Handling Exceptions). Many 1Z0-808 questions show a short snippet without any throw keyword and ask which exception or error the JVM produces at runtime—or whether the snippet prints a normal value instead. Knowing the exact trigger conditions and superclass relationships of every core exam exception makes these questions rapid, reliable points.

Master Reference Table of Exam Exceptions & Errors

Exception / ErrorCategoryDirect Exam-Relevant SuperclassClassic Runtime Trigger
NullPointerExceptionUncheckedRuntimeExceptionCalling an instance method, accessing an instance field, indexing an array, unboxing null, or switching on a null reference
ArithmeticExceptionUncheckedRuntimeExceptionInteger division or remainder by zero (10 / 0, 10 % 0)
ArrayIndexOutOfBoundsExceptionUncheckedIndexOutOfBoundsExceptionAccessing arr[-1] or arr[arr.length]
StringIndexOutOfBoundsExceptionUncheckedIndexOutOfBoundsExceptionSpecified for StringBuilder.deleteCharAt outside its bounds. String’s charAt and substring APIs specify the broader IndexOutOfBoundsException.
IndexOutOfBoundsExceptionUncheckedRuntimeExceptionOut-of-range index in ArrayList.get(idx) or List.remove(idx)
ClassCastExceptionUncheckedRuntimeExceptionInvalid runtime downcast (Object o = "hi"; Integer n = (Integer) o;)
IllegalArgumentExceptionUncheckedRuntimeExceptionPassing an invalid argument to a method that checks preconditions
NumberFormatExceptionUncheckedIllegalArgumentExceptionInteger.parseInt("12a") or Double.valueOf("bad")
ArrayStoreExceptionUncheckedRuntimeExceptionStoring a wrong element type through a covariant array reference (Object[] a = new String[1]; a[0] = 5;)
DateTimeExceptionUncheckedRuntimeExceptionInvalid calendar values such as LocalDate.of(2026, 2, 30)
DateTimeParseExceptionUncheckedDateTimeExceptionInvalid text passed to LocalDate.parse("2026-13-01")
StackOverflowErrorError (Unchecked)VirtualMachineError -> ErrorUnbounded recursion exhausting the call stack
ExceptionInInitializerErrorError (Unchecked)LinkageError -> ErrorA non-Error throwable escapes a static initializer during class initialization
OutOfMemoryErrorError (Unchecked)VirtualMachineError -> ErrorAn allocation exceeds an implementation limit or available memory
NoClassDefFoundErrorError (Unchecked)LinkageError -> ErrorA required class definition cannot be loaded, or an active use needs an already erroneous class
IOExceptionCheckedExceptionGeneral input/output failure
FileNotFoundExceptionCheckedIOExceptionOpening a missing or inaccessible file stream
java.text.ParseExceptionCheckedExceptionLegacy SimpleDateFormat.parse(...) failing to parse text
ClassNotFoundExceptionCheckedReflectiveOperationException -> ExceptionClass.forName("Missing") failing to locate a class dynamically

Runtime Exceptions & Subtle Exam Traps

1. NullPointerException vs. static Member Access

Dereferencing null triggers NullPointerException—including during unboxing (Integer n = null; int x = n;) and switch (str) when str is null. However, calling a static method or reading a static field via a typed null variable does not dereference that value. Selecting the static member does not prevent failures while evaluating a more complicated qualifier or while initializing its class:

public class NullTrap {
    static String tag = "OK";
    public static void main(String[] args) {
        NullTrap ref = null;
        System.out.println(ref.tag); // Prints OK (static field accessed via class, no NPE!)
        // System.out.println(ref.toString()); // Throws NullPointerException at runtime
    }
}

2. ArithmeticException: Integers vs. Floating-Point

Only integral division or remainder by zero (int, long, short, byte, char) throws ArithmeticException. Floating-point (float and double) division follows IEEE 754 rules and never throws:

System.out.println(5.0 / 0);   // Infinity
System.out.println(-5.0 / 0);  // -Infinity
System.out.println(0.0 / 0.0); // NaN
// int x = 5 / 0;              // Throws ArithmeticException: / by zero

3. IndexOutOfBoundsException, ArrayIndexOutOfBoundsException & StringIndexOutOfBoundsException

Remember the hierarchy here for catch ordering and exception-identification questions:

  • ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException (arrays).
  • StringIndexOutOfBoundsException extends IndexOutOfBoundsException. The String.charAt API allows the broader superclass; StringBuilder.deleteCharAt explicitly specifies the narrower type.
  • ArrayList.get(idx) throws IndexOutOfBoundsException.

A catch for IndexOutOfBoundsException handles both named subclasses. A catch for one subclass does not match the other, so use the documented superclass when handling bounds violations from String.charAt.

4. IllegalArgumentException, NumberFormatException & ArrayStoreException

Two subtle RuntimeException traps appear frequently:

  • NumberFormatException extends IllegalArgumentException: Placing catch (IllegalArgumentException e) before catch (NumberFormatException e) fails compilation with exception java.lang.NumberFormatException has already been caught.
  • ArrayStoreException vs. ClassCastException: Java arrays are covariant (String[] is a subtype of Object[]), so Object[] items = new String[2]; compiles. Assigning items[0] = 42; (Integer) compiles too, then fails at runtime with ArrayStoreException (not ClassCastException).

5. DateTimeException vs. DateTimeParseException vs. java.text.ParseException

These Java SE 8 date operations report their failures with unchecked exceptions:

  • LocalDate.of(2026, 2, 30) throws java.time.DateTimeException (unchecked).
  • LocalDate.parse("2026-02-30") throws java.time.format.DateTimeParseException, which extends DateTimeException (unchecked).
  • By contrast, legacy java.text.SimpleDateFormat.parse(...) declares java.text.ParseException, which is a checked Exception.

Error Triggers: ExceptionInInitializerError & StackOverflowError

ExceptionInInitializerError in static Initializers

If the class’s initializer code completes abruptly with a non-Error throwable, initialization normally reports ExceptionInInitializerError. If creating the wrapper fails due to lack of memory, the JVM reports OutOfMemoryError instead. An Error from the initializer itself propagates without wrapping:

public class StaticInitFail {
    static int[] nums = new int[2];
    static {
        int x = nums[5]; // Throws ArrayIndexOutOfBoundsException -> JVM wraps in ExceptionInInitializerError!
    }
    public static void main(String[] args) {
        System.out.println("Never reached");
    }
}

Note

The wrapping rule belongs to class initialization. A runtime exception in an instance initializer ordinarily propagates out of that construction directly. It can still reach class initialization if the construction occurs inside a static initializer. The compiler disallows static initializers of a normal named class that can throw checked exceptions.

StackOverflowError & NoClassDefFoundError

A thread that needs more stack space than the VM permits gets StackOverflowError. An implementation that attempts to expand its stack can instead report OutOfMemoryError when memory is unavailable for expansion. A class marked erroneous after initialization fails cannot later be initialized successfully through the same class definition. Another active use requiring initialization then gets NoClassDefFoundError.

Test Your Knowledge

What is the runtime result of executing the following main method?

public class Demo {
    static String name = "Java8";
    public static void main(String[] args) {
        Demo d = null;
        Object[] arr = new String[2];
        System.out.print(d.name + ":");
        arr[0] = 100;
    }
}
A

Throws NullPointerException immediately at d.name

B

Prints Java8: and then throws ClassCastException

C

Prints null: and then throws ArrayStoreException

D

Prints Java8: and then throws ArrayStoreException

Test Your Knowledge

Which exception or error is thrown on the initial attempt to run this class, assuming ordinary allocation succeeds?

public class Boot {
    static {
        String s = null;
        s.length();
    }
    public static void main(String[] args) {
        System.out.println("Started");
    }
}
A

NullPointerException directly without wrapping

B

ExceptionInInitializerError

C

NoClassDefFoundError

D

IllegalStateException

Test Your Knowledge

Which statement accurately compares Java SE 8 date/time and number exceptions?

A

DateTimeParseException is a checked exception that requires throws or try-catch

B

Double.valueOf("abc") throws ArithmeticException

C

NumberFormatException is a subclass of IllegalArgumentException, and DateTimeException is an unchecked RuntimeException

D

5.0 / 0.0 throws ArithmeticException

Sections you finish are checked off in the contents.