Comments
// Everything to the end of the line is ignored.
/* Everything (possibly many lines)
is ignored until a */
/** Used for automatic HTML documentation generation
by the javadoc program. */
Identifier Names
- Start identifiers with an alphabetic character (a-z or A-Z),
and continue with alphabetic, numeric (0-9), or '_' (underscore) characters.
Do not use $.
- Second words in a name should start with an uppercase letter.
- Do not use keywords (see below).
- Class and interface names should start with an uppercase letter
(Graphics, ActionListener, JButton, ...)
- Variable and method names should start with a lowercase letter
(repaint(), x, ...).
- Constants should be all uppercase with underscores between words
(BoxLayout.X_AXIS, Math.PI, ...).
Keywords
| Types |
boolean byte char double float int short true false
|
| Flow |
if else while for do continue
switch case break default
assert try catch
finally throw return synchronized
|
| OOP |
class extends implements instanceof interface new null super this enum
|
| Declarations |
final import native package private protected public static throws
transient volatile void
|
| Other |
strictfp goto const
|
Variables - Local, Instance, Class
Variables may be local, instance (field), or static (class) variables.
Formal parameters are local variables
that are assigned values when the method is called.
| local |
instance |
static / class |
| Where declared |
In a method. |
In class, but not in a method. |
In class using static keyword. |
| Initial value |
Must assign a value before using. Compiler error if you don't. |
Zero for numbers,
null for objects, false for boolean.
Or initialized in constructor. |
Zero/null/false or initialized in static initializer. |
| Visibility |
Only in the same method. No visibility may be declared. |
private: Only methods in this class.
Default: All methods in same package.
public: Anyone can see it.
protected: This class and all subclasses can see it.
|
Same as instance. |
| Created |
When method is entered. |
When an instance of the class (object) is
created with new. |
When program is loaded. |
| Destroyed |
When the method returns. |
When there are no more references to the object. |
When program terminates. |
|