local variable
(need 1 out of 3 points)
a variable defined within a block/method
created when block is entered and destroyed after exiting
Their scope is the block of code in which they are declared so they can only be accessed there
public
(need 1 out of 3 points)
Can be accessed from any other class in the project
All public methods and variables of a class are inherited by its subclasses
Dependency (1 point for how to draw it)
(need 2 out of 4 points)
class A uses class B
One thing depends on the other thing / A change in the independent thing will affect the dependent thing
But class A doesn’t contain an instance of class B as part of its own state
Graphically represented as a dashed directed line. The arrowhead points towards the independent thing
Encapsulation
(2 out of 3 points needed)
Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods
If a field is declared private, it cannot be accidentally accessed by anyone outside the class thereby providing security to the fields within the class
Also referred to as data hiding
how to compare two strings
String1.equals(String2)
instance variable
(need 2 out of 4 points)
- non-static variables
- declared in a class outside any method
- created when an object of the class is created and destroyed when the object is
- can use access modifiers
private
(need 1 out of 3 points)
Private: methods, variables, and constructors that are private can only be accessed within the declared class itself (most restrictive level).
Inheritance relationship (1 point for how to draw it)
(need 3 out of 5 points)
Inheritance - class A is a class B
Inheritance
(2 out of 3 points)
Creating or extending a more specific class from an existing general one
So a subclass will acquire the states and behaviors of its parent class
Helps to reuse, customize and enhance existing code
'this' keyword
(need 2 out of 6 points)
Keyword used inside methods or constructors of a class
Refers to any member of the current object
When we have one instance variable and one local variable/method parameter, the local variable will hide the instance variable
‘this’ is used with a field to point to the instance variable instead of the local one
‘this’ can also be used inside constructors to call another overloaded constructor in the same class (explicit constructor invocation). It is required as the constructor cannot be called explicitly
Cannot use ClassName(argument) - instead use this(argument)
class variable
(3 out of 4 points)
Declared within a class, outside any method
with the ‘static’ keyword
The same across all instances of the class
Can be accessed with the class identifier or the object identifier
mutator
(1 point)
a type of method used to control changes to an encapsulated instance variable (aka setter method)
Aggregation (1 point for how to draw it)
(need 3 out of 5 points)
class A has a class B
One thing is a part of another thing (‘whole-part’)
Special case of association, solid line with hollow diamond head towards the whole thing
Both can exist without the other
The relation is unidirectional - A has B but B doesn’t have A necessarily
Class vs Object
(need 3 out of 5)
Object is a particular instance of a class, while class is a template for creating objects
No memory is allocated when a class is created (except for static variables), while an object is allocated memory space when it is instantiated
Method overloading
(1 out of 3 points)
parameter variable
(2 out of 2 points)
the identifier for the information expected to be passed to functions and procedures
where the specific values passed are arguments
accessor
(1 point)
a type of method which returns the value of a private instance variable (aka getter method)
define UML
(3 out of 4 points needed)
Shows the system’s classes, their attributes, methods, and relationships between objects
Constructor
(3 out of 5 needed)
method invoked when an object of that class is created (using the ‘new’ keyword)
on object creation, used to initialize the instance variables in the object
The Java compiler provides a default constructor if you don't have a constructor in the class
Method overriding
(need 2 out of 5 points)
For inherited methods where the child class has the same method as the base class. In this case the child class overrides the parent class method
the object type (NOT parameter variable type) determines which method is used at runtime
Overriding methods must have the same return type and must not have a more restrictive access modifier
Static and final methods, constructors cannot be overridden
Aka runtime (dynamic binding) polymorphism
primitive
(define and name at least 4 examples)
the most basic data types available within Java (boolean, byte, char, short, int, long, float, and double)
Define the 'protected' access modifier and explain why it is useful
variables/methods can be accessed from the class itself, its subclasses AND all classes in the same package as the class
how to draw in a UML diagram (must get all for points):
- class name
- static variables
- constant variables
- access modifiers
- methods with return types and parameters
- variables with data type
- underline for static, all caps for constant
- ClassName in the top row of table
- Variables and methods written as the following
vis attribute : type
vis operation (arg list) : return type
Polymorphism
(need 3 out of 4 points)
Means “Many forms”
Adapting a single action in different ways - a method doing different things based on the object it is acting upon
Allows you to define one interface and have multiple implementations
Examples: method overloading, method overriding
Write code to define a stack in Java
Stack<Integer> myStack = new Stack<>();
(or any other valid data type)