Chapter 1 Flashcards
Constructors
There are two key points to note about the constructor: the name of the constructor matches the name of the class, and there’s no return type.
The rules for what a Java code file contains
■ Each file can contain only one class.
■ The filename must match the class name, including case, and have a .java extension.
A value is assigned to a reference in one of two ways:
■ A reference can be assigned to another object of the same type.
■ A reference can be assigned to a new object using the new keyword.
important differences you should know between primitives and reference types.
First, reference types can be assigned null, which means they do not currently refer to an object. Primitive types will give you a compiler error if you attempt to assign them null.
Next, reference types can be used to call methods when they do not point to null. Primitives do not have methods declared on them. Primitives do not have methods.
Finally, notice that all the primitive types have lowercase type names. All classes that come with Java begin with uppercase.
Three rules to remember for legal identifiers:
- The name must begin with a letter or the symbol $ or _.
- Subsequent characters may also be numbers.
- You cannot use the same name as a Java reserved word
Rule for instance variables
they are available as soon as they are defined and last for the entire lifetime of the object itself.
The rule for class (static) variables
they go into scope when declared like the other variables types. However, they stay in scope for the entire life of the program.
The rules on scope: (Local, instance, and class variables)
Local variables—in scope from declaration to end of block
Instance variables—in scope from declaration until object garbage collected
Class variables—in scope from declaration until program ends
PIC
Package declaration- Required? - No
Import statements - Required? - No
Class declaration - Required? - YES
_______ ________ can be defined in the same file, but only ___ of them is allowed to be public
- multiple classes
- one
A file is also allowed to have _______ class be public. As long as there isn’t more than ___ public class in a file, it is okay.
- neither
- one
System.gc()
Is not guaranteed to run, and you should be able to recognize when objects become eligible for garbage collection.
An object is no longer reachable when one of two situations occurs
- The object no longer has any references pointing to it.
- All references to the object have gone out of scope.
finalize()
Could run zero or one time.
Benefits of Java
- Object Oriented
- Encapsulation
- Platform Independent
- Robust
- Simple
- Secure