==
Primitive Types vs Reference Types
==
Primitive Types
- byte, short, int, long, float, double, char, boolean
- used for storing simle values
- copied by their value, and these values are independent of each other
Reference Types
- classes eg Array, Date, Point, String
- copied by their references
- used for storing complex objects
==
Strings
==
- immutable // anything that modifies a String returns a new String
eg String name = "Erron";
[Link]([Link]("o", "")); // Errn
[Link](name); // Erron
String name = "Hello World";
[Link]() // 11
[Link]("rld") // true
[Link]("e") // 1
[Link](" ", "_") // Hello_World
[Link]() // hello world
[Link] // HELLO WORLD
[Link]() // eg " Hello World " => "Hello World"
==
Escape Sequences
==
use Backslash (\) to use special characters
String message = "Hello \"Erron\""; // Hello "Erron"
==
Arrays
==
int[] numbers = new int[2];
number[0] = 1;
number[1] = 2;
[Link]([Link]());
int[] numbers = {1,2,3};
==
Math
==
[Link](1.1F) // 1
[Link](1.1) // 2
[Link](1.1) // 1
[Link](1, 2) // 2
[Link](1, 2) // 1
[Link]() // any number from 0 - 1
[Link]() * 100 // any number from 0 - 100 with decimal value
[Link]([Link]() * 100) // any number from 0 - 100 without decimal value
==
NumberFormat currency = [Link]();
String result = [Link](1234.567) // $1,234.57
[Link]().format(0.1) // 10%
==
Reading Input
==
Scanner scanner = new Scanner([Link]);
[Link]("Enter age: ");
byte age = [Link](); // eg 12
[Link]("Age: " + age); // Age: 12
==
String[] fruits = {"Apple", "Mango", "Banana"}
for(String fruit : fruits) {
[Link](fruit);
}
==