Chapter 3 Flashcards

1
Q

How do you create an object? What is the name of its process?

A

An object is created via the “new” operator. The The “new” operator calls the constructor, which is a special method that sets up the object.

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

What does it mean to declare an object reference variable?

A

When writing for example: String pizza; you’re not creating an object of type String called pizza, but you’re creating a reference to the object, so not the object per se will be saved, but its connection to it (its address).

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

What’s the difference between a primitive variable and an object variable?

A

A primitive variable contains the value itself (num1 = 38;) while an object variable contains the address of the object (name1 = new String(“Steve Jobs”).

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

What are aliases?

A

Aliases are two or more object references that refer to the same object.

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

What’s the difference between:
String chocolate = new String(“…”)
and
chocolate = “…”;

A

The second one is more brief, but they’re equivalent.

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

Can a string object be modified?

A

No. But modified versions of the original can be created with several methods of the String class.

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

What is the index in a string?

A

In a string, each written character has an identificative number starting from 0. The letter “o” of “hello” would be at index 4.

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

What is a class library?

A

A class library is a collection of classes that we can use when developing programs.

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

Without importing a specific class from a package, how could you use in a program? Take the Scanner class for example.

A

Instead of
import java.util.Scanner,
we could call the class by writing its full name
java.util.Scanner.

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

What is the function of NumberFormat and DecimalFormat? How are they implemented?

A

NumberFormat and DecimalFormat are used to format output data by presenting it in a particular way.

Example:
NumberFormat fmt1 = NumberFormat.getCurrencyInstance();
or
NumberFormat fmt2 = NumberFormat.getPercentInstance();
and then writing
(“Subtotal: “ + fmt1.format(subtotal));

DecimalFormat fmt = new DecimalFormat (“0.###”)
and
(“Subtotal + fmt1.format(subtotal));

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

What is an enumerated type declaration?

A

An enumerated type declaration lists all possible values for a variable of that type.

Example:
enum Season(winter, spring, summer, fall)

the values inside the brackets are the only that can be assigned to the variable Season.

The variable Season will act therefore as a class. Example:

Season time; declaration of variable time as type Season.

time = Season.fall

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

What is the ordinal value of an emurated type?

A

Each enumerated type is stored as an integer, called its ordinal value.

The first value in an enumerated type is 0, the second is one, and so on.

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

What are Wrapper Classes and where do we use them?

A

Wrapper classes are classes that create objects containing primitive values.

Integer age = new Integer(40); is an object type Integer holding the value 40.

Wrapper classes are used in situations where a primitive value will not suffice.

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

What is autoboxing?

A

Autoboxing is the automatic conversion of a primitive value to a corresponding wrapper object.

Example:
Integer obj;
int num = 42;
obj = num;

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

What is the Type Comparison Operator?

A

The instanceof operator compares an object to a specified type.
You can use it to test if an object is an instance of a class, of a subclass, ecc.

Example:
Integer obj1 = new Integer(3);
System.out.println("obj1 instanceof Integer: " + (obj1 instanceof Integer));

Result: obj1 instanceof Integer: true

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

How do you set up a scene?

A
Example:
Scene scene = new Scene(root, 300, 120, Color.RED);
with root being the group included and 300 and 120 being the dimensions of the window.
17
Q

How does the coordinate system in JavaFX work?

A

The first set is the width, from left to right.

The second set is the height, from up to down.

18
Q

Complete:

Line(___, ___, ___, ___)

A

Line(startX, startY, endX, endY)

19
Q

Complete:

Rectangle(___, ___, ___, ___)

A

Rectangle(x, y, width, height)

with x and y its starting points

20
Q

Complete:

Circle(___, ___, ___)

A

Circle(centerX, centerY, radius)

21
Q

Complete:

Ellipse(___, ___, ___, ___)

A

Ellipse(centerX, centerY, radiusX, radiusY)

22
Q

How do you color a circle? (named c)

A

c.setFill(Color.BLUE);

23
Q

What does the Color class do?

A
The Color class represents objects with specific colors in it, The initialization of such object is:
Color purple = Color.rgb(183, 44, 150);