Chapter 10: Object Oriented Thinking Flashcards

1
Q

What is a classes contract?

A

The collection of public constructors, methods, and fields + the description of how these members are supposed to behave.

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

What’s the difference between traditional oriented programming paradigm and object oriented programming paradigm?

A

Traditional is action-driven, and data are separated from actions.
Object-oriented focuses on objects, and actions are defined along with the data in objects.

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

How should you separate the public parameter from the private data fields?

A

When you receive the public parameters, set the private data fields equal to the parameter using a this.

 public BMI(String name, int age, double weight, double height) {
10      this.name = name;
11      this.age = age;
12      this.weight = weight;
13      this.height = height;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is object-oriented programming good for?

A

In the traditional way of programming you have to pass data to methods regularly. With object-oriented programming any data and operation that can be related to an object is put inside the object.

JAVA PROGRAMMING INVOLVES THINKING IN TERMS OF OBJETCS AND CAN BE THOUGHT OF AS A COLLECTION OF COOPERATING OBJECTS.

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

What is the association relationship between classes?

A

Association is a general binary relationship that describes an activity between two classes. For example, there is an association relationship between a “student” and “course” class AND a association relationship between a “course” and “teacher” class.

The multiplicity is a possible specification of the ratio of classes in the relationship. For examples, there must be between 5 and 60 students in a course. A teacher must only teach between 0 and 3 courses a semester.

Association can be implemented using methods and data fields.

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

What is the aggregation relationship between classes?

A

A specific kind of association relationship that indicates ownership between two objects.

If one objects existence is dependent on another object existing, that is called composition. For example a name and a person have an aggregation relationship. The name can’t exist if the person doesn’t exist. Therefore it is called a composition relationship.

Data fields in aggregating relationships are put in the aggregating class. The name and address of a student will be stored in the student class.

Aggregation will be called composition in the book.

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

What is wrapping?

A

Java doesn’t use primitive data types as objects. But many methods in Java require arguments to be objects. So wrapping is a way to “wrap” a primitive data type into an object.

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

All wrapper classes are immutable, what does this mean?

A

Once a wrapper object is constructed, the internal value is set and can’t be changed. There is also no no-arg constructors for wrappers.

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

What is boxing and unboxing?

A

Boxing is converting a primitive value to a wrapper.

Unboxing is converting a wrapper to a primitive value.

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

How should you efficiently create a string?

A

use the string literal when creating a string.

String n = stringLiteral;

is better than

String n = new String(stringLiteral);

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

What is regular expression?

A

A way to check and compare strings to see if a user inputted string matches the requirements (all lowercase, a number, etc.)

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

What is regular expression?

A

A way to check and compare strings to see if a user inputted string matches the requirements (all lowercase, a number, etc.)
You can accomplish this by matching, splitting, and replacing.

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

How can you convert a string into an array?

A

By using the toCharArray method.

char[] chars = “Java”.toCharArray;

chars[0] = J
chars[1] = a
chars[2] = v
chars[3] = a
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the BigInteger class used for?

A

The BigInteger class is useful for computing and processing integers of any size.

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

What is the BigDecimal class used for?

A

The BigDecimal class can be used to compute and process floating-point numbers with any arbitrary precision.

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