Files:
- Normally there is one class per file.
- If the file has a public class, the file must be named after the class.
- A private class can only exist nested inside another class.
Naming Conventions:
- Class should start with a Capital letter and use CamelCasing.
- Methods and attributes should start with a lowercase letter and use camelCasing.
- Constant or Final attributes should be ALL CAPS and use UNDERSCORE_AS_SPACING.
UML Visibility:
- + means Public (all classes).
- - means Private (only subclasses).
- # means Protected (only classes in same package + subclasses).
References:
- Holds an object’s address.
- Declaring a reference creates no object.
new creates the object.
- An unassigned reference defaults to
null.
p1 = p2 makes both names point to the same object.
- An object with no remaining references is eligible for garbage collection.
Constructors:
- They have the same name as the class and no return type (not even
void).
- Java supplies a default no-arg constructor only if you define none. once you write any constructor, the defaults disappears.
- Constructors can be overloaded
this(...) calls another constructor of the same class and must be the first line.
this refers to the current object. It resolves name clashes, as in this.x = x
Delegation:
- An object hands a task to another object, e.g.
Circle.translate() calls point.translate().
- assigning the passed object as
this.center = center, link them together (same reference) so changes to one affect the other.
- assigning it as
this.center = new Point(center), keep therm independent.