Basic Java Cheat Sheet
Basic Java Cheat Sheet
Naming Conventions
1. Names of programs start with a capital letter
2. Names of variables and functions are lower case letters
3. No spaces between words but each subsequent words begins with a capital letter is
called “Camel Case” or using underscores between words (older form or unix and MS
based) is “Snake Case.”
Number Conventions
Numbers start at 0 (for example first ten digits are 0,1,2,3,4,5,6,7,8,9)
Based on 8-Bit architecture of 2^8 (i.e 256 values) ranging from 0 to 255
0 is full off, 255 is full on, 63 is the first quarter, 127 is half and 191 is the three quarter value
Output Window
size( width, height );
background( colour ) ;
Colour
0 is Black, 255 is White, Everything in between is a Shade of Grey
Red, Green, Blue and Additive Light Colours (Cyan, Magenta, Yellow)
Opacity effects, append 0 (Transparent) to 255 (Opaque) to colour value or black/white value
Shapes
point( x, y);
line( x1, y1, x2, y2);
rect( x, y, width, height);
note: x, y represent the top left corner of the rectangle
appending another value (or argument) rounds corners
Text
text( “Hello World”, x, y);
textSize( );
Variables
int x = 0; integers don’t have decimals
float y = 1.23; floats have decimals
boolean play = true; either True or False
char initial = “H”
String name = “Kevin”; strings of characters are words
Conditional Statements
if ( conditional ) equal to == and &&
{ not equal to != or ||
greater than >=
} less than <=
Loops
for( int i = 0; i < number of loops; i = i + 1 ); note: shorthand version of “i = i + 1”
{ is “i++”
Modules
Key Modules
void setup( ) void draw( )
{ {
} }
Common Modules
void keyPressed( ) void keyReleased( )
{ void mousePressed( )
int k = keyCode;
if ( k = = LEFT)
{
}
}
You can also create a module for anything else that you would like to use but you need to “call”
the module in your program (usually in the void draw).
References:
processing.org
coding-club.weebly.com