Java has been one of the most widely deployed programming languages in the world for over 25 years. It powers enterprise backends, Android apps, big data platforms, and countless financial systems. Oracle offers two Java certification levels: Java Foundations (1Z0-811, entry-level conceptual) and Java SE 17 OCP (1Z0-829, the professional certification for experienced Java developers). This guide covers the core concepts tested across both — from Java's fundamental syntax and object-oriented principles to the advanced features introduced in Java 11-17.
Practice this topic
Java is a statically typed, compiled language that runs on the JVM (Java Virtual Machine) — 'write once, run anywhere'. Primitive types: byte (8-bit, -128 to 127), short (16-bit), int (32-bit, default for integers), long (64-bit, suffix L — 100L), float (32-bit decimal, suffix f — 3.14f), double (64-bit decimal, default for decimals), char (16-bit Unicode character, single quotes — 'A'), boolean (true or false). Wrapper classes: Integer, Double, Character — autoboxing converts primitives to wrappers automatically (Integer x = 5), unboxing converts back. String is not a primitive — it is an immutable Object (String pool — string literals are cached). Control flow: if/else if/else, switch (traditional with break, switch expression in Java 14+ — returns a value directly), for (traditional, enhanced for-each for iterables), while, do-while, break (exit loop), continue (skip iteration), labeled break/continue (for nested loops). Java operators: arithmetic (+, -, *, /, % — integer division truncates: 7/2 = 3), compound assignment (+=, -=), increment/decrement (++i pre-increment, i++ post-increment — different return values when used in expressions), ternary (condition ? valueIfTrue : valueIfFalse).
Java is an object-oriented language — everything is a class or interface (except primitives). Class anatomy: fields (instance variables), constructors (same name as class, no return type — called with new keyword), methods (return type + name + parameters). Access modifiers: public (visible everywhere), protected (visible within package and subclasses), package-private/default (no modifier — visible within same package only), private (visible only within the class — encapsulation). Inheritance: extends keyword — subclass inherits all non-private fields and methods of superclass. Method overriding: same signature, different implementation in subclass — @Override annotation verifies the override is correct. super() calls superclass constructor (must be first line). Polymorphism: a superclass reference can hold a subclass object — method calls resolve to the actual object's type at runtime (dynamic dispatch). instanceof operator checks type at runtime. Abstract classes: cannot be instantiated, may have abstract methods (no body) that subclasses must implement. Interfaces: define a contract — all methods are implicitly public abstract (unless default or static methods in Java 8+). A class can implement multiple interfaces (multiple inheritance of type) but can only extend one class.
Java Collections Framework provides standard data structure implementations. List (ordered, allows duplicates): ArrayList (backed by array, fast random access, slow insertion in middle), LinkedList (doubly linked list, fast insertion/deletion, slow random access). Set (unordered, unique elements): HashSet (hash table, O(1) add/contains, no order), LinkedHashSet (insertion order maintained), TreeSet (sorted order, O(log n) operations). Map (key-value, unique keys): HashMap (O(1) average), LinkedHashMap (insertion order), TreeMap (sorted by key). Generics: type parameters prevent ClassCastException at compile time — List<String> guarantees only Strings, no casting needed. Wildcards: List<?> (unknown type), List<? extends Number> (Number or subtype), List<? super Integer> (Integer or supertype). Functional programming in Java (Java 8+): Lambda expressions (anonymous function — (x) -> x * 2), method references (Math::abs, String::new), functional interfaces (one abstract method — Predicate<T>, Function<T,R>, Consumer<T>, Supplier<T>), Stream API (fluent pipeline over collections — filter, map, sorted, collect, reduce, forEach), Optional<T> (container for potentially null values — avoids NullPointerException).
Exception handling in Java: checked exceptions (must be caught or declared — IOException, SQLException), unchecked exceptions (RuntimeException subclasses — NullPointerException, ArrayIndexOutOfBoundsException, ClassCastException — do not need to be declared). try-with-resources: automatically closes AutoCloseable resources (InputStream, Connection) when the try block exits — eliminates finally blocks for resource cleanup. Multi-catch: catch (IOException | SQLException e) — handle multiple exception types in one block. Java I/O: InputStream/OutputStream (bytes), Reader/Writer (characters), BufferedReader/BufferedWriter (buffered for performance), Files utility class (Java 7+ NIO.2 — Files.readAllLines, Files.write, Files.copy, Files.delete). Java 17 features relevant to OCP: Records (immutable data classes — record Point(int x, int y) {} automatically generates constructor, getters, equals, hashCode, toString), Sealed Classes (restrict which classes can extend a class — sealed class Shape permits Circle, Rectangle), Pattern Matching for instanceof (if (obj instanceof String s) { s.length(); } — no cast needed), Switch Expressions (switch expression with arrow syntax — no fall-through, returns value), Text Blocks (multiline strings delimited by triple quotes).
== compares object content in Java
== compares object references (memory addresses) for Objects — two different String objects with the same content are == false unless they are the same instance from the String pool. Use .equals() to compare object content. For primitives, == compares values correctly.
abstract classes and interfaces serve the same purpose
Abstract classes can have state (fields), constructors, and concrete methods — use when classes share implementation. Interfaces define contracts with no state (before Java 8) — use for multiple type inheritance. A class can implement multiple interfaces but extend only one class.
Catching Exception at the top level is good defensive coding
Catching Exception (or worse, Throwable) hides bugs by swallowing unexpected exceptions. Catch the most specific exception type you can handle. Let unexpected exceptions propagate to a top-level error handler that logs and alerts — silent swallowing of exceptions is a major source of production bugs.
Try free Oracle Java Programming practice questions with explanations, topic links and progress tracking.