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.
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 / Error | Category | Direct Exam-Relevant Superclass | Classic Runtime Trigger |
|---|---|---|---|
NullPointerException | Unchecked | RuntimeException | Calling an instance method, accessing an instance field, indexing an array, unboxing null, or switching on a null reference |
ArithmeticException | Unchecked | RuntimeException | Integer division or remainder by zero (10 / 0, 10 % 0) |
ArrayIndexOutOfBoundsException | Unchecked | IndexOutOfBoundsException | Accessing arr[-1] or arr[arr.length] |
StringIndexOutOfBoundsException | Unchecked | IndexOutOfBoundsException | Specified for StringBuilder.deleteCharAt outside its bounds. String’s charAt and substring APIs specify the broader IndexOutOfBoundsException. |
IndexOutOfBoundsException | Unchecked | RuntimeException | Out-of-range index in ArrayList.get(idx) or List.remove(idx) |
ClassCastException | Unchecked | RuntimeException | Invalid runtime downcast (Object o = "hi"; Integer n = (Integer) o;) |
IllegalArgumentException | Unchecked | RuntimeException | Passing an invalid argument to a method that checks preconditions |
NumberFormatException | Unchecked | IllegalArgumentException | Integer.parseInt("12a") or Double.valueOf("bad") |
ArrayStoreException | Unchecked | RuntimeException | Storing a wrong element type through a covariant array reference (Object[] a = new String[1]; a[0] = 5;) |
DateTimeException | Unchecked | RuntimeException | Invalid calendar values such as LocalDate.of(2026, 2, 30) |
DateTimeParseException | Unchecked | DateTimeException | Invalid text passed to LocalDate.parse("2026-13-01") |
StackOverflowError | Error (Unchecked) | VirtualMachineError -> Error | Unbounded recursion exhausting the call stack |
ExceptionInInitializerError | Error (Unchecked) | LinkageError -> Error | A non-Error throwable escapes a static initializer during class initialization |
OutOfMemoryError | Error (Unchecked) | VirtualMachineError -> Error | An allocation exceeds an implementation limit or available memory |
NoClassDefFoundError | Error (Unchecked) | LinkageError -> Error | A required class definition cannot be loaded, or an active use needs an already erroneous class |
IOException | Checked | Exception | General input/output failure |
FileNotFoundException | Checked | IOException | Opening a missing or inaccessible file stream |
java.text.ParseException | Checked | Exception | Legacy SimpleDateFormat.parse(...) failing to parse text |
ClassNotFoundException | Checked | ReflectiveOperationException -> Exception | Class.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:
ArrayIndexOutOfBoundsExceptionextendsIndexOutOfBoundsException(arrays).StringIndexOutOfBoundsExceptionextendsIndexOutOfBoundsException. The String.charAt API allows the broader superclass; StringBuilder.deleteCharAt explicitly specifies the narrower type.ArrayList.get(idx)throwsIndexOutOfBoundsException.
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:
NumberFormatExceptionextendsIllegalArgumentException: Placingcatch (IllegalArgumentException e)beforecatch (NumberFormatException e)fails compilation withexception java.lang.NumberFormatException has already been caught.ArrayStoreExceptionvs.ClassCastException: Java arrays are covariant (String[]is a subtype ofObject[]), soObject[] items = new String[2];compiles. Assigningitems[0] = 42;(Integer) compiles too, then fails at runtime withArrayStoreException(notClassCastException).
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)throwsjava.time.DateTimeException(unchecked).LocalDate.parse("2026-02-30")throwsjava.time.format.DateTimeParseException, which extendsDateTimeException(unchecked).- By contrast, legacy
java.text.SimpleDateFormat.parse(...)declaresjava.text.ParseException, which is a checkedException.
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.
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;
}
}
Throws NullPointerException immediately at d.name
Prints Java8: and then throws ClassCastException
Prints null: and then throws ArrayStoreException
Prints Java8: and then throws ArrayStoreException
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");
}
}
NullPointerException directly without wrapping
ExceptionInInitializerError
NoClassDefFoundError
IllegalStateException
Which statement accurately compares Java SE 8 date/time and number exceptions?
DateTimeParseException is a checked exception that requires throws or try-catch
Double.valueOf("abc") throws ArithmeticException
NumberFormatException is a subclass of IllegalArgumentException, and DateTimeException is an unchecked RuntimeException
5.0 / 0.0 throws ArithmeticException
Sections you finish are checked off in the contents.