QUESTIONS WITH VERIFIED ANSWERS
\.Field - ANSWERS-a member variable or data stored by an object
\.method - ANSWERS-a member function of the class that may operate on fields
\.References - ANSWERS-All objects are accessed by references
\.Type promotion - ANSWERS-Converting from a smaller to larger, can do implicitly
double weight = 200;
\.Type demotion - ANSWERS-Converting from larger type to a smaller one
Must cast
int height = (int) 10.99
,\.Automatic garbage collection - ANSWERS-Objects with no references to them
are automatically deleted
\.static method - ANSWERS-can be called on the class with no object. Also called
class methods
\.static field - ANSWERS-Shared by all instances of the class
\.Pass by value - ANSWERS-Passing a primitive type passes its value
Passing an object passes (by value) a reference to the object
When passed an object, state can be modified
What object it points to cannot be changed
\.Arrays - ANSWERS-Fixed size when created
\.Generic - ANSWERS-works with different types of objects
\.Collections - ANSWERS-Only stores objects, no primitives
Use Wrapper classes such as Integer
,\.String - ANSWERS-Compare using .equals()
== compares the reference
Immutable, cannot be changed once created.
\.Scanner - ANSWERS-Keyboard input done via Scanner
Scanner scanner = new Scanner(System.in);
System.in does not need to be closed, don't close a Scanner created from
System.in
\.Files - ANSWERS-File(filepath)
Represents a single file on disk (by path)
Scanner(File)
does reading, use .hasNextInt() .nextInt()
PrintWriter(File)
does writing, use .println()
\.Static factory method - ANSWERS-A static method which creates an object
, Like a constructor, but more flexible. Can give a descriptive name
\.Formatted printing - ANSWERS-Use printf()
System.out.printf(<format string>, arg0, ...);
System.out.printf("%s! Is it %b that you're %d?%n", "Waldo", true, 42);
Waldo! Is it true that you're 42?
\.Wrapper - ANSWERS-A class to hold a primitive value
\.Interface - ANSWERS-A set of methods a class can choose to implement
\.FileFilter - ANSWERS-FileFilter filter = new FileFilter() {
@Override
public boolean accept(File file) {
}
};
\.Anonymous class - ANSWERS-Instance of an unnamed class which is defined on
the fly