Abstraction, Abstract Classes and Interfaces in Java
Abstraction exposes what a type does and hides how. Abstract classes share partial implementation, interfaces declare a capability.
Notes related to the Java language.
100 notes tagged
Abstraction exposes what a type does and hides how. Abstract classes share partial implementation, interfaces declare a capability.
One reference type, many possible behaviours. Polymorphism is what lets code work with a supertype and stay correct as new subtypes appear.
A subclass replaces inherited behaviour by declaring the same signature, and the JVM chooses the version at runtime from the actual object.
Inheritance lets a subclass acquire the members of a superclass, creating an is-a relationship that polymorphism is built on.
Four levels of visibility control who can see a member, and choosing the narrowest one that works is the single easiest design win.
Encapsulation hides internal state behind a deliberate public surface, so a class can guarantee its own rules stay true.
static binds a member to the class rather than to any instance, which changes when it is created, how it is accessed and what it can see.
Inside an instance method, this is a reference to the object the method was called on, which resolves shadowing and enables chaining.
A constructor runs once when an object is created, and its job is to leave that object in a valid state.
A class describes the state and behaviour of a kind of thing, and an object is one concrete instance of that description held in memory.
When text is built piece by piece, a mutable buffer avoids the copying that repeated String concatenation forces.
String is an immutable object with a shared literal pool, and both facts explain how comparison, concatenation and performance behave.