Java Cheat Sheet
Simple program
Simple program
Declarations
Variable declaration
Constant declaration
Constant declaration
Object declaration
Formal parameter declarations
Instancing
Assignment statement
Actual parameters
Loops
Simple for-statement
Method
Method declaration
Method calls
General
Modifiers
Types
Type cast
Output statements
Increment and decrement assignments
Packages
Accessing a package
Simple program |
class classname {
public static void main (String [] argname) {
declarations and statements
}
}
|
[TOP]
Output statements |
System.out.println (items);
System.out.println ();
System.out.print (items);
|
[TOP]
Variable declaration |
type name;
type name1, name2, name3;
type name = value;
|
[TOP]
Constant declaration |
static final type name = value;
|
[TOP]
Assignment statement |
variable = experssion;
|
[TOP]
Constant declaration |
static final type name = value;
|
[TOP]
Accessing a package |
import java.package.*;
|
[TOP]
Object declaration |
modifier classname objectname = new classname (parameters);
modifier classname objectname = classname.getInstance (parameters);
|
[TOP]
Formal parameter declarations |
(type field, type field ...)
|
[TOP]
Actual parameters |
(expression, expression, ...)
|
[TOP]
Simple for-statement |
for (start; chekc; update) {
body
}
|
[TOP]
Increment and decrement assignments |
variable ++; // add one to variable
variable --; // subtract one from variable
variable += exp; // add exp to variable
variable -= exp; // subtract exp from variable
|
[TOP]
Type cast |
(type) expression
|
[TOP]
Method declaration |
modifiers kind name (parameters) {
fields and statements
return expression; // typed methods only
}
modifiers
kind
|
[TOP]
Method calls |
method (parameters); // declared static in this class
object.method (parameters); // declared in another object
classname.methode (parameters); // declared static in another class
|
[TOP]
Modifiers |
public =
private =
static = indicates that storage for the field is to be created once
only for the class, and not each time a new object is created.
final = indicates that the contents of the fiel cannot be changed
during the program; in other words, it is constant.
|
[TOP]
Types |
Type Representation Init.Value Storage Max.Value
byte signed integer 0 8 bits 127
short signed integer 0 16 bits 32767
int signed integer 0 32 bits 2147483647
long signed integer 0 64 bits over 10E18
float floating-point 0.0 32 bits over 10E38
double floating-point 0.0 64 bits over 10E308
|
[TOP]
Last changed by DJPO, 20-Sep-98.