Java SE 8 Programmer I (OCAJP 8) study materials
Java SE 8 Programmer I (OCAJP 8) study resources

Java SE 8 Programmer I (OCAJP 8) flashcards

Java SE 8 Programmer I (OCAJP 8) · Build recall with a focused review session.

31 cards. Read the term and the definition here. The deck at the top of this page is optional.

public class file rule
A source file can hold at most one public top-level class, and the file name must match that class name exactly, including case, plus the .java extension.
main method signature
The JVM entry point is public static void main(String[] args). Equivalent valid forms include String... args or a differently named String array parameter.
default constructor
A class with no declared constructor gets an implicit no-arg constructor with the same access modifier as the class. Declaring any constructor removes it.
primitive widening order
Implicit widening follows byte→short→int→long→float→double, and char→int. Narrowing in the reverse direction needs an explicit cast and may lose data.
literal suffix rules
Integer literals are int unless suffixed L. Decimal literals are double unless suffixed F. A leading zero means octal, so 08 does not compile.
autoboxing cache range
Integer.valueOf caches values from -128 to 127, so two autoboxed Integers in that range compare equal with ==, while larger values may not.
short-circuit operators
&& and || skip evaluating the right operand when the left determines the result. The single-character & and | on booleans always evaluate both sides.
switch allowed types
switch accepts byte, short, char, int, their wrapper classes, String, and enum constants. long, float, double, and boolean are not permitted.
compound assignment casting
Operators like += and -= include an implicit narrowing cast, so byte b = 10; b += 5; compiles while b = b + 5; fails.
array length field
Array size is fixed at creation and exposed through the final field length. Writing arr.length() with parentheses does not compile.
array default values
New array elements are initialized to 0 for numeric primitives, false for boolean, the null character for char, and null for object references.
multidimensional array creation
int[][] a = new int[2][]; creates two null inner-array slots. Each row must be allocated separately before its elements can be assigned.
do-while loop
A do-while loop executes its body at least once because the condition is tested after the body. The closing while(...) requires a semicolon.
labeled break
A labeled break such as break outer; exits the loop bearing that label, letting an inner loop terminate an enclosing loop directly.
unreachable code error
Statements after an unconditional break, return, or throw in the same block fail compilation. A constant-true loop without break also makes following code unreachable.
overloading resolution
Overloads are chosen at compile time by parameter types, count, and order. Return type, parameter names, and thrown exceptions do not participate.
varargs parameter rules
A varargs parameter (Type... name) must be last and is treated as an array inside the method. Callers may pass zero arguments or an explicit array.
static method restrictions
Static methods cannot use this or directly access instance fields and instance methods. They are invoked via the class name or any instance reference.
super constructor call
If a constructor does not call this(...) or super(...) explicitly, the compiler inserts super(). It must be the first statement in the constructor body.
override access modifier rule
An overriding method cannot have a more restrictive access modifier than the overridden method, but it may widen it and may return a covariant subtype.
static method hiding
A static method in a subclass with the same signature as a static superclass method hides rather than overrides it; which one runs depends on the reference type.
interface default methods
Java 8 interfaces may declare default methods with a body and static methods. Implementing classes inherit defaults unless a conflict requires an override.
checked versus unchecked
RuntimeException, Error, and their subclasses are unchecked. All other Throwable subtypes are checked and must be caught or declared with throws.
catch order rule
Catch blocks are checked top-down, so a supertype catch placed before a subtype catch makes the subtype block unreachable and causes a compile error.
finally return override
A return statement inside finally replaces any pending return from the try or catch block, which can silently discard values or exceptions.
multi-catch syntax
catch (IOException | SQLException e) handles several unrelated exception types in one block. The parameter is implicitly final and cannot be reassigned.
String immutability
String objects never change. Methods like substring, trim, and replace return new String objects, so the original reference keeps its original content.
substring end index
substring(begin, end) returns characters from begin up to but not including end. substring(2, 5) yields three characters at indexes 2, 3, and 4.
ArrayList remove overloads
remove(int index) deletes by position and returns the removed element. remove(Object o) deletes the first matching value and returns boolean.
Arrays.asList limitations
Arrays.asList returns a fixed-size list backed by the source array. set works, but add and remove throw UnsupportedOperationException.
java.time immutability
LocalDate, LocalTime, and LocalDateTime are immutable. Methods such as plusDays return a new instance rather than modifying the original object.