Java¶
/*
Multiline comment
*/
// single line comment
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Variables¶
Primitive types:
String
- characterschar
- single characterint
- integerfloat
- floating point numberboolean
- true or false
// declaration
type variableName = value;
// other possible declarations
type variableName;
variableName = value;
int anInteger = 1;
// multiple declarations
type x, y, z;
x = y = z = value;
int x = 1, y = 2, z = 3;
Keywords:
final
- constantstatic
- class variablepublic
- accessible from anywhereprivate
- accessible only from the classprotected
- accessible from the class and subclassesvoid
- no return value
final type variableName = value;
final int CONSTANT = 1;
Data Types¶
byte
- 1byte numbers: -128 to 127short
- 2bytes numbers: -32,768 to 32,767