Chapter 10: Object Oriented Thinking Flashcards
What is a classes contract?
The collection of public constructors, methods, and fields + the description of how these members are supposed to behave.
What’s the difference between traditional oriented programming paradigm and object oriented programming paradigm?
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 should you separate the public parameter from the private data fields?
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;
What is object-oriented programming good for?
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.
What is the association relationship between classes?
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.
What is the aggregation relationship between classes?
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.
What is wrapping?
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.
All wrapper classes are immutable, what does this mean?
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.
What is boxing and unboxing?
Boxing is converting a primitive value to a wrapper.
Unboxing is converting a wrapper to a primitive value.
How should you efficiently create a string?
use the string literal when creating a string.
String n = stringLiteral;
is better than
String n = new String(stringLiteral);
What is regular expression?
A way to check and compare strings to see if a user inputted string matches the requirements (all lowercase, a number, etc.)
What is regular expression?
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 can you convert a string into an array?
By using the toCharArray method.
char[] chars = “Java”.toCharArray;
chars[0] = J chars[1] = a chars[2] = v chars[3] = a
What is the BigInteger class used for?
The BigInteger class is useful for computing and processing integers of any size.
What is the BigDecimal class used for?
The BigDecimal class can be used to compute and process floating-point numbers with any arbitrary precision.