Command Palette

Search for a command to run...

Posts in series "Advanced Java"

17 posts

[Advanced Java] The Four OOP Principles in Depth: Where Object Designs Go Wrong

The four OOP principles in Java taken past the definitions on OpenJDK 21: encapsulation enforced by behaviour instead of accessors, the inherited method that walks around a subclass guard, the delegation rewrite, switching on types you own versus types you do not, a leaky abstraction in a signature, and a subclass that compiles, passes its own test and still breaks its caller.

[Advanced Java] Nested, Inner, Local and Anonymous Classes in Java

Static nested, inner, local and anonymous classes in Java on OpenJDK 21: the synthetic this$0 field proved with javap, Outer.this and outer.new Inner(), the memory leak an inner class causes, effectively final capture, the Outer$1 class file, and a concrete comparison of anonymous classes against lambdas.

[Advanced Java] Advanced Enums in Java: Constructors, Constant Bodies, EnumMap and the Enum Singleton

Advanced enums in Java on OpenJDK 21: what javap shows an enum actually compiles to, fields and the implicitly private constructor, constant-specific class bodies and the extra class files they emit, abstract methods, enums implementing interfaces, EnumMap and EnumSet, exhaustive switch, the enum singleton reflection refuses to break, an enum state machine, and the ordinal and values() traps.

[Advanced Java] Generics in Java: Type Parameters, Bounded Types, Wildcards and Type Erasure

Generics in Java on OpenJDK 21: the pre-generics Object container and the ClassCastException it produced, writing generic classes and generic methods, bounded and multiply-bounded type parameters, wildcards and PECS with the exact javac errors, type erasure proved with javap, the Signature attribute, bridge methods, and what SuppressWarnings unchecked really promises.

[Advanced Java] SOLID Principles in Java: Five Rules and When to Break Them

The five SOLID principles in Java on OpenJDK 21, each with a before and after that compiles and runs: a class split by its reasons to change, a growing switch replaced by an interface, a subclass that breaks its caller with no warning, an UnsupportedOperationException the compiler could have prevented, a class that cannot run without a file, and where each principle stops paying for itself.

[Advanced Java] Common Design Patterns in Java: Singleton, Factory, Builder, Observer and Strategy

Five design patterns in Java on OpenJDK 21, each one demonstrated inside the JDK itself and each one shown where it does damage: singleton initialisation and the race an unsynchronised null check loses, Integer.valueOf and its cache, a staged builder the compiler checks, a listener that leaks and a listener that stops the broadcast, and Comparator as the strategy type you have already been using.