Getting Started
Hello.java
Compiling and running
Variables
Primitive Data Types
| Data Type |
Size |
Default |
Range |
byte |
1 byte |
0 |
-128 ^to^ 127 |
short |
2 byte |
0 |
-2^15^ ^to^ 2^15^-1 |
int |
4 byte |
0 |
-2^31^ ^to^ 2^31^-1 |
long |
8 byte |
0 |
-2^63^ ^to^ 2^63^-1 |
float |
4 byte |
0.0f |
N/A |
double |
8 byte |
0.0d |
N/A |
char |
2 byte |
\u0000 |
0 ^to^ 65535 |
boolean |
N/A |
false |
true / false |
{.show-header}
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
Operators
{.marker-none .cols-4}
{.marker-none .cols-4}
- &&
- ||
- ?:{data-tooltip=“Ternary (shorthand for if-then-else statement)”}
{.marker-none .cols-4}
{.marker-none}
{.marker-none .cols-4}
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
{.show-header .left-text}
ArrayList
HashMap
HashSet
ArrayDeque
Misc
Access Modifiers
| Modifier |
Class |
Package |
Subclass |
World |
| public |
Y |
Y |
Y |
Y |
| protected |
Y |
Y |
Y |
N |
| no modifier |
Y |
Y |
N |
N |
| private |
Y |
N |
N |
N |
{.show-header .left-text}
Regular expressions
See: Regex in java
Comment
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
{.marker-none .cols-6}
Math methods
| Method |
Description |
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