Term
Java identifiers can start with... |
|
Definition
Letter, $ or Connecting character |
|
|
Term
|
Definition
Java classes that have properties |
|
|
Term
|
Definition
A class that can't be subclassed. |
|
|
Term
|
Definition
end in a semicolon rather than curely braces |
|
|
Term
Just remember that all interface methods are public and abstract regardless of what you see in the interface definition. |
|
Definition
|
|
Term
You need to remember one key rule for interface constants. They must always be public static final |
|
Definition
|
|
Term
For the exam, you need to recognize that a subclass can't see, use, or even think about the private members of its superclass. You can, however, declare a matching method in the subclass. But regardless of how it looks, it is not an overriding method! It is simply a method that happens to have the same name as a private method (which you're not supposed to know about) in the superclass. The rules of overriding do not apply, so you can make this newly-declared-but-just-happens-to-match method declare new exceptions, or change the return type, or anything else you want to do with it. |
|
Definition
|
|
Term
|
Definition
may be accessed only if the class accessing the member belongs to the same package, |
|
|
Term
|
Definition
can be accessed (through inheritance) by a subclass even if the subclass is in a different package. |
|
|
Term
So, when you think of default access, think package restriction. No exceptions. But when you think protected, think package + kids. |
|
Definition
|
|
Term
|
Definition
|
|
Term
So if the subclass-outside-the-package gets a reference to the superclass (by, for example, creating an instance of the superclass somewhere in the subclass' code), the subclass cannot use the dot operator on the superclass reference to access the protected member. |
|
Definition
|
|
Term
Can access modifiers be applied to local variables? |
|
Definition
|
|
Term
|
Definition
|
|
Term
The first concrete subclass of an abstract class must implement all abstract methods of the superclass. |
|
Definition
|
|
Term
A method can never, ever, ever be marked as both abstract and final, or both abstract and private. |
|
Definition
|
|
Term
Finally, you need to know that the abstract modifier can never be combined with the static modifier. |
|
Definition
|
|
Term
|
Definition
indicates that a method can be accessed by only one thread at a time. |
|
|
Term
|
Definition
The things you specify between the parentheses when you're invoking a method: doStuff("a", 2); // invoking doStuff, so a & 2 are arguments |
|
|
Term
|
Definition
The things in the method's signature that indicate what the method must receive when it's invoked:
void doStuff(String s, int a) { } // we're expecting two // parameters: String and int |
|
|
Term
Every time you make a new object, at least one constructor is invoked. Every class has a constructor, although if you don't create one explicitly, the compiler will build one for you. |
|
Definition
|
|
Term
a constructor can't ever, ever, ever, have a return type…ever! |
|
Definition
|
|
Term
constructors must have the same name as the class in which they are declared. |
|
Definition
|
|
Term
Constructors can't be marked static (they are after all associated with object instantiation), they can't be marked final or abstract (because they can't be overridden). |
|
Definition
|
|
Term
|
Definition
a single 16-bit Unicode character. |
|
|
Term
—unlike instance variables—local variables don't get default values. |
|
Definition
|
|
Term
If the variable is declared as an interface type, it can reference any object of any class that implements the interface. |
|
Definition
|
|
Term
Java supports only single inheritance |
|
Definition
this means a class can have only one immediate superclass |
|
|
Term
Even though the actual object at runtime is a Horse and not an Animal, the choice of which overloaded method to call (in other words, the signature of the method) is NOT dynamically decided at runtime. |
|
Definition
|
|
Term
To summarize, which overridden version of the method to call (in other words, from which class in the inheritance tree) is decided at runtime based on object type, but which overloaded version of the method to call is based on the reference type of the argument passed at compile time. |
|
Definition
|
|
Term
So don't be fooled by code that shows a concrete class that declares that it implements an interface, but doesn't implement the methods of the interface. Before you can tell whether the code is legal, you must know what the superclasses of this implementing class have declared. |
|
Definition
|
|
Term
Remember that overloading is not much more than name reuse. |
|
Definition
|
|
Term
Remember that overloading is not much more than name reuse. |
|
Definition
|
|
Term
To overload a method you must change the argument list. |
|
Definition
|
|
Term
To overload a method you cannt change only the return type |
|
Definition
|
|
Term
to override, you must keep the argument list you can use a subtype of the return value |
|
Definition
|
|
Term
For the exam, be sure you know that overloaded methods can change the return type, but overriding methods can do so only within the bounds of covariant returns. Just that knowledge alone will help you through a wide range of exam questions. |
|
Definition
|
|
Term
An array is a perfectly legal return type? |
|
Definition
|
|
Term
In a method with a primitive return type, you can return any value or variable that can be implicitly converted to the declared return type? |
|
Definition
|
|
Term
In a method with a primitive return type, you can return any value or variable that can be explicitly cast to the declared return type? |
|
Definition
yes for example public int foo () { float f = 32.5f; return (int) f; } |
|
|
Term
In a method with an object reference return type, you can return any object type that can be implicitly cast to the declared return type? |
|
Definition
yes for egample public Animal getAnimal() { return new Horse(); // Assume Horse extends Animal }
public interface Chewable { } public class Gum implements Chewable { } public class TestChewable { // Method with an interface return type public Chewable getChewable() { return new Gum(); // Return interface implementer } } |
|
|
Term
Every class, including abstract classes, MUST have a constructor. |
|
Definition
|
|
Term
Two key points to remember about constructors are that |
|
Definition
they have no return type and their names must exactly match the class name. |
|
|
Term
polymorphism doesn’t apply to static method |
|
Definition
|
|
Term
Polymorphism is only for instance methods not for instance variables |
|
Definition
|
|
Term
For each class you write, you must decide if it makes sense to consider two different instances equal. |
|
Definition
|
|
Term
The equals() method in class Object uses only the == operator for comparisons, so unless you override equals(), two objects are considered equal only if the two references refer to the same object. |
|
Definition
|
|
Term
If two objects are equal, their hashcodes must be equal as well. |
|
Definition
|
|
Term
Instance variables and objects live on |
|
Definition
|
|
Term
Local variables"function parameters + local varables" live on |
|
Definition
|
|
Term
characters are just 16-bit unsigned integers under the hood. |
|
Definition
|
|
Term
For the exam, you need to know only that strictfp is a keyword and can be used to modify a class or a method, but never a variable. Marking a class as strictfp means that any method code in the class will conform to the IEEE 754 standard rules for floating points. |
|
Definition
|
|
Term
Look for questions with a method declaration that ends with a semicolon, rather than curly braces. If the method is in a class—as opposed to an interface—then both the method and the class must be marked abstract. |
|
Definition
|
|
Term
Interfaces can be implemented by any class, from any inheritance tree. |
|
Definition
|
|
Term
But while an abstract class can define both abstract and non-abstract methods, an interface can have only abstract methods. |
|
Definition
|
|
Term
and variables defined in the interface are declared. These rules are strict: ■ All interface methods are implicitly public and abstract. |
|
Definition
|
|
Term
All variables defined in an interface must be public, static, and final |
|
Definition
|
|
Term
■ All interface methods are implicitly public and abstract. In other words, you do not need to actually type the public or abstract modifiers in the method declaration, but the method is still always public and abstract. ■ All variables defined in an interface must be public, static, and final— in other words, interfaces can declare only constants, not instance variables. ■ Interface methods must not be static. ■ Because interface methods are abstract, they cannot be marked final, strictfp, or native. (More on these modifiers later.) ■ An interface can extend one or more other interfaces. ■ An interface cannot extend anything but another interface. ■ An interface cannot implement another interface or class. ■ An interface must be declared with the keyword interface. ■ Interface types can be used polymorphically (see Chapter 2 for more details). |
|
Definition
|
|
Term
can't do the below combinations abstract static abstract final abstract private |
|
Definition
|
|