Miscellaneous
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 |
Regular expressions
String text = "I am learning Java";
// Removing All Whitespace
text.replaceAll("\\s+", "");
// Splitting a String
text.split("\\|");
text.split(Pattern.quote("|"));
See: Regex in java
Comment
// I am a single line comment!
/*
And I am a
multi-line comment!
*/
/**
* This
* is
* documentation
* comment
*/
Keywords
abstractcontinuefornewswitchassertdefaultgotopackagesynchronizedbooleandoifprivatethisbreakdoubleimplementsprotectedthrowbyteelseimportpublicthrowscaseenuminstanceofreturntransientcatchextendsintshorttrycharfinalinterfacestaticvoidclassfinallylongstrictfpvolatileconstfloatnativesuperwhile
{.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
try {
// something
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("always printed");
}