Study guide
3.2 Constructors, Overloading, Initialization Order, and Garbage Collection
Oracle Java SE 17 Developer Certified Professional 1Z0-829
Track your progress as you read
Finished sections get a check mark.
1 Introduction: The 1Z0-829 Exam
About the Java SE 17 Developer (1Z0-829) Exam
2 Chapter 1: Java Fundamentals & Language Basics
1.1 Primitive Types, Literals, Wrapper Classes, and Type Promotion/Casting 1.2 Local Variable Type Inference (`var`) Rules and Scoping 1.3 Operators, Precedence, Evaluation Order, and Short-Circuit Evaluation 1.4 Text Blocks, String Immutability, and StringBuilder APIs
3 Chapter 2: Program Flow & Decision Constructs
2.1 Conditional Branching with if/else and the Ternary Operator 2.2 Switch Statements and Switch Expressions 2.3 Iteration Constructs, Loop Control, and Branching Labels
4 Chapter 3: Object-Oriented Design & Class Mechanics
3.1 Class Declarations, Field/Method Signatures, and Access Modifiers 3.2 Constructors, Overloading, Initialization Order, and Garbage Collection 3.3 Inheritance, Method Overriding, Polymorphism, and `super`/`this` 3.4 Abstract Classes, Static Members, and Object Methods (`equals`, `hashCode`, `toString`)
5 Chapter 4: Advanced OOP: Interfaces, Records & Sealed Types
4.1 Interface Architecture: Default, Static, and Private Methods 4.2 Enumerations: Constants, Constructors, Methods, and Custom Bodies 4.3 Records: Canonical/Compact Constructors, Components, and Immutability 4.4 Sealed Classes and Interfaces: `permits`, Hierarchy Constraints, and Modifiers
6 Chapter 5: Pattern Matching & Nested Types
5.1 Pattern Matching for `instanceof` and Flow Scoping Mechanics 5.2 Nested Types: Member Inner, Static Nested, Local, and Anonymous Classes 5.3 Defensive Programming, Immutability Patterns, and Validation
7 Chapter 6: Generics, Collections & Arrays
6.1 Generic Classes, Interfaces, Methods, and Type Erasure 6.2 Bounded Type Parameters and Wildcards (PECS Rule) 6.3 Collections Framework: List, Set, Queue, and Deque APIs 6.4 The Map Interface, Sorting, Comparable, and Comparator 6.5 Arrays: Declaration, Initialization, Multidimensional Arrays, and the Arrays Utility Class
8 Chapter 7: Functional Programming & Lambda Expressions
7.1 Functional Interfaces and Lambda Syntax Rules 7.2 Standard Functional Interfaces in `java.util.function` 7.3 Method References: Static, Bound, Unbound, and Constructor References
9 Chapter 8: The Stream API
8.1 Stream Lifecycle: Creation, Pipeline Architecture, and Lazy Evaluation 8.2 Intermediate Stream Operations: Filtering, Mapping, Sorting, and Slicing 8.3 Terminal Stream Operations: Reduction, Matching, Finding, and Collecting 8.4 Primitive Streams (`IntStream`, `LongStream`, `DoubleStream`) and Numeric Statistics
10 Chapter 9: Advanced Streams & Collectors
9.1 The Optional Class: Safe Null Handling, Transformation, and Chaining 9.2 The Collectors API: Downstream Reductions, Grouping, and Partitioning 9.3 Parallel Streams: Fork/Join Pool, Spliterators, and Concurrency Pitfalls
11 Chapter 10: Exception Handling
10.1 The Java Exception Hierarchy: Checked vs. Unchecked Exceptions and Errors 10.2 Exception Constructs: `try-catch-finally`, Multi-Catch, and Rethrowing 10.3 Try-With-Resources, `AutoCloseable`, Suppressed Exceptions, and Custom Exceptions
12 Chapter 11: Date/Time API & Localization
11.1 Date and Time Core Types: `LocalDate`, `LocalTime`, `LocalDateTime` 11.2 Timestamps, Intervals, and Durations: `Instant`, `Period`, and `Duration` 11.3 Time Zones, Daylight Saving Time (DST) Offsets, and `ZonedDateTime` 11.4 Internationalization and Localization: `Locale`, `ResourceBundle`, and Formatters 11.5 Formatting and Parsing Messages, Numbers, Percentages, and Localized Dates
13 Chapter 12: Java Platform Module System (JPMS)
12.1 Module Architecture, `module-info.java`, and Module Paths 12.2 Module Directives: `requires`, `requires transitive`, `exports`, and Qualified Exports 12.3 Reflection, Deep Encapsulation, `opens`, and Open Modules 12.4 Services in JPMS (`uses`, `provides...with`), Migration Paths, and Tooling (`jlink`, `jdeps`) 12.5 Compiling and Packaging Code: Non-Modular JARs, Modular JARs, and Migration Strategies
14 Chapter 13: Concurrency & Multithreading
13.1 Thread Fundamentals, `Runnable`, `Callable`, and Thread Lifecycle 13.2 Memory Visibility, `volatile`, Intrinsic Locks, and Synchronization 13.3 The Concurrency Framework: `ExecutorService`, Thread Pools, and `Future` 13.4 Concurrent Collections, Atomic Variables, Explicit Locks, and `CompletableFuture`
15 Chapter 14: Java I/O and NIO.2
14.1 Classical I/O: Byte and Character Streams, Readers, Writers, and Buffering 14.2 Object Serialization, `Serializable`, `transient`, and `serialVersionUID` 14.3 NIO.2 Architecture: `Path`, `Paths`, and Basic `Files` Operations 14.4 Advanced NIO.2: Directory Walking, Streams (`Files.lines`, `walk`), and `WatchService`
16 Chapter 15: Accessing Databases with JDBC
15.1 JDBC Architecture, Drivers, `DriverManager`, and `DataSource` Connections 15.2 SQL Execution: `Statement`, `PreparedStatement`, and `CallableStatement` 15.3 `ResultSet` Navigation, Data Types, and Transaction Management (Commit, Rollback, Savepoints)
17 Chapter 16: Annotations & the Java Logging API
16.1 Standard Annotations: @Override, @FunctionalInterface, @Deprecated, @SuppressWarnings, and @SafeVarargs 16.2 Java Logging API Basics: Logger, Levels, Handlers, and Configuration
3.2 Constructors, Overloading, Initialization Order, and Garbage Collection
Key Takeaways Explain This Topic AI
The compiler provides a default no-argument constructor only if no constructors of any kind are declared in the class; its access modifier matches the class declaration.
Explicit constructor invocations using this(...) or super(...) must appear as the very first executable statement in a constructor body and cannot form a circular invocation cycle.
Initialization follows a rigid order: superclass static blocks -> subclass static blocks -> superclass instance initializers/fields -> superclass constructor -> subclass instance initializers/fields -> subclass constructor.
Invoking an overridden instance method from a superclass constructor executes the subclass implementation before subclass fields are initialized, resulting in default field values.
Objects become eligible for garbage collection when they are no longer reachable from any live GC root; circular references in an island of isolation are collected without issue.
Last updated: October 2026
Constructors, Initialization Order, and Garbage Collection
Understanding object instantiation, constructor mechanics, and memory management is fundamental to writing reliable Java applications and succeeding on the 1Z0-829 exam. A solid grasp of the order of execution during object creation and the reachability graph during garbage collection prevents subtle runtime bugs.
1. Constructor Mechanics and Default Constructors
A constructor initializes a newly created object. Syntactically, a constructor resembles a method but has no return type (not even void ) and must match the class name exactly.
Compiler-Generated Default Constructor Rules
Condition : The compiler generates a default no-argument constructor only if the class defines zero explicit constructors.
Signature and Body : The default constructor takes no arguments and contains a single statement: super(); .
Access Level : The access modifier of the default constructor matches the access modifier of the class itself. A public class receives a public default constructor; a package-private class receives a package-private default constructor.
Supersession : As soon as any constructor is explicitly declared (even a constructor with multiple parameters), the compiler does not generate a default no-arg constructor.
Warning
If a superclass declares only parameterized constructors (e.g., SuperClass(int x) ), any subclass that does not explicitly invoke super(x) in its own constructors will fail to compile. This occurs because the subclass constructor implicitly attempts to call super() , which no longer exists in the superclass.
2. Constructor Overloading and Chaining ( this and super )
Constructors can be overloaded by providing different parameter counts, types, or orders. To avoid duplicate initialization code, constructors can chain to other constructors.
Chaining Rules
this(...) : Calls an overloaded constructor in the same class .
super(...) : Calls a constructor in the immediate superclass .
First Statement Constraint : If present, this(...) or super(...) must be the first executable statement in the constructor body.
Mutual Exclusivity : A constructor cannot call both this(...) and super(...) . If neither is written, the compiler automatically inserts super(); on line 1.
No Circularity : Constructor chaining cannot form an infinite recursive loop (e.g., A() calls this(1) and A(int) calls this() ). The compiler detects constructor recursion and issues a compile-time error: recursive constructor invocation .
Static Context Restriction : Arguments passed to this(...) or super(...) cannot reference instance members, instance methods, or the this reference of the object under construction because the object instance does not yet exist. public class Account {
- private String id;
- private double balance;
- public Account() {
- this("DEFAULT", 0.0); // Chained constructor call
- }
- public Account(String id, double balance) {
- super(); // Implicit if omitted
- this.id = id;
- this.balance = balance;
- }
- }
- 3. Complete Class and Instance Initialization Order
When a class is referenced and an object is instantiated via new , initialization proceeds through two distinct phases: Class (Static) Initialization and Instance Initialization . Phase 1: Class (Static) Initialization (Occurs once upon first class reference)
- 1. Superclass static fields & static initialization blocks (in declaration order)
- 2. Subclass static fields & static initialization blocks (in declaration order)
- Phase 2: Instance Initialization (Occurs every time 'new' is executed)
- 3. Subclass constructor is entered, immediately delegating via super(...)
- 4. Superclass instance fields & instance initializer blocks (in declaration order)
- 5. Superclass constructor body executes
- 6. Subclass instance fields & instance initializer blocks (in declaration order)
- 7. Subclass constructor body executes
- The Classic Exam Trap: Calling Overridden Methods from Super Constructors
If a superclass constructor invokes an instance method that is overridden by the subclass, dynamic method dispatch invokes the subclass implementation at runtime. However, at that moment, the subclass instance fields have not yet been initialized—they hold default primitive values ( 0 , false ) or null . class Base {
- int count = 10;
- Base() {
display(); // Calls overridden method in Child!
- }
- void display() {
- System.out.println("Base count: " + count);
- }
- }
- class Child extends Base {
- int count = 20; // Initialized AFTER Base constructor completes
- void display() {
- System.out.println("Child count: " + count);
- }
- }
- public class InitTest {
- public static void main(String[] args) {
- new Child(); // Outputs: Child count: 0
- }
- }
At the time Base() runs, Child.count is still uninitialized ( 0 ). The output is Child count: 0 , not 20 or 10 .
- 4. Object Lifecycle, Heap Allocation, and Garbage Collection
- Stack vs. Heap Allocation
Stack : Stores active thread execution frames, local primitive variables, and references to objects residing on the heap.
Heap : Stores all object instances and arrays. Memory is allocated on the heap whenever new is evaluated.
Root Reachability
Java employs a tracing garbage collector that builds an object graph starting from Garbage Collection (GC) Roots :
Active thread local variables on call stacks.
Static reference variables held in loaded classes.
JNI (Java Native Interface) global and local references.
An object on the heap is eligible for garbage collection when there is no path of references connecting it to any live GC root.
Becoming Eligible for GC
Dereferencing / Nullification : Setting the reference variable to null ( ref = null; ).
Reassignment : Pointing the reference to another object ( ref = new OtherObject(); ).
Out of Scope : When a method returns, its local stack frame pops, discarding local references.
Islands of Isolation : When two or more unreferenced objects reference each other in a closed loop, but none can be reached from any GC root. The entire group is immediately eligible for garbage collection. class Node {
- Node friend;
- }
- public class IsolationDemo {
- public static void main(String[] args) {
- Node a = new Node(); // Object 1
- Node b = new Node(); // Object 2
- a.friend = b;
- b.friend = a;
- a = null;
- b = null;
// Both Object 1 and Object 2 form an island of isolation and are eligible for GC!
- }
- }
- 5. Garbage Collection Invocations and Cleanup Modernization
- System.gc()
Invoking System.gc() or Runtime.getRuntime().gc() sends a request to the JVM suggesting that a collection cycle be performed. It is never a guarantee. The JVM may ignore the request or defer execution.
Deprecation and Removal of Finalizers
Historically, the Object.finalize() method allowed an object to perform cleanup before memory reclamation. However, finalizers suffer from fundamental design flaws: unpredictable timing, potential thread stalls, ignored exceptions, severe performance overhead, and the ability to resurrect dead objects.
finalize() was deprecated in Java 9.
Marked for removal in Java 18 (JEP 421).
Modern Alternatives: AutoCloseable and Cleaner
AutoCloseable & Try-With-Resources : The preferred standard for prompt, deterministic resource reclamation (e.g., closing file descriptors, network connections, and database handles).
java.lang.ref.Cleaner : Introduced in Java 9 to replace finalizers for non-deterministic background cleanup using phantom references, avoiding object resurrection and thread starvation.