Chapter 4 Flashcards

1
Q

What does an object have?

A

An object has state and behaviour.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does a class contain?

A

A class contains data declarations and method declarations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
What's the difference between a method declaration called
public int roll()
and
public static int roll()
?
A

Without putting static, the method will compute for the object on which the object is called. The variables present in the class of the called object will be the ones of the object on which the object was called.

When writing a static method, it means that the method refers to the class and the variables called inside the method will affect every object of that class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are accessors and mutators?

A

These are also known as getters and setters. Respectively, they retrieve the value of a specific variable and set a new variable to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is it good practice to define a toString method for a class?

A

The toString method will return a string of characters representing the object in the way we want it to.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the data scope?

A

The scope of data is the area in a program in which that data can be referenced.

If data is declared at the class level, then it can be referenced by all methods in that class.
If data is declared within a method, it can be used only in that method.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is instance data?

A
Instance data is any variable declared at the class level.
These variables are not created with the creation of the class itself, but with each creation of the object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is UML?

A

UML stands for Unified Modeling Language. Its diagrams show relationships among classes and objects.

A UML class diagram consists of one or more classes, each with sections for the class name, attributes (data), and operations (methods).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the two possible views of an object? What is encapsulation?

A

An object can be seen in two different ways:

  • Internally: the details of the variables and methods of the class that defines it
  • Externally: the services that an object provides and how the object interacts with the rest of the system.

Encapsulation consists in hiding the inner workings of an object from the client. This is done to avoid the client to directly access or modify the data of an object. With encapsulation the only interaction possible is via the methods of a given class (that we define).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of a modifier? What does a visibility modifier do? What modifiers do we have?

A

A modifier is a Java reserved word that specifies particular characteristics of a method or data.

A visibility modifier allows encapsulation to be done at different degrees.

With "public", the method or data could be accessed from everywhere.
With private, the method or data could be accessed only inside the class in which it's declared.
Without writing anything, the method or data could be accessed only from inside the package (default visibility).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why can’t constants be declared private?

A

Because although the user can access the constant, it cannot be modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between service methods and support methods?

A

Service methods are public, they’re made to interact with the user.
Support methods are private, they’re made to assist service methods and shouldn’t therefore be accessed directly by the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does happen to the flow of control when a method is invoked?

A

The flow of control jumps to the method and executes its code (from top to bottom), before returning to the original flow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does a method header have?

A

The method header has (for example):
public char calc (int num1, int num2, String message)

  • public is the visibility modifier
  • char is the return type of the metjhod
  • calc is the name of the method
  • inside the parenthesis we find the parameters, each indicating variable type and its name)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does a method body have?

A

A method body contains the operation with the variables given in the header. The return expression (unless the methods has return type void) must be consistent with the declaration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s the difference between actual and formal parameters?

A

Actual parameters are the values that are put inside a method header during its call. Formal parameters are the name of the values that are declared together with the declaration of the method.

17
Q

What’s the name of a variable declared inside a method? Where is it recognised?

A

It’s a local variable and it exists only as long the method is in execution.

18
Q

How do you write the Arc (JavaFX) constructor?

A

Arc(centerX, centerY, radiusX, radiusY, startAngle, arcLength)
with startAngle the angle referred to the horizontal line
with arcLength the ANGLE portion of which the arc is going to be drawn.

19
Q

What are different arc types?

A

ArcType.OPEN -> the curve along the ellipse edge
ArcType.CHORD -> end points are connected by a straight line
ArcType.ROUND -> end points are connected to the center point of the ellipse, forming a rounded “pie” piece

20
Q

Through which object can an image be displayed?

A

An image can be loaded as an Image object, but for it to be displayed an ImageView object must be used.

21
Q

What does a stack pane do?

A

A stack pane is a layout pane of JavaFX that puts nodes on top of eachother

22
Q

What are the three objects that control the GUI?

A

Control:
is a screen elements that displays information or allows the user to interact with the program (labels, buttons, text fields, sliders, etc).
Event:
is an object that corresponds to a certain activity/action from the user (mouse is moved/dragged, mouse button is clicked, graphical button is clicked, keyboard, timer, etc.)
Event handlers:
An event executes a series of actions after a certain event has been triggered.

23
Q

What is a FlowPane?

A

A FlowPane is a layout pane that displays various elements in different vertical and horizontal cells.

24
Q

What does heritance do? (example: FahrenheitPane extends GridPane)

A

This means that the FahrenheitPane class inherits all the methods from the GridPane class. In practice, this means that inside the body of the FahrenheitPane class, all the methods of GridPane could be called as they were its own.