Object Oriented Programming

Data Type

Group Data Type Size Range
Integer byte 1 byte 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,648 to 2,147,483,647
long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Floating-point float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double 8 bytes Stores fractional numbers. Sufficient for storing 15 to 16 decimal digits
Character char 1 bytes Stores a single character/letter or ASCII values
String 1
Boolean boolean 1 bytes Stores true or false values

Input vs Output

Type Example Format Scanner scan = new Scanner(System.in);
Integer byte a = 7; System.out.printf("%d", a); byte a = scan.nextByte();
short a = 9; short a = scan.nextShort();
int a = 9; int a = scan.nextInt();
long f = 9; long f = scan.nextLong();
Floating-point float f = 7.3f; System.out.printf("%f", f); float f = scan.nextFloat();
double a = 7.9; double a = scan.nextDouble();
Character char ch = 'A'; System.out.printf("%c", ch); char ch = scan.next().charAt(0);
String String s = "Hello"; System.out.printf("%s", s); String s = scan.nextLine();
Boolean boolean b = true; System.out.printf("%b", b); boolean b = scan.nextBoolean();