OOP
Objects, inheritance, interfaces, records and the patterns that hold real Java together.
Take this course in the learning hubLessons
- Classes and ObjectsHow a class becomes an object, and why a variable holds a reference rather than the object itself.
- ConstructorsHow to build objects that are valid from their very first instruction, using chained constructors.
- EncapsulationWhy fields go private, and how keeping rules next to data stops callers from breaking your object.
- toString and the Object ClassWhat every object inherits from Object, and how to write a toString that is worth reading in a log.
- Inheritance and superHow extends shares state and behaviour, how super works, and when inheritance is the wrong tool.
- PolymorphismHow one call site runs different code depending on the actual object, and why that kills if/else chains.
- Abstract ClassesWhen to use an abstract class, and how the template method pattern fixes the steps of an algorithm.
- Interfaces and Default MethodsHow interfaces define capability, and how default and static methods let those contracts evolve safely.
- Composition Over InheritanceWhy holding an object as a field usually beats extending it, and how to swap behaviour at runtime.
- The equals / hashCode ContractThe rules hash collections rely on, and exactly what breaks when you override only one of the two.
- Immutability and Defensive CopiesHow to build objects that cannot change, and why final alone is not enough to stop mutation.
- Static Nested vs Inner ClassesThe real difference between a static nested class and an inner class, and why static is the safer default.
- Sealed TypesHow sealed types close a hierarchy so the compiler can prove your switch handles every possible case.
- SOLID in PracticeThe five SOLID principles stated in concrete Java terms, and where each one actually earns its keep.
- Factory and Strategy PatternsHow to pass behaviour in as a parameter and centralise the decision of which implementation to build.
- Builder and Singleton PatternsHow to assemble complex immutable objects readably, and the one singleton form that is hard to get wrong.
- Overloading vs OverridingWhy the object decides an override, while the variable decides an overload.
- super and this: Constructor ChainingHow this(...) delegates sideways and super(...) goes up, and why the order is fixed.
- Access ModifiersWhat private, package-private, protected and public actually let through.
- Object Initialisation OrderThe exact order of static blocks, field initialisers, instance blocks and constructors.
- Casting and instanceof PatternsPattern matching for instanceof, and why a plain cast can still blow up at runtime.
- Covariant Return TypesHow an override can narrow its return type, so callers stop writing casts.
- Static Factory MethodsWhy a named static method often beats new: validation, caching and hidden subtypes.
- Interface or Abstract Class?A short decision procedure for choosing between an interface and an abstract class.
- Default Methods and the DiamondWhat happens when two interfaces hand you the same default method, and how to pick.
- Anonymous Classes and LambdasWhat an anonymous class gives you that a lambda does not, and when each one fits.
- Records as Value ObjectsHow records generate equals, hashCode and toString, and where validation goes.
- The Observer PatternHow one object tells many listeners that something happened without knowing who they are.
- Dependency Inversion in PracticeConstructor injection in plain Java, and why it makes tests need no mock library.
- Enums as ObjectsEnum constants are objects, so each one can carry data and its own method body.
- The Four Pillars of OOPAbstraction, encapsulation, inheritance and polymorphism, named once and shown in one small program.
- IS-A, HAS-A and Object LifetimeAssociation, aggregation and composition: who owns whom, and what still exists when the owner is gone.
- Writing Your Own Generic TypesType parameters on your own classes and methods, bounded types, and what erasure will not let you do.
- Record Patterns in switchTake records apart inside a switch, filter an arm with when, and let the compiler prove the coverage.
- Copy Constructors and Deep CopiesWhy clone() is a trap, how a copy constructor reads, and where a shallow copy quietly shares state.
- equals Across a Class HierarchyWhy adding a field in a subclass breaks equals symmetry, and the two honest ways out of it.
- Decorator and AdapterTwo wrapping patterns: one adds behaviour behind the same interface, the other changes the interface.
- Designing Your Own ExceptionsWhen a new exception type earns its keep, what to put on it, and why the cause must survive.
- Coupling, Cohesion and DemeterTell an object what you want instead of walking through its fields, and keep each class about one thing.
- Why equals and inheritance cannot both be rightSymmetry or substitutability - with instanceof you cannot have both.
- Never call an overridable method from a constructorThe subclass override runs before its own fields exist.
- Liskov violations that compile perfectlyA subclass that satisfies the compiler and breaks every caller.
- Variance: why arrays and generics disagreeArrays are covariant and unsafe; generics are invariant and need wildcards.