Variables
- 8 Primitive Variables
 
intwidth of 32-bit, [-2^32, 2^32 - 1]. After Java 7, a long integer can be written as-2_147_483_648to be easier to readbytewidth of 8-bit. [-2^8, 2^8 - 1]shortwidth of 16-bit, [-2^16, 2^16 - 1]longwidth of 64-bit, [-2^64, 2^64 - 1]. Declare:long value = 100Lfloatwidth of 32-bitfloat myFloatValue = 5.2ffloat myFloatValue = (float) 5.2
doublewidth of 64-bitdouble myDoubleValue = 5.2ddouble myDoubleValue = 5.2- Doubles are more preferred in java since it’s more precise and faster
 
charwidth of 16-bit (2 bytes)char myChar = '\u00A9'
boolean
String is NOT a primitive data type in Java, but is considered as 9th variable1
2
3
4String str = "10";
int myInt = 50;
lastString = str + myInt;
System.out.println(lastString);
Output: 1050
[Cast]
Since Java will automatically translate literals in expressions into Integer, we have to cast it when doing calculations of other types: (byte) (myByteValue/2).Longer variables will accept shorter variables, (no need to cast byte to long), but shorter variables will not accept longer variables
Keywords & Expressions
Keywords are 53 reserved words.
Datatype is not part of the expression. Expression consist of variable, operators, value.