PRIMITIVE DATA TYPES
Integer |
|
Minimum Value |
Default |
Maximum Type Value |
byte |
|
-128 (byte) |
0 |
127 |
short |
2 bytes |
-32,768 (short) |
0 |
32,767 |
int |
4 bytes |
-2,147,483,648 |
0 |
2,147,483,647 |
long |
8 bytes |
-9,223,372,036,854,775,808 |
0 |
9,223,372,036,854,775,807 |
float (4 bytes with 7 digits fractions)
double (8 bytes with 15 digits fractions)
char (are specified between SINGLE quotation marks)
String (are specified between DOUBLE quotation marks)
Boolean
59 reserved words, including all of the data types.
CONSTANT
final
ARRAYS
One-dimensional array is a numbered list of variables of the same type.
String[] dinnerGuests = new String[8];
dinnerGuests[0] = “Fred”;
dinnerGuests[1] = “Jane”;
…
String dinnerGuests[] = {“Fred”, “Jane”, “Michael”, “Brenda”, … }
int twoDiArray[][]={{10,9,8,7,6,5,4,3,2,1},{}}; // Declare a two dimensional array
int[][][] threeDiArray; // Uninitialized 3D array.
Array indexes must either be type int (32-bit integer) or be able to be cast as an int. As a result, the largest possible array size is 2,147,483,647.
STRING
String in Java is represented as a class, not as an array of characters, so it has methods such as length() and substring().
OPERATORS
+ Addition
- Subtraction
* Multiplication
/ Division
% Integer Remainder
++ increment operators
-- decrement operators
double * (float, long, int, short, byte) = double
double mySalary = 1000.65
int approxSalay = (int) mySalary //called casting process
== is equal to
!= is not equal to
< is less than
> is more than
<= is less than or equal to
>= is greater than or equal to
&& AND
|| OR
CONTROL STRUCTURES
if ( ) { … } else { … }
while ( ) { … }
do { … } while ( )
for (int i=10; i=0; i--) { … }
switch