• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/72

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

72 Cards in this Set

  • Front
  • Back

What is the relationship between a class and an object?

A class defines the structure and behaviour of all entities of a given type, an object is one instance of that type of entity

How does a class model object state?

State of an object defined in a class by the fields

How does a class model state behaviour?

Behaviour of an object defined in a class by the methods

What is the purpose of the static keyword?

Static members belong to the class instead of a specific instance


Only one instance of a static field exists

What are the purpose of get and set methods?

Get methods return the value of a field


Set methods set the value of a field

What is the purpose of a constructor method?

The constructor method is called to create a new class object

What three tasks does the new operator conduct?

Instantiates a class by allocating memory for a new object


Returns a reference to that memory


Invokes the object's constructor

Given a class, can you identify its fields, constructors and methods?

Field: private typeName;




Constructor: public className( typeName) { ... }




Methods: public getTypeName() { return typeName; }

How does the use of private and public access modifiers assist encapsulation?

The fields within the class are private, only the class needs to access them


The interface is public, allowing the user to access/modify the internal state

What are the benefits of encapsulation?

Encapsulation protects the data fields from unauthorised access


Also ensures that data fields are modified consistently


Encapsulation allows you to change the way data is stored without affecting the external use of an object

What is the difference between a primitive and a reference type?

Primitive types are basic types of data


Reference types are any instantiable class, as well as arrays

What are the 8 primitive types?

Byte, short, int, long, float, double, boolean, char

Name some examples of reference types

String, Scanner, Random, Die, int[], String[]

Are generic parameters compatible with both types?

No, only reference types

What is meant by auto-boxing and unboxing?

Auto-boxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes


If the conversion goes the other way, it's unboxing

Could you implement a simple class based on a UML design?

Top bar: class name


Middle bar: field names, types


Bottom bar: methods

Can you identify and draw a composition relationship?



Can you identify and draw an aggregation relationship?



Can you identify and draw an inheritance relationship?



Given a short case study that identifies classes and their relationships, can you combine these concepts into a UML class diagram?



Given two classes, can you identify a superclass and a subclass?

The subclass will always extend its superclass

Can a subclass stop methods from being inherited?

No, but there are ways around it


Making the relevant method in the superclass private


Or moving the method into the subclass

What is the meaning of methods that are inherited?

Inherited methods are those which are predefined from the superclass and passed down to the subclass

What is the meaning of methods that are overridden?

Overridden methods are those which are inherited form the superclass, but are redefined by the subclass

What is the meaning of methods that are newly defined?

The term "redefinition" isn't usually used with regards to Java methods - either override or overload


To overload in Java is to create two methods in the same class with the same name, but different signatures

Are you familiar with the substitution principle?

Substitutability is a principle in OO programming, stating that, in a program, if S is a subtype of T, then objects of type T may be replaced with objects of type S

What is the difference between upcasting and downcasting?

Up-casting is casting to a supertype


Down-casting is casting to a subtype

If an object of type X is assigned to a variable of type Y, what are the implications in terms of the methods that can, and cannot be invoked?

You can only use methods that would be defined in object X's interface


If you later decide to use a different implication of X, it is easy

Do you understand the implications of making a method final?

You can declare some, or all of a class' methods final


You use the final keyword in a method declaration to indicate that the method cannot be overridden by subclasses

Can you describe the diamond problem that may arise if multiple inheritances were permitted?

The diamond problem is an ambiguity that arises when two classes, B and C, inherit from A, and class D inherits from both B and C


The compiler gets confused as to which methods it should use

Explain the purpose of the @Override annotation

The @Override annotation is used to redefine methods for different classes

Can you explain the purpose of the toString() method and its conventional formation?

This method is inherited from the Object class, and defines how you print out an object in a string format


For example:


return "Person:[name: " + name + ", age: " + age + "]";

Can you explain the purpose of the equals() method?

They are used to test equivalence in objects

Given a UML class diagram, can you write an overridden equals() method?

@Override


public boolean equals(Object obj) {


if(obj == this)


return true;


if(obj == null || obj.getClass() != this.getClass())


return false;


Person guest = (Person) obj;


return age == guest.getAge() && name = guest.getName();


}

What is the difference of testing equality using the equals() method or the == operator, and where are they both appropriately used?

== compares memory addresses, equals() compares the values in the objects

What is the default behaviour of the equals() method you inherit from Object?

It is the same as the comparison operator; it compares memory addresses

Can you explain the purpose of the compareTo() method?

It is used for comparing two strings lexicographically


Each character of both strings is converted into a Unicode value, and so if both the strings are equal, it returns 0, else it returns a positive/negative value

Given a UML class diagram, can you implement a compareTo() method?

@Override


public int compareTo(Object that) {


if(this == that) return 0;




primitive numbers use >, <


booleans use &&, and (... && !...)


Other Objects use a comparison int, and the compareTo method recursively

Would you be able to use the compareTo() method in a test class to compare objects?

You can call the method to test two objects, that can be equal, to test equality

Can you explain how compareTo() assists in sorting a list?

It defines whether an object should be placed before or after another object, from whatever is returned from the method

Why might you choose to declare an interface type and initialise this with a concrete class type?

An interface gives you the ability to specify a set of behaviours that all classes implementing the interface will share in common


We can define variables and collections that don't have to know what kind of object they will hold

Can you use informed decisions to identify an appropriate data structure to use?

In class X, there is an ArrayList of type Y, which shows the aggregate relationship


X has many Y, stored in an ArrayList

Can you implement some of the common methods that an aggregate class would contain, e.g. add, remove, size, etc - all via delegation?

Kennel k = new Kennel();


Dog d1 = new Pug("Carlie");


Dog d2 = new Labrador("Rex");


k.addDog(d1);


k.addDog(d2);


System.out.println(k.getDogs());

What enables an aggregate class to be used within a for-each loop

The class must implement iterable, as well as a method that defines what it should iterate over

Can you write a for-each loop?

for(Module m : StudentProfile.getCourse().getModulesOnCourse())


System.out.println(m.toString());

Can you outline the three components that make up a stream pipeline, with one or more example of each?

A source - collection, array, generator function, I/O channel


Zero or more intermediate operations that return a new stream - filter, map, limit, etc.


A terminal operation that produces a non-stream result - forEach, count, anyMatch, etc.

What is a functional interface?

An interface that is defined with only a single abstract method

What is a lambda expression?

A lambda expression is an anonymous function that can be used to create delegates, or expression tree types

Can you write basic functions using lambda expressions?

Names.stream().filter(Name -> Name.length() > 5).forEach(System.out :: println);

How do functional interfaces provide a basis for lambda expressions?

A functional interface is a runnable block of code which can be the target of a lambda expression

Can you explain how the Border Pane lays out its child nodes?

Nodes can be placed in five regions - top, bottom, centre, left, right


If application doesn't need regions, there is no need to define it, and no space is allocated to it

Can you explain how a Border Pane behaves when its container is resized?

If the window is larger than the space needed for each region, the space is given to the centre node by default


If the window is smaller, the nodes may overlap

Can you explain how the HBox lays out its child nodes?

The HBox layout provides an easy way for arranging a series of nodes in a single, horizontal, row

Can you explain how the HBox behaves when its container is resized?

The padding property can be set to manage the distance between the nodes and the edges of the HBox


Spacing can be set to manage the distance between the nodes

Can you explain how the VBox lays out its child nodes?

The VBox layout is identical to HBox, except its nodes are laid out in a vertical column

Can you explain how the VBox behaves when its container is resized?

The padding property can be set to manage the distance between the nodes and the edges of the VBox pane


Spacing can be set to manage the distance between the nodes


Margins can be set to add additional space around the individual controls

Can you explain how the StackPane lays out its child nodes?

The StackPane layout places all of its nodes within a single stack, with each new node added on top of the previous node

Can you explain how the StackPane behaves when its container is resized?

The alignment property can be set to manage how children are positioned in a StackPane


This property affects all children, so margins can be set to adjust the position of individual children in the stack

Can you explain how the Grid Pane lays out its child nodes?

The Grid Pane enables you to create a flexible grid of rows and columns in which to lay out nodes


Nodes can be placed in any cell, and can span cells as needed

Can you explain how a Grid Pane behaves when its container is resized?

Gap properties can be set to manage the spacing between rows and columns


The padding property can be set to manage the distance between the nodes and the edges of the grid

Can you explain how the Flow Pane lays out its child nodes?

The nodes within a Flow Pane are laid out consecutively and wrap at the boundary set for the pane


Nodes can flow vertically or horizontally

Can you explain how a Flow Pane behaves when its container is resized?

Gap properties can be set to manage the spacing between the rows and the columns.


The padding property can be set to manage the distance between the nodes and the edges of the pane

Can you explain how the Tile Pane lays out its child nodes?

A Tile Pane is similar to a Flow Pane


Nodes are in a grid, where each cell is the same size


Nodes can be laid out vertically or horizontally


Horizontal tiling wraps the tiles at the Tile Pane's width boundary, vertical at the height boundary

Can you explain how a Tile Pane behaves when its container is resized?

Gap properties can be set to manage the spacing between the rows and columns


The padding property can be set to manage the distance between the nodes and the edges of the pane

Can you explain how an Anchor Pane lays out its child nodes?

Anchor Panes enable you to anchor nodes to the top, bottom, left, right, or centre of the pane

Can you explain how the Anchor Pane behaves when its container is resized?

As the window is resized, the nodes maintain their position, relative to the anchor point


Nodes can be anchored to more than one position, and more than one node can be anchored to the same position

What is the benefit of separating the controller in a typical MVC design?

It allows for flexibility


Because the view doesn't care about the underlying model, supporting multiple file formats is easier - just add a model subclass for each

What is an immutable object?

An immutable object is one who's state cannot be changed

Can you provide an example that shows how the String class is immutable?

A string is initialised to a value, using the concat() method on that string returns a new string


The state of the original string is not changed as the value from concat() is not stored

What is the difference between a String literal and a String object?

A String literal is initialised like this:


String a = "abc";


If String b = "abc", a == b would return true




String c = new String("abc"); is a String object


String d = new String("abc");


c == d would return false because they have different references

Can you explain how to make an immutable class?

Declare the class as final, so it can't be extended


Make all fields private so that direct access is not allowed


Don't provide setter methods for variables


Make all mutable fields final so that its value can only be changed once


Initialise all fields via a constructor, performing deep copy


Perform cloning of objects in the getter methods to return a copy, rather than returning actual object reference

Can you identify the requirement for, and implement, defensive copies?

Any mutable objects within a field should be copied when being passed to a method