Variable Types
Data Access
UML and Relationships
Foundational Definitions
Java & Random Trivia
100

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

100

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

  • Only one public class in a Java program (name must match filename)
100

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

100

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

100

how to compare two strings

String1.equals(String2)

200

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

200

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). 

  • Private variables can be accessed by public getter methods
  • Private modifiers is how an object encapsulates itself and hides data from the outside world
200

Inheritance relationship (1 point for how to draw it)

(need 3 out of 5 points)

  • Inheritance - class A is a class B

  • One thing is general (superclass) which is extended by a specific thing (subclass)
  • Solid line with a hollow arrowhead pointing to the general thing
  • Multiple children possible
  • Multiple parents are not supported by Java
200

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

200

'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)

300

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




300

mutator

(1 point)

  • a type of method used to control changes to an encapsulated instance variable (aka setter method)

300

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

300

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

  • A given class is defined only once, while an object can be created from it many times
  • A class is defined with the class keyword while an object is created with the 'new' keyword
  • Any example e.g. Book vs "Harry Potter"
300

Method overloading

(1 out of 3 points)

  • Method with the same name has multiple implementations for different argument lists/signatures
  • Constructor in Java can be overloaded
  • Aka compile time (static binding) polymorphism
400

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

400

accessor

(1 point)

  • a type of method which returns the value of a private instance variable (aka getter method)

400

define UML

(3 out of 4 points needed)

  • Unified Modeling Language
  • A graphical standard for documenting conceptual information about software systems
  • Can make the software development process more efficient
  • Shows the system’s classes, their attributes, methods, and relationships between objects

400

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

  • In Java, written with same name as class and no return type
  • The Java compiler provides a default constructor if you don't have a constructor in the class

  • Can overload constructors
400

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

500

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)

500

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

  • Gives the subclass a chance to use a helper method while preventing an unrelated class from trying to use it
500

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


500

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

500

Write code to define a stack in Java

Stack<Integer> myStack = new Stack<>();

(or any other valid data type)

M
e
n
u