Constructors
Methods called to initialise new objects
Private = Protected Static function - Uses the methods on the object
Constructors - A function which will automatically be called when object is created. Has same name as class. Used to initialise the object
Default Constructor - used when you pass no parameters to new.
Current object reference
Methods (non-static member functions) know which object they are acting upon 'this' is an object reference to the current object. Can miss it out and will be assumed. Sometimes need to tell something else which object you are working on, and you commonly use 'this' to do so
Static Members
Static members (functions and data) are not associated with any specific object. Have not 'this' Often shared between all of the objects of that class, rather than a specific object
ArrayList
Standard Java classes. Stores items as a list. Can grow.
- abstraction: don't need to know how it is implemented, only know its interface.
Imports and Packages
Code is organised into a hierarchical structure of packages
All standard classes are in packages and don't need to say which package the class you want to use is from
Array list is in the java.util
package.
Generic Types
Array list is a generic type
In java, generic has a<type>
added at the end of the name to say what it is
Runtime behaviour cannot depend upon the parameterised type
- Behaviour must be the same regardless of the type of object
- This is Parametric Polymorphic
Abstraction
- Do not need to know how the classes are implemented in order to use them
- Hiding all but the information the user needs
- Also allows user to change the implementation of a class later if needed. Nothing that uses it should need to change - key for decomposition
Composition/Aggregation
Can be though of as one object containing, or 'having' another Aggregation and Composition are both important in oops. Both mean that an object is composed of, or 'aggregates', other objects.
Aggregation: Items are contained in, or from a part of, the container item, but have a lifetime of their own Composition: The composed items only last as long as the containing item lasts, so they cease existing when container does