What is the purpose of the main method and what is it’s syntax?
The main method is the point of insertion for the program and where we will instantiate classes.
Syntax:
public static void main(String args[]) {
};
What is the essential class structure?
What are the basic properties of a constructor?
remember, instance variables are declared in the class not in the constructor.
What are the important properties of instance variables?
Key differences between local variables and instance variables?
local:
- declared inside methods
- compatible values must be assigned to them before using them
instance:
- declared inside the class (after CONSTANTS) and outside methods
- assigned values in the constructor
- default values are assigned if the constructor does not explicitly assign values to them
What are the responsibilities of the constructor?
the constructor is responsible for…
- ensuring instance variables are set to valid and logical initial values
What happens if we exclude a constructor from our class? what if we include multiple?
if no constructor…
- Java compiler will generate a default constructor and add it to the .class bytecode file
- the auto-generated default constructor will set all instance variables to their default values
if multiple…
- no default constructor is added
- constructors can call upon each other using the “this” keyword
What are some key properties of a Java object?
Briefly summarize the key points of encapsulation and information hiding
encapsulation:
- each class is responsible for exposing and managing its own state
- we put data with the methods that manage it
information hiding:
- wrap objects in a privacy barrier
- users only need to know how to use an object but not how the objects is able to do what it does
What are the visibility modifiers? Explain the scope of each.
What are the basic rules for using visibility modifiers with a class?
When should we use accessors and what is the syntax for accessors (getters)?
when to use…
- access private instance variables, we may write accessors for SOME instance variables
syntax…
public int getValue() {
return this.aValue;
}
usually come before mutators (setters)
When should we use mutators and what is the syntax for mutators (setters)?
when to use…
- change data stored in an object’s instance variables (change the state of an object), we may write mutators for SOME instance variables
syntax…
public void setInstanceVariableTo(<data> newValue) {
oldValue = newValue;
}</data>
usually come after accessors (getters)
What are some important facts to remember about using mutators?
What is the use of the toString method? What are some of its properties?
Why do we use the keyword “this”?
we use “this” to remedy overshadowing
What are some properties of a class’ interface and implementation?
Interface…
- a class’ public interface is composed of it’s public members
- we call a class’ public interface it’s application programming interface (API)
- we say that only a class’ API is visible and that we expose the interface
- class instances communicate with the system and each other through the API’s
Implementation…
- the system and other objects are clueless to the other object’s “inner workings”
- a well designed class hides how it achieves its functionality
- nobody needs to know how a class gets its job done
What are the benefits of information hiding?
What are some rules we should follow to minimize scope, mutability, and accessability?
What is responsibility-driven design (RDD)?
follows Abbot’s Heuristic…
- classes employ self governance: each class must be responsible for manipulating its own data
- RDD leads to high coherence (MORE connections WITHIN a class) and low coupling (LESS connections BETWEEN classes)
- localize change: when change is needed, as few classes as possible should be affected
coupling increases when…
- A has an instance variables that refers to (is of type) B
- A uses object B
- A has a method that references B (via return type or parameter)
- A is a subclass of (or implements) class B
What does UML stand for?
UML = unified modelling language
What is a UML class diagram? What are the three key components?
similar to an entity relationship diagram it represents different classes (entities), their properties (instance variables), and their behaviours (constructors and methods)
three key components…
1. class name
2. attributes (+ for public and - for private)
3. methods (+ for public and - for private)
What are functions in Java called?
methods
What are some key details of methods? What is the syntax for a method header?
syntax (for method header):
public int methodName (final int firstIntParam, final int secondIntParam)