Module 2 · Lesson 1 of 34/22 in the course~15 min
Module lessons (1/3)
Classes, Objects and JVM Heap
Lesson preview5 hands-on exercises readyCourse Java · Module 2 — Fundamentals of OOP
Stack/Heap template for new objects, encapsulation with private, constructors and reference this.
What you'll learn in this lesson
- Model real concepts through classes (state with instance fields + behavior with methods).
- Initialize the state consistently using constructors and disambiguating with
this. - Visualize how the JVM separates references on the Stack from instances allocated on the Heap.
Overview
In Object Oriented Programming (OOP), a class is the blueprint that defines structure and behavior; an object is a concrete instance allocated in memory via new.
A constructor has the exact same name as the class and does not declare any return types (not even void):
Sections covered in this lesson
- 11. Instance, Constructors and Reference fields
this - 22. Instantiate with
newand Basic Encapsulation - 33. Interactive Simulator: JVM Stack Frame vs Object Heap
- 4Try it yourself
Pro Lesson · Module 2 — Fundamentals of OOP
Unlock "Classes, Objects and JVM Heap" and the full Course Java curriculum
Stack/Heap template for `new` objects, encapsulation with `private`, constructors and reference `this`.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course Java plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.