Primitives: start with lower case
References/classes: Start with upper case
Ex. Strings
Int: Integer
Double: Decimal
Can also be an integer, in a way
Char: Character
String: String
Boolean: Boolean (true or false)
Difference between char and string:
- When changing the value of char, the old value gets deleted, but in when a string is changed, the old string is still in memory by default
- String use ” ” and characters use ‘ ‘
Every data type is primitive, except strings (they are reference)
When dividing only use doubles, integers do not work well, they will just round down to nearest integer, even if the number is 2.9, it will become 2
Special characters:
\t = tab
\n = newline
\’ = single quote
\” = double quote
Assignment: equal sign (=)
A single = denotes (means) assignment
A variable can be changed:
Ex.
Int counter = 0;
Counter = counter + 1;
System.out.println(counter);
1
Increment(add) and decrement(minus) by 1:
++: used to add 1
—: used to subtract 1
Ex.
Int x = 0;
x++; => 1
x—; => 0
Data Type Storage in Java:
- Character (char) → 16 bits
- Integers
- Byte → 8 bits
- Short → 16 bits
- Int → 32 bits
- Long → 64 bits
- Floating Point
- Float → 32 bits
- Double → 64 bits
- Boolean → 1 bit (true/false)
- Scanner IS also a data type for input
No Responses