The Department of Computer Science & Engineering
cse@buffalo

Java Quick Reference
Stuart C. Shapiro


References
The Java Language Specification: Second Edition
JavaTM 2 SDK, Standard Edition Documentation Version 1.4.0
JavaTM 2 Platform, Standard Edition, v 1.4.0 API Specification
Javadoc 1.4 Tool

Comments
// rest of line
/* multiline comment */
/** documentation comment */

Creating Documentation Files
javadoc -d docfile -author sourcefiles

Classes
public class name
{  [class_variable_declarations]
   public static void main{String[] args) {statements}
   [methods]
}

Methods
{public | private} [static] {type | void} name(arg, ..., arg) {statements}

Class Variable Declarations
{public | private} static type name [= expression];

Types and Literals
nullnull
booleantrue false
char'a'
byte short int long32 2147483648L
float double3.14E+5F 3.14E+5
String"A string"
type[[length]] {1, 2, 3}

Operators
Numerical: + - * / %
String: +
Relational: == != < <= > >= string.equals(string)
Boolean: ! && ||

Conditional Expression
(condition ? then_expression : else_expression)

I/O
System.out.print[ln](string)

Control Structures
[label:]{statements}
break [label];
return expression;
System.exit(0);
if (condition) statement [else statement]
while (condition) statement
do statement while (condition);
for (initialization; termination; update) statement
switch (integer_or_char_expression) {
   case integer_or_char_literal: statements break;
   ...
   case integer_or_char_literal: statements break;
   default: statements}


Stuart C. Shapiro <shapiro@cse.buffalo.edu>