Class
an extensible program-code-template for creating initial values for states (variables) and implementations of behaviours (functions/procedures/methods)
Identifier
a named pointer that explicitly identifies an object, class, method, or variable
Primitive
the most basic data type available within the Java language
The 8 primitive data types:
boolean, byte, char, short, int, long, float, double
Variable
a value that a program can manipulate in a named storage location, but must be declared before they can be used
Instance variables
Non-static variable
Declared in a class outside any method, constructor or block
Use access modifiers (private, public, protected)
Example: int engMarks, int mathsMarks
Parameter variables
the passing of information/instructions into functions or procedures
Example: (int x, int y)
Arguments
the values that are passed into parameters
Local variable
a variable defined within a block, method, or constructor
Example: int age = 0;
Method
a set of code that can be called at any point in a program by utilising the name
Accessor
returns the value of a private instance (class) variable, also known as a getter method
Mutator
control changes to an encapsulated instance (class) variable/state, also known as a setter method
Constructor method
an instance method that is invoked when an object of that class is created
Object creation rule in Java
When an object is created, one of the constructor method in the class must be invoked (to initialise the instance variables in the object)
The difference between method and constructor
Method | Constructor |
---|---|
Method can be any user-defined name | Constructor must be class name |
Should have return type | It shouldn’t have any return type (even void) |
Method should be called explicitly either with object reference or class reference | Be called automatically whenever object is created |
Method is not provided by compiler in any case | Java Compiler provides a default constructor if there isn’t one |
Method signature
Combination of the method name and the parameter list
Return value
Used to exit from a method, with or without a value.
Method procedures
don’t return any value (void)
Method functions
return a value
The 3 Java access modifiers
public, protected, private
Public
can be accessed from any other class
Private
can only be accessed within the declared class itself
classes can’t be private but methods and variables can
if public getter methods are present in the class, private variables can be accessed outside the class
Protected
accessed only by the subclasses
Summary of access
Modifier | Class | Package | Subclass | World |
---|---|---|---|---|
Public | Y | Y | Y | Y |
Protected | Y | Y | Y | N |
No modifier | Y | Y | N | N |
Private | Y | N | N | N |
extends
used in a sub class to inherit the properties of a super class
Static
a non-access modifier that is applicable for the following: blocks, variables, methods, nested classes
precede its declaration with the keyword static
Encapsulation
hiding methods or variables so other classes cannot manipulate them without going through
The 4 OOP Fundamentals
Abstraction, Polymorphism, Inheritance, Encapsulation
Inheritance
the mechanism by which one class is allowed to inherit the features (states and behaviors) of another class
includes Super Class and Sub Class
Advantages of inheritance
minimises the amount of duplicate code in an application by sharing common code amongst several subclasses
better organisation of code
code is more flexible to change
Super Class
The class whose features are inherited is known as a super class (or base class or parent class)
Sub Class
The class that inherits the other class is known as subclass. The subclass can add is own states and behaviors in addition to the superclass states and behavior
Types of loops
While, do-while, count-controlled
Static arrays
do not change
Features of modern programming languages that enable internationalisation
Common character sets (e.g. Unicode, ASCII)
Platform independent high level languages let code run on many platforms5
Open source movement
supports the use of open-source licences….