Final exam Flashcards
4 phases running a Java program
- edit: store program in .java file
- compile: use java compiler (Javac) to create bytecodes from source code to .class file
- load class: read bytecodes in .class
- execute: Java Virtual Machine (JVM) translates bytecodes into machine language
Fields
State or properties of object.
Methods
Behavior or actions of an object. May model concrete things, abstract things or tasks.
Classes
Classification of objects, describes commonality of sets of similar objects.
Object
Instance of a class.
Static fields
Independent of object, exists once per class and shared by all objects of class.
Constructor
Speical method, to create object of class (via new).
Static methods
Independent of any object, cannot access fields or methods. Connected to class.
Void methods
Type of method that returns nothing.
Array
Ordered list of variables of the same type. Size of array is predefined.
Program
Collection of interacting objects (from classes).
How to access fields?
objectName.fieldName
How to invoke methods?
objectName.methodName()
Which types are there + examples?
- primitive type: int, long, short, boolean, double, float, char (support operations +, -, *)
- reference type: classes
String is special type: support concatenation (+)
A variable ___ to an object, and ___ an address.
A variable refers to an object, and contains an address.
Which type has an address?
Reference type, stored as objects.
What does ‘ ==’ check between two variables?
Whether they have the same address.
What does ‘ c1.equals(c2)’ check between two variables?
Check the equivalence in fields.
Aliasing
Two different variables for the same object (address), with ‘ c1 = c2’
Garbage collection
Removes unused addresses on its own.
this Object
Default calling object. Inside class passed implicitly.
What are the Object Oriented fundamentals?
Encapsulation, Separation of Concerns and Loose Coupling.
Encapsulation
Information hiding from user, to keep people from breaking your code.
3 methods for encapsulation + explain
- change state only via behavior (getters and setters)
- hide implementation types (private methods)
- composition = identify what varies and separate that from what stays the same