Chapter 8 from book - A Second Look at Classes and Objects
"has a" p. 521
The relationship that exists when an instance of one class is a member of another class. Ex. The relationships that exists among the Course, Instructor, and the Textbook classes can be described as: > The course has an instructor. > The course has a textbook. The "has a" relationship is sometimes called a "whole-part relationship" because one object is part of a greater whole. p. 521
What can "security holes" do? p. 525
They can allow code outside the class to modify private data inside the class. p. 525
The "compareTo" method. p. 535
This is a type of method that is designed to compare enum constants. p. 535
One common use of the "this" keyword p. 531
To overcome the "shadowing" of a field name by a parameter name. Remember from Chapter 6 that if a method's parameter has the same name as a field in the same class, then the parameter name shadows the field name. p. 531
True or False: Any method called from a static method must also be static. p. 501
True If the method uses any of the class's fields, they must be static as well. p. 501
True or False: A method can return a reference to an object. p. 505
True Methods can be written to return an int, double, float, or other primitive data types. Methods can also return a reference to an object.
What does the toString method return? p. 507
Typically, the method returns a string that represents the "state" of an object. Ex. BankAccount account = new BankAccount (1500.0); System.out.println("The balance is $" + account.getBalance()); p 507
UML diagram illustration p. 508
UML are a way of visualizing your program. They contain the following (see picture for reference): Class Fields Constructors Methods p. 508
UML p. 508
UML can be described as a general purpose visual modeling language to visualize, specify, construct and document software systems. Mentioned on p. 508- Google Search led to: http://www.tutorialspoint.com/uml/uml_overview.htm
"fully qualified name" p. 534
Under most circumstances, what type of name must you use when you assign names to enum constants? p. 534
"deep copy" p. 525
When you make a copy of the aggregate object, it is important that you also make copies of the objects it references - this is known as a "deep copy". p. 525
"aggregation" p. 517
Aggregation occurs when an instance of a class is a field in another class. p. 517
What does an "enumerated data type" consist of? p. 533
An "enumerated data" type consists of a set of predefined values. You can use the data type to create variables that can hold only the values that belong to the enumerated data type. TIP: It is not required to write enum constants in all upper case but because they represent constant values, the standard convention is to write them in all uppercase letters. p. 533
object's "state" p 507
An object's "state" is simply the data that is stored in the object's fields at any given moment. p 507
How do you show aggregation in a UML diagram? p. 525
By connecting two classes with a line that has an open diamond at one end. The diamond is closer to the class that has the aggregate (the whole). p. 525
How is a static field created? p. 497
By placing the key word "static" after the access specifier and before the field's data type.
How do you create your own data types in Java? p.533
By using "enumerated data types".
What set of fields does each instance of a class have?
Each instance of a class has its own set of fields.
What set of fields does each instance of a class have? p. 495
Each instance of a class has its own set of fields.
"this" key word p.530
The name of a reference variable that an object can use to refer to itself. It is available to all non-static methods. p. 530
What happens when you use the == operator with reference variables? p. 512
The operator compares the memory addresses that variables contain, not the contents of the objects referenced by the variables.
Static Class Members p. 495
A static class member belongs to the class, not the objects instantiated from the class.
"new" p. 510
The keyword used to create a new object. Ex. BankAccount KathAccount = new BankAccount(); page 507 or Stock xyzCompany = new Stock("XYZ", 9.62); p. 507
What does java store in all uninitialized static member variables? p. 497
0
Two specific practices that can help prevent security holes in your classes... *There are more than two but the book covers two. p. 525
1. Perform deep copies when creating field objects 2. Return copies of field objects, not the originals p. 525/526
"data type" p. 533
A "data type" defines the values that are legal for any variable of that data type. p. 533
"ordinal value" p. 535
A constant's "ordinal value" is its position in the enum declaration, with the first constant being at position "0". Ex: 0 1 2 3 enum Day{SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY} 4 5 6 7 *The numbers represent the ordinal value of the days of the week. p. 535
"copy constructors" p. 516
A copy constructor is simply a constructor that accepts an object of the same class as an argument. p. 516 It is another way of making a copy of an object. p. 516
Static Members p. 496
A field or method that does not belong to any instance of a class. Such members are known as static fields and static methods.
The "finalize method" p. 544
If a class has a method named "finalize", it is called automatically just before an instance of the class is destroyed by the garbage collector. If you wish to execute code just before an object is destroyed, you can create a finalize method in the class and place the code there. p. 544
"shallow copy" p. 525
If you make a copy of an aggregate object, but only make a reference copy of the objects it references, then you have performed a "shallow copy". p. 525
"immutable objects" p. 526
Immutable objects do not provide a way to change their contents. p. 526 String objects are immutable. p. 526 NOTE: It is permissible to return a reference to a String object, even if the String object is a private field because String objects are immutable. p. 527 Wrapper classes are immutable which means that once you create an object, you cannot change the object's value. p. 559
"object aggregation" p. 521
Making an instance of one class a field in another class is called "object aggregation". Footnote: The word aggregate means "a whole which is made of constituent parts." p. 521
toString Method p. 507
Most classes can benefit from having this method. It is implicitly called under certain circumstances.
When a class contains a static method, is it necessary for an instance of the class to be created in order to execute the method? p. 499
No
How many copies of the field in memory , regardless of the number of instances of the class that might exist, will there be when a field is declared with the key word "static"? p. 496
One
"CRC" cards p. 547
Stands for class, responsibilities, and collaborations. This is one popular method of discovering a class's responsibilities and collaborations (by creating CRC cards). p. 547
Example of an "immutable object" p. 526
String objects are immutable. p. 526
"whole-part relationship" p. 521
The "has a" relationship is sometimes called a "whole-part relationship" because one object is part of a greater whole. p. 521
"ordinal method" p. 535
The "ordinal method" returns an integer value representing the constant's ordinal value. p. 535
"garbage collection" p. 542
The Java Virtual Machine periodically runs a process which removes unreferenced objects from memory called "garbage collection". p. 542
Access Specifiers Google Search http://www.wideskills.com/java-tutorial/introduction-to-java-access-modifiers p. 497
The access to classes, constructors, methods and fields are regulated using access modifiers i.e. a class can control what information or data can be accessible by other classes. To take advantage of encapsulation, you should minimize access whenever possible. Examples of "access specifiers": private protected default public Google Search http://www.wideskills.com/java-tutorial/introduction-to-java-access-modifiers
How do you compare the contents of objects? p. 511
The class must have a method such as equals for comparing the contents of objects. p.511 You cannot determine whether two objects contain the same data by comparing them with the == operator. The String class has a method named "equals" (which determines whether two strings are equal). However, you must write an equals method(or one that works like it) for a class in order to determine whether two objects of the class contain the same values. p. 511 Ex. if (symbol.equals(object2.symbol) && sharePrice == object2.sharePrice) status = true; //objects are equal else status = false; //objects are not equal p. 513 NOTE: Every class automatically has an equals method, which works the same as the == operator. This method is called when necessary if you have not provided your own equals method. you will learn more about this in Chapter 10. p. 514
A rule in Java is "You cannot call a constructor explicitly, as you do other methods." There is one exception to this rule....What is this exception? p. 532
You can use the "this" key word to call one constructor from another constructor in the same class. p. 532
How do you copy an object? p. 514
You must create a new object and then set the new object's fields to the same values as the fields of the object that is being copied. p. 514
How do you pass an object as a method argument?
You pass an object reference.
What type of copy should you make when creating field objects? p. 526
deep copies