Mind map
Class
Map content
Class
Class Members
- Instance variables: State
- Lives on the heap
- reference variable
- Default value: 0, 0.0, false, '\u0000', null
- non-access modifiers
- transient
- volatile
- final: constant
- methods: Behavior
- Local variables
- Lives on the stack
- final: constant
- No default value; using uninitialized one gives compiler error
- Var-arg type
- Arguments vs Parameters
- Return Type
- Covariant Returns
- non-access modifiers
- Final Method
- Abstract Method
- Synchronized Method
- Native Method
- Strictfp Method
- Local variables
- Instance variables: State
static varibales & static methods
Overloading rules:
- MUST change the argument list
- CAN change the return type
- CAN change the access modifier
- CAN declare new or broader checked exceptions or eliminate ant ones
- CAN coexist in the same class or in a subclass
Inheritance: the mechanism by which an object acquires properties of another object.
- Overriding
- MUST not change the argument list
- CAN not change the return type except for covariant returns
- when an exact match isn't found, the compiler determines which method to use
- Widening has precedence over autoboxing (for backward compatibility)
- autoboxing has precedence over Var-args
- Seelct the method with the smallest argument that is wider than the parameter
- Widening
- Widening Reference Variable
- autobox and then widen the parameter for a match to be made is LEGAL: Case a parameter of type Object
- Widening Primitive Variable
- widen and then autobox the parameter for a match to be made is ILLEGAL : too much for the compiler
- Widening Reference Variable
- You can combine var-args with either widening or autoboxing
- Declared checked exceptions should respect Backward compatibility with legacy code
- Must not throw new or broader checked exceptions
- Can reduce or eliminate exceptions
- Restrictivity
- Must not make more restrictive
- CAN be less restrictive
- Abstract Class
- super keyword
- instanceof
- Overriding
Constructor: Instantiation
- can use any access modifier, including private
- The constructor name must match the name of the class.
- must not have a return type
- legal (but stupid) to have a method with the same name as the class
- Abstract classes have constructors
- Interfaces do not have constructors (not part of an object's inheritance tree)
- The only way a constructor can be explicitely invoked is from within another constructor
- Constructor Chaining
- super constructor
- Every constructor has, as its first statement, either a call to an overloaded constructor (this()) or a call to the superclass constructor (super()), although remember that this call can be inserted automatically by the compiler.
- If you do not type in the call to super() or a call to this(), the compiler will insert a no-arg call to super() for you, as the very first statement in the constructor
- A call to super() can be either a no-arg call or can include arguments passed to the super constructor.
- Only static variables and methods can be accessed as part of the call to super() or this(): super(Animal.NAME)
- Default constructor
- Default no-arg constuctor automatically generated by the compiler: If you don't type a constructor into your class code
- A no-arg constructor is not necessarily the default but the default constructor is always a no-arg constructor
- The default constructor has the same access modifier as the class, has no arguments, includes a no-arg call to the super constructor (super()).
object
- equals(), hashCode(), and toString()
- overriding equals() & hashCode() rules:
- use the instanceof operator to be sure you're evaluating an appropriate class.
- compare the objects' significant attributes
- the equals() contract
- Reflexive: x.equals(x) is true.
- Symmetric: If x.equals(y) is true, then y.equals(x) must be true.
- Transitive: If x.equals(y) is true, and y.equals(z) is true, then z.equals(x) is true.
- Consistent: Multiple calls to x.equals(y) will return the same result.
- Null: If x is not null, then x.equals(null) is false.
- If you override equals(), override hashCode().
- if two objects are equal, their hashcodes must be equal.
- An overridden equals() must be at least as precise as its hashCode() mate.
- hashCode() contract
- Consistent: multiple calls to x.hashCode() return the same integer.
- If x.equals(y) is true, x.hashCode() == y.hashCode() is true.
- If x.equals(y) is false, then x.hashCode() == y.hashCode() can be either true or false, but false will tend to create better efficiency.
- transient variables aren't appropriate for equals() and hashCode().
- overriding equals() & hashCode() rules:
- Lives on the heap
- State + Behavior
- equals(), hashCode(), and toString()
Initialization Block
- Init blocks execute in the order they appear.
- Static init blocks run once, when the class is first loaded: static { x = 7 ; }
- Instance init blocks run after the constructor's call to super() every time a class instance is created: { y = 8; }
IS-A vs HAS-A
Polymorphism (many forms): process objects differently based on their data type
- static polymorphism (Decided at compile-time): Method Overloading
- dynamic polymorphism (resolved at runtime): Method overriding
Encapsulation: the attributes of an entity are enclosed in that entity. This gives context to attributes.
Abstraction: a process where you show only “relevant” data and “hide” unnecessary details of an object from the user
Modifiers
- Access modifiers
- Non-access modifiers
Enums
- for(CoffeeSize cs: CoffeeSize.values()) {}
- c1 == c2 and c1.equals(c2) are equivalent
- Special class extending Enum<E> class
- The constructor should be private
Interface
Identifiers
Keywords
Information
- Description
- Mind Map on Class, created by Abdelkrim ZAHMOUNI on 03/10/2018.
- Created by
- Abdelkrim ZAHMOUNI
- Views
- 0
- History
-
- Created by Abdelkrim ZAHMOUNI · Sep 23, 2018
- Copied by Abdelkrim ZAHMOUNI · Oct 3, 2018
- Rating