Show Menu
Cheatography

Java Basic Cheat Sheet (DRAFT) by

Java Basic

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Java Statements

If statement
if ( expression ) {
    statements
} else if ( expression) {
    statements
} else {
    statements
}

While Loop
while ( expression ) {
    statements
}

Do-While Loop
do {
    statements
} while ( expression );

For Loop
for ( int i = 0; i < max; ++i) {
    statements
}

For Each Loop
for ( *Type item : collection ) {
    item statements 
} 

Switch Statement
switch ( expression ) {
case value:
    statements
    break;

default:
    statements
}

Exception Handling
try {
    statements;
} catch (ExceptionType e1) {
    statements;
} catch (Exception e2) {
    catch-all statements;
} finally {
    statements;
}
 

Class Template

public class Classname {
    String varName1 = "";
    int varName2 = "";
    char varName3 = '';
    public static String CONSTANT1="";
    
    // Constructor
    public Classname (String arg0){
    statements
    }
    // Method
    public void methodName1(){
        statements;
    }

}
public / private / protected [ abstract ]
extends Class implement Interf­ace­/Class

Attributes Constr­uctor Getter­s/S­etters Methods

Method Template

public String methodName(String arg0){
    statements
  return value;
}
public / protected / private [abstract] void/S­tri­ng/­int...