Java Keywords
abstractbooleanbreakbytecasecatch
charclassconstcontinuedefaultdo
doubleelseextendsfinalfinallyfloat
forgotoifimplementsimportinstanceof
intinterfacelongnativenewpackage
privateprotectedpublicreturnshortstatic
strictfpsuperswitchsynchronizedthisthrow
throwstransienttryvoidvolatilewhile
assertenum

Legal Identifiers
Must start with a letter, $, or underscore.
After the first character, can contain any letter, currency character, underscore, or number.
No limit to the number of characters it can contain.
Can't use a Java keyword as an identifier.
Case sensitive - foo and FOO are two different identifiers.

Naming Conventions
If a variable consists of only one word, spell it in all lowercase letters.
If a variable consists of more than one word, capitalize the first letter of each subsequent word.
If a variable stores a constant value, use all capital letters, and separate words with underscore. Example: static final int NUM_GEARS = 6
For class names, the first letter should be capitalized, and if it consists of several words, capitalize the first letter of each subsequent word.
For interfaces, the names should be adjectives like Runnable, or Serializable.
For methods, the first letter should be lowercase, and then normal camelCase rules should apply. In addition, the names should contain a verb, such as "getBalance", "doCalculation", "setBalance".
For enums, all letters should be uppercase.
JavaBean Naming Conventions
For most properties, the getter method's prefix must be "get". For boolean properties, the prefix may be "get" or "is".
The setter method's prefix must be "set".
For both getter and setter methods, use camelCase for the method name.
Setter methods must be public, take an argument of the desired type, and return void.
Getter methods must be public, take no arguments, and return the desired type.
Listener register methods must use the prefix "add", followed by the listener type - ie, "addActionListener()".
Listener unregister methods must use the prefix "remove", followed by the listener type - ie, "removeActionListener()".
The type of listener to be added or removed must be passed as the argument to the method.
Listener method names must end with the word "Listener."

Source File Rules
There can be at most one public class per source file.
If a public class exists in the source file, the name of the file must be the name of the class, with '.java' as a suffix. Example: A file containing "public class MyClass" must be named "MyClass.java".
If there are no public classes in the source file, you may name it anything that doesn't match a class in the file, with a '.java' suffix.
If the class is in a package, the package statement must be the first line in the source code file.
If there are import statements, they must be after the package statement if one exists, and before everything else.

Class Access Modifiers
default (no modifier)Visible to classes in same package.
publicVisible to classes in all packages.
Class Non-Access Modifiers
finalClass can not be overridden. Cannot use with abstract.
abstractClass can never be instantiated - must be overridden. Cannot use with final.
Abstract classes can have non-abstract methods.
Abstract methods in class must be prefixed with "abstract", and end in a semicolon instead of curly braces.
strictfpMethods in class uses strict floating point calcuations.
staticFor nested classes only, creates a class that will exist independently of any instances created for the class.

Class Member Access Modifiers
Including methods, variables, and inner classes.
VisibilityPublicProtectedDefaultPrivate
From the same classYYYY
From any class in the same packageYYY
From a subclass in the same packageYYY
From a subclass outside the same packageYY (through inheritance)
From any non-subclass class outside the packageY

Non-Access Modifiers
for Class Methods
final Method cannot be overridden. Cannot use with abstract.
abstract Method must be overridden. Cannot use with final, private, or static.
Abstract methods in class must be prefixed with "abstract", and end in a semicolon instead of curly braces.
If even one method is marked abstract, the class MUST be marked as abstract, as well.
strictfp Method uses strict floating point calculations.
static Marks a method that can be used without an instance of this class.
synchronized Method can be accessed by only one thread at a time.
native Method is implemented in platform-dependent code. The body must be a semicolon, like an abstract method, indicating that the implementation is omitted.
for Instance Variables
final Once assigned, the variable becomes a constant, and can never be reassigned.
Can also be used on arguments in a function signature. Example: public void doIt(final int x).
static Marks a variable that can be used without an instance of this class.
transient Skip this variable when serializing the object.
volatile The thread accessing the variable must always reconcile its own private copy of the variable with the master copy in memory.
for Local Variables
final Once assigned, the variable becomes a constant, and can never be reassigned.
Can also be used on arguments in a function signature. Example: public void doIt(final int x).
No other access modifier can be applied to local variables!

Interfaces
Similar to a class, but use the word "Interface" instead of "Class".
Interfaces are abstract, whether it is marked that way or not.
May extend other interfaces, but not classes.
Interface Methods
Must contain only public abstract methods (no actual methods).
All methods in interface are public and abstract, whether they are marked that way or not.
Interface methods can't be static, final, strictfp, or native.
Interface methods must end in a semicolon, not curly braces.
This implies curly braces anywhere in an interface is an error - watch out for them!
Interface Variables
All variables are public, static, and final, whether they are marked that way or not.
To make this easier to remember, type interface variables in all caps, with underscores separating the words. This will jog your memory that they actually ARE static final constants (and public to boot!), whether you mark them that way or not.

Enum Rules
Enums constants should be in all caps.
Enums can be declared as a top level class, or an inner class, but not within a method.
It is optional to put a semicolon at the end of the enum declaration.
You can compare enums with == or .equals, but < and > don't work.
You must specify all enum values at compile time - it is not possible to add to the enum values at run time.
They can be simple, such as

    enum CoffeeSize { TALL, GRANDE, VENTI} // <-- no semicolon

or they can look like almost like a full blown class, but with the word "enum" instead of "class", such as

enum CoffeeSize {
    TALL(0), GRANDE(1), VENTI(2); // declare the enum constants, and call the constructor for each value
    private int size;
    CoffeeSize(int size) { this.size = size; } // constructor
    public int getSize() { return size; }
}; // <-- optional semicolon

Range of Numeric Primitives
TypeBitsBytesMin RangeMax RangeValid as array subscript
byte81-128127Y
short162-32,76832,767Y
char162065,535Y
int324-2,147,483,6482,147,483,647 Y
long648-9,223,372,036,854,775,8089,223,372,036,854,775,807N
float324 N
double648 N