Java OOP Essentials: quick revision, 44 bites
All 44 revision bites from this kit, free and with no sign-up.
Class vs Object: Blueprint vs Building
A class is a blueprint; an object is the building.
A **class** defines the structure (fields) and behavior (methods) that objects of that type will have. An **object** is a concrete instance created from that blueprint, with its own state.
Takeaway. A class is a template; an object is a living instance with its own data.
Fields and Methods: The Anatomy of a Class
Fields hold data; methods define actions.
Takeaway. Fields represent what an object knows; methods represent what it does.
Defining a Class and Creating an Object
See a complete Java class in action.
Takeaway. Use 'new' to create an object, then access its fields and methods with dot notation.
Primitive vs Reference: The '==' Trap
Comparing objects with '==' can mislead you.
Takeaway. For objects, '==' tests identity, not equality — use '.equals()' for value comparison.
Objects in the Real World: A Bank Account
Your bank account is an object with state.
Takeaway. OOP lets you map real-world entities to code, with each object holding its own state.
Primitive vs Reference Types
Two kinds of variables: store value or store address.
Takeaway. Primitives hold values directly; references hold addresses to objects in memory.
Naming Conventions: Clarity Matters
Names should reveal intent instantly.
Takeaway. Consistent naming makes code readable and maintainable.
Remember: 'new' Creates, Dot Accesses
New makes it, dot uses it.
Think of `new` as the **constructor** that brings an object to life, and the dot (`.`) as the **remote control** to access its fields and methods.
Takeaway. Always use 'new' to instantiate, and dot notation to interact with the object.
Spot the Reference Variable in Exams
Exams love testing reference vs primitive.
Takeaway. Reference variables share the same object; changes through one are visible through all.
Objects Live on the Heap
Objects reside in a special memory area.
In Java, all objects are allocated on the **heap**, while primitive variables and references can live on the stack. The garbage collector automatically cleans up objects no longer referenced.
Takeaway. Java manages memory for objects via the heap and garbage collection.
Constructors: The Object Initializers
Every object starts with a constructor call.
A **constructor** is a special method that initializes a new object when it is created. It has the same name as the class and **no return type**.
Takeaway. Constructors are the entry point for object initialization, ensuring objects start in a valid state.
Default vs. Parameterized Constructors
Two ways to build an object.
Takeaway. Default constructors give basic initialization; parameterized constructors allow custom initial states.
Writing Default and Parameterized Constructors
See both constructors in action.
Takeaway. Default constructors set safe fallback values; parameterized constructors set specific values at creation.
Constructor Overloading: Multiple Ways to Initialize
Same name, different parameters.
**Constructor overloading** means defining multiple constructors in the same class, each with a different parameter list. Java picks the right one based on the arguments passed.
Takeaway. Overloading gives flexibility: you can create objects with varying levels of detail.
Overloading Constructors in Practice
Multiple constructors, one class.
Takeaway. Overloading lets you create objects with default, square, or custom dimensions — all using the same class name.
The 'this' Keyword: Referring to the Current Instance
Disambiguate fields from parameters.
Inside a constructor, `this` refers to the **current object** being created. It's used to distinguish instance variables from parameters with the same name.
Takeaway. `this` clarifies which variable you're referring to and enables constructor chaining.
Using 'this' to Resolve Name Conflicts
Same name? Use 'this'.
Takeaway. `this` is essential when parameter names shadow field names, making code clear and error-free.
Initialization Order in an Object's Lifecycle
What runs first when you create an object?
Takeaway. Fields get default values before the constructor body runs, so you can rely on them being set.
Forgetting the Default Constructor When Overloading
Overloaded? Default disappears.
Takeaway. Once you add a parameterized constructor, the default is gone — plan accordingly.
Misusing 'this()' in Constructors
Constructor chaining has rules.
Takeaway. Constructor chaining via `this()` is powerful but must follow the first-statement rule.
Spotting Constructor Signatures in Exams
Look for the missing return type.
Takeaway. In exam questions, identify constructors by the class name and absence of a return type.
Real-World Use: Configuring Objects with Constructors
How apps use constructors daily.
Takeaway. Constructors are used everywhere to set up objects with required data and valid initial conditions.
Access Modifiers Control Visibility
Who can see your class members?
Access modifiers in Java determine **where** a class, method, or field can be accessed from. They are the foundation of encapsulation, protecting data from unintended external changes.
Takeaway. Choosing the right access modifier controls who can see and modify your code.
The Four Access Levels
Know your four visibility options.
Takeaway. Each modifier gives a different level of access, from most restrictive (private) to least (public).
Private vs. Public: The Core Trade-off
Why not make everything public?
Takeaway. Private protects data; public exposes functionality. Use private by default for fields.
Encapsulation in Action
A real-world bank account example.
Takeaway. Encapsulation ensures that an object's data can only be changed in controlled ways.
Getters and Setters in Java
The standard way to protect fields.
Takeaway. Getters and setters allow controlled access to private fields, enabling validation and future changes.
Making Fields Public for Convenience
Shortcut that breaks encapsulation.
Takeaway. Public fields are a common anti-pattern; use private fields with accessors.
Default to Private, Then Widen
Start restrictive, open up as needed.
Takeaway. The principle of least privilege: give each member the minimum access it needs.
Benefits of Data Hiding
Why hiding data is a superpower.
Takeaway. Data hiding improves reliability and maintainability of your code.
Remembering Access Levels for Exams
A quick memory trick for modifiers.
Takeaway. Use the 'P' trick: Private, Package, Protected, Public — from most to least restrictive.
Encapsulation in Real Libraries
How Java's own APIs use this.
Java's standard library, like `ArrayList`, hides its internal array and exposes methods like `add()` and `get()`. This lets developers change the internal implementation without breaking user code.
Takeaway. Encapsulation is used everywhere in real-world APIs to ensure stability and flexibility.
The ATM Analogy
You don't open the cash drawer.
An ATM exposes buttons (public methods) but keeps the cash and internal mechanisms private. You can't directly grab money; you must use the provided interface.
Takeaway. Encapsulation is like an ATM: controlled access, hidden internals.
Static Belongs to the Class, Not the Object
Static members are shared, not per-object.
In Java, the `static` keyword means a member belongs to the **class itself**, not to any individual instance. All objects of that class share the same static member.
Takeaway. Static members are shared across all instances; instance members are unique per object.
Static Fields, Methods, Blocks, and Constants
Four static things you must know.
Takeaway. Static fields store shared data, static methods provide utility behavior, static blocks initialize static state, and static constants define fixed values.
Static vs Instance: Code in Action
See the difference with a simple class.
Takeaway. Static `count` is shared and incremented by both objects, while `instanceNum` is unique per object.
Calling Instance Members from Static Context
A classic compile-time error.
Takeaway. Static methods work at class level; they need an object reference to touch instance data.
Utility Methods: When Static Makes Sense
Think `Math.max()` — no object needed.
Takeaway. Use static for behavior and values that are independent of any particular instance.
Static vs Instance: Access Rules
Who can call what?
Takeaway. Instance methods can access everything; static methods are limited to static members unless they create an object.
Static Constants: Use `final` with `static`
Constants should be both static and final.
Takeaway. Static final fields create true constants — one shared, immutable value.
How Static Blocks Initialize Class State
Run once when class loads.
Takeaway. Static blocks execute once at class loading, perfect for one-time setup of static data.
Exam Trap: Static Methods Can't Use `this`
No `this` in static context!
Takeaway. In static methods, `this` is invalid — always use the class name for static access.
Real-World Use: Shared Counters and Config
Think of a global counter or app config.
Takeaway. Static members model class-level state that every object shares.
Remember: Static = Shared
Static means 'one for all'.
Think of **static** as **shared** — one copy for the whole class. Instance means **individual** — each object has its own.
Takeaway. Static = class-level shared; instance = object-level unique.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages