Show Menu
Cheatography

Beginner Java Cheat Sheet by

A quick reference sheet to java's beginner instructions

Datatypes

int
2, 5, -3, -10, 22
float
2.5, 3.2, 10.15, -2010, 0, 0.01
String
"­Nom­", "­Cli­ent­", "­Mod­DeP­ass­e", "­-5.2­"
boolean
true, false

Declar­ations

DATATYPE VARIABLE;
DATATYPE VARIABLE = VALEUR;
DATATYPE VARIABLE, VARIABLE2;
DATATYPE VARIABLE = VALEUR, VARIABLE2 = VALEUR2;

Condit­ional

if
if(CON­DITION) {}
if else
if(CON­DITION) {} else {}
if else if
if(CON­DITION) {} else if(CON­DIT­ION2) {}
 

Printing

System.ou­t.p­rin­tln­("Me­ssa­ge");
System.ou­t.p­rin­tln­(Va­ria­ble);

Scanning

import java.u­til.Sc­anner;
Scanner NOM = new Scanne­r(S­yst­em.in);
int variable = scanne­r.n­ext­Int();
float variable = scanne­r.n­ext­Flo­at();
String variable = scanne­r.n­ext­Line();

Boucle

while
while(­CON­DITION) { }
for
for(int i = 0; i < max; i++) { }
do while
do {} while(­CON­DIT­ION);
 

Arrays (Tableau)

TYPE nom[];
nom = new TYPE[T­AILLE];
TYPE nom[] = new TYPE[T­AILLE];
TYPE nom = { valeur1, valeur2, valeur3 };

Array Loop

int tableau[] = new int[5];
for(int i = 0; i < 5; i++){
    tableau[i] = valeur; 
    // possible:
    tableau[i] = scanner.nextInt();
}
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Selenium WebDriver Cheat Sheet Cheat Sheet