int myNum = 5; // Integer number
float myFloatNum = 5.99f // Floating number
char myLetter = 'N' // Character
boolean myBool = True; // Boolean
String myText = "Hello"; // string
Data types are divided into two groups :
- Primitive data type - includes byte, short, int, long, float, double, boolean and char
- non-primitive data type - such as string, arrays and classes.
Primitive Data Types
A Primitive data type specifies the size and type of valiable values, and it has no additional methods.
There are eight primitive data types in java:
byte - 1 byte
description : stores whole numbers from -128 to 127
short - 2 bytes
stores whole numbers from -32,768 to 32,767
int - 4 bytes
stores whole numbers from -2,147,483,6478 to 2,247,483,647
long - 8 bytes
stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float - 4 bytes
Stores fractional number. Sufficient for storing 6 to 7 decimal digits
boolean - 1 bit
stores true or false values
char - 2 bytes
stores a single character/letter or ASCII values.
0 Comments