Java
Getting Started
Hello.java
public class Hello {
// main method
public static void main(String[] args)
{
// Output: Hello, world!
System.out.println("Hello, world!");
}
}Compiling and running
$ javac Hello.java
$ java Hello
Hello, world!Variables
int num = 5;
float floatNum = 5.99f;
char letter = 'D';
boolean bool = true;
String site = "quickref.me";Primitive Data Types
Strings
See: Strings
Loops
See: Loops
Arrays
See: Arrays
Swap
Type Casting
Conditionals
See: Conditionals
User Input
Java Strings
Basic
Concatenation
StringBuilder
StringBuilder sb = new StringBuilder(10);
sb.append("QuickRef");
sb.delete(5, 9);
sb.insert(0, "My ");
sb.append("!");
Comparison
Manipulation
Information
Immutable
Once created cannot be modified, any modification creates a new String
Java Arrays
Declare
Modify
Loop (Read & Modify)
Loop (Read)
Multidimensional Arrays
Sort
Java Conditionals
If else
Switch
Ternary operator
Java Loops
For Loop
Enhanced For Loop
Used to loop around array's or List's
While Loop
Do While Loop
Continue Statement
Break Statement
Java Collections Framework
Java Collections
ArrayList
HashMap
HashSet
ArrayDeque
Misc
Access Modifiers
Regular expressions
See: Regex in java
Keywords
abstract
continue
for
new
switch
assert
default
goto
package
synchronized
boolean
do
if
private
this
break
double
implements
protected
throw
byte
else
import
public
throws
case
enum
instanceof
return
transient
catch
extends
int
short
try
char
final
interface
static
void
class
finally
long
strictfp
volatile
const
float
native
super
while
Math methods
Math.max(a,b)
Maximum of a and b
Math.min(a,b)
Minimum of a and b
Math.abs(a)
Absolute value a
Math.sqrt(a)
Square-root of a
Math.pow(a,b)
Power of b
Math.round(a)
Closest integer
Math.sin(ang)
Sine of ang
Math.cos(ang)
Cosine of ang
Math.tan(ang)
Tangent of ang
Math.asin(ang)
Inverse sine of ang
Math.log(a)
Natural logarithm of a
Math.toDegrees(rad)
Angle rad in degrees
Math.toRadians(deg)
Angle deg in radians
Try/Catch/Finally
Last updated