xxxxxxxxxx
/*
Java Data Types
There 2 Types Of Data Types In Java
1) Primitive -> byte, char, short, int, long, float, double and boolean.
2) Non-primitive -> (All Classes) -> String, Arrays etc.
Type Size Stores
byte 1 byte whole numbers from -128 to 127
short 2 bytes "" -32,768 to 32,767
int 4 bytes "" -2,147,483,648 to 2,147,483,647
long 8 bytes ""-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float 4 bytes fractional numbers; for storing 6 to 7 decimal digits
double 8 bytes fractional numbers; "" 15 ""
boolean 1 bit true or false values
char 2 bytes single character/letter or ASCII values
*/
xxxxxxxxxx
/*
Java Data Types
There 2 Types Of Data Types In Java
1) Primitive -> byte, char, short, int, long, float, double and boolean.
2) Non-primitive -> (All Classes) -> String, Arrays etc.
Type Size Stores
byte 1 byte whole numbers from -128 to 127
short 2 bytes "" -32,768 to 32,767
int 4 bytes "" -2,147,483,648 to 2,147,483,647
long 8 bytes ""-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float 4 bytes fractional numbers; for storing 6 to 7 decimal digits
double 8 bytes fractional numbers; "" 15 ""
boolean 1 bit true or false values
char 2 bytes single character/letter or ASCII values
*/
xxxxxxxxxx
// This code provides a list of Java data types along with their descriptions.
// You can add or modify descriptions as needed.
public class DataTypesInJava {
public static void main(String[] args) {
System.out.println("Java Data Types:");
System.out.println("1. int: Used for storing whole numbers");
System.out.println("2. float: Used for storing decimal numbers");
System.out.println("3. double:Used for storing double precision decimal numbers");
System.out.println("4. char: Used for storing single characters");
System.out.println("5. String:Used for storing sequence of characters");
System.out.println("6. boolean:Used for storing true/false values");
System.out.println("7. byte: Used for storing small integer values");
System.out.println("8. short: Used for storing small integer values");
System.out.println("9. long: Used for storing large integer values");
}
}
xxxxxxxxxx
int age = 28;
char grade = 'A';
boolean late = true;
byte b = 20;
long num1 = 1234567;
short no = 10;
float k = (float)12.5;
double pi = 3.14;
null is another, but it can only ever store the value null.
xxxxxxxxxx
int count = 0;
// Check for each primitive data type
if (boolean.class.isPrimitive()) count++;
if (byte.class.isPrimitive()) count++;
if (short.class.isPrimitive()) count++;
if (int.class.isPrimitive()) count++;
if (long.class.isPrimitive()) count++;
if (float.class.isPrimitive()) count++;
if (double.class.isPrimitive()) count++;
if (char.class.isPrimitive()) count++;
System.out.println("The number of primitive data types in Java are: " + count);