public class HelloWorld { public static void main(String[] args) { // Prints "Hello, World" to the terminal window. System.out.println("Hello, World"); }}javac HelloWorld.javajava HelloWorldjavac *.javajava HelloWorld // HelloWorld is your preferred main class|
Type
|
Default Value
|
Memory Allocation
|
|
byte
|
0
|
8 bits
|
|
short
|
0
|
16 bits
|
|
int
|
0
|
32 bits
|
|
long
|
0L
|
64 bits
|
|
float
|
0.0F
|
32 bits (decimal)
|
|
double
|
0.00D
|
64 bits (decimal)
|
|
boolean
|
False
|
varies on impliment
|
|
String
|
NULL
|
depends on character count
|
|
char
|
\u0000
|
16 bits (unicode)
|
|
Operand
|
What they do
|
|
=
|
Assign value
|
|
==
|
Check value/address similarity
|
|
>
|
More than
|
|
>=
|
More than or equals
|
|
>>>
|
Move bit to the right by
|
|
++
|
Increment by 1
|
int x = 12;int x; // will be defined as 0String x = new String;double x = 10; // Expanding data typesint y = (int) 10.222222; // Narrowing data typesif (statement) {}if (statement) {} else{}switch (num) {
case 1: doSomething();
break;
default: doThis();
break;
}
for (int i: someArray) {}while (something) {}do {something} while (true)if (n < 2) { return false; }
for (int i=2; i <= n/i; i++)
if (n%i == 0) return false;
return true;
String s1 = "Hello World";String s2 = "Hello World;System.out.println(s1 == s2);TruenewString s1 = "Hello World";String s2 = new String;s2 = "Hello World";System.out.println(s1 == s2);FalseString s1 = "Hello World";String s2 = "Hello World";s2 = "Hello Thailand";System.out.println(s1 == s2);FalseVelocityResponseWritercom.company.project.uistudentNameMAX_PARAMETER_COUNT = 100Scanner x = new Scanner(System.in);String inputString = x.next(); // for String type inputint inputInteger = x.nextInt(); // for Integer type inputString inputString = args[0]; // for String type inputInt inputString = (int) args[0]; // for Integer type inputimport java.Object.Scanner
<default> modifier when not assigning any.public modifier allows same class access|
Attribute Type
|
Access Grants
|
|
Private
|
Allows only in class where variable belongs
|
|
Public
|
Allows any class to have this attribute
|
|
Static
|
Attribute that dependent on class (not object)
|
|
Final
|
Defined once. Does not allow any change/inheritance
|
<mod> <return> mthdName (<args>) { }public double getAge () { return someDouble;}<modifier> Person () {}<modifier> Person (String name) { this.name = name;}<access_modifier> abstract class HelloWorld () {}interface Bicycle { void speedUp (int increment);}class fuckBike implements Bicycle { ... void speedUp (int increment) { speed += increment; } ...}private void setTime(int hour, int minuite, int second){this.hour = hour;this.minuite = minuite;this.second = second;}class HelloWorld extends Object {}class HelloWorld inherits InterfaceThing {}public printer(String x){}public printer(String x, String y){}public printer(String x){}public printer(String x, String y){} // conflictpublic printer(String y, String x){} // conflict@Override in front of the public name. If the override is unsuccessful, JDK will returns error.public void helloWorld(){System.out.println("Hello");}@Overridepublic void helloWorld(){System.out.println("Hello World");}System.out.println("Hello World");System.out.print("Hello World");Scanner sc = new Scanner(System.in);double d = sc.nextDouble()|
Methods
|
Usage
|
Math.max(<value1>, <value2>) |
Return maximum value
|
Math.min(<value1>, <value2>) |
Return minimum value
|
Math.abs(<value>) |
Return unsigned value
|
Math.pow(<number>, <exponent> |
Return value of a numberexponent
|
Math.sqrt(<value>) |
Return square root of a value
|
msg.length()msg.toLowerCase()msg.toUpperCase()msg.replaceAll(String a, String b)msg.split(String delimeter)msg.startsWith(String pre)msg.endsWith(String post)String.format(String format, Object... args)|
Methods
|
Description
|
|
charAt(int index)
|
Returns the char value at the specified index
|
|
compareTo(String otherString)
|
Compare 2 strings lexicographically
|
|
concat(String str)
|
Concatenate specified string
|
|
endsWith(String suffix)
|
Test if the string ends with specified suffix
|
|
equals(String andObject)
|
Test if strings values are the same
|
|
toCharArray()
|
Convert string to character array
|
|
toLowerCase()
|
Convert string to lowercase
|
|
toUpperCase()
|
Convert string to uppercase
|
|
toString()
|
Convert things to string
|
|
valueOf(<value>)
|
Return the representation of argument
|
|
length()
|
Return length of the string
|
|
replaceAll(String a, String b)
|
Replace string a to string b
|
|
split(String delimeter)
|
Split string between delimeter
|
|
startsWith(String prefix)
|
Test if string starts with specified prefix
|
|
format(String format, Object arg)
|
Format strings to the format given
|
boolean add(Object element);boolean remove(Object element);int size();boolean isEmpty();boolean contains(Object element);Iterator Iterator();|
Method
|
Usability
|
|
void add (int index, Object element)
|
Add value to list
|
|
Object remove(int index)
|
Remove item #index from list
|
|
Object get(int index)
|
Retrieve item #index from list
|
|
void set(int index, Object element)
|
Set data to correspond #index
|
|
int indexOf(Object element)
|
Find the #index from element
|
|
ListIterator listIterator()
|
|
List x = new HashList();
|
Method
|
Usability
|
Arrays.asList(1, 2, 3)Arrays.stream(primitiveArray)arrayList.stream()LinkedList myList = new LinkedList<Integer>t()new LinkedList<>(Arrays.asList(1, 2, 3)))myList.add(50)Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.