Show Menu
Cheatography

Java Basics and Language Cheat Sheet (DRAFT) by

Stuff for Java

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

Variable Declar­ation and Initia­liz­ation

--------------------------------
primitive datatypes only
--------------------------------
<datatype> <name>;
<datatype> <name> = <value>;

//Variable Declaration

byte b;
int i;
boolean imNotTrue;
char c;

//Variable initialization

b = 127;
i = 1234423;
imNotTrue = false;
c = 'a'

// Inline declaration and initialization

int number = 64532;
boolean trustMe = true;

// you can't declare a variable twice in the same scope

int num = 5;
int num = 10;
 

method declar­ation

<modifier> <|abstract|> <returntype> <name> ( <parameter> , ... )
{

    //must be the same datatype as the returntype of the method.
    //no need for return if the returntype is void
    return <value>;
}