Please note: This page is imported from my wiki, which hasn't been updated in over 10 years. Some of the formatting was lost during the import. I'll try to get around to fixing it someday.
SCJP
Structure
- Order of things in a file (comments disregarded): package decaration //(optional)//
- There can only be one public class in a file.
Syntax
-
Reserved words to note: strictfp, assert, transient, const, native, default, volitile, instanceof.
Access and modifiers
-
Access modifiers:
- public: accessible to all in the Java Universe (JU)
- protected: accessible to other classes in the package, and subclasses in other packages
- private: only viewable by the class itself.
-
With no access modifier, the class has default behaviour - it is visible to all in the same package.
-
Non-access modifiers: strictfp, final, abstract.
Classes
- If a class contains any abstract methods it must be delcared abstract.
- abstract method declarations, including (implicit) abstract interface method declarations should end with a semicolon (;) and not curly braces.
Interfaces
- An interface is a contract for behaviour with NO implementation code.
- In an interface, the compiler treats method signatures as if they are prefixed by the modifiers public abstract. Both/either public and abstract keywords could be included but are unnecessary.
- interfaces are allowed to include constants which may not be overwritten by classes that implement the interface. These constants must be public static final. However, they do not need to be declared with any of these modifiers as these are implicit.
- instanceof is an operator, instanceOf() is a function.
Constructors