1. Primitive Data Types (Basic):
Primitive data types are basic built-in types that store actual values directly in memory.
Java has 8 Primitive Data Types
These store actual values
- Byte:
Stores small integer numbers
byte a = 10;
Program:
public class ByteExample {
public static void main(String[] args) {
byte a = 10;
System.out.println("Byte value: " + a);
}
}
- Short:
Stores medium integer numbers
short b = 200;
Program:
public class ShortExample {
public static void main(String[] args) {
short b = 200;
System.out.println("Short value: " + b);
}
}
- Int:
Stores integer numbers
int c = 1000;
Program:
public class IntExample {
public static void main(String[] args) {
int c = 1000;
System.out.println("Int value: " + c);
}
}
- Long:
Stores large integer numbers
long d = 100000L;
Program:
public class LongExample {
public static void main(String[] args) {
long d = 100000L;
System.out.println("Long value: " + d);
}
}
- Float:
Stores decimal numbers
float e = 10.5f;
Program:
public class FloatExample {
public static void main(String[] args) {
float e = 10.5f;
System.out.println("Float value: " + e);
}
}
- Double:
Stores large decimal numbers
double f = 20.99;
Program:
public class DoubleExample {
public static void main(String[] args) {
double f = 20.99;
System.out.println("Double value: " + f);
}
}
- char:
Stores single character
char g = 'A';
Program:
public class CharExample {
public static void main(String[] args) {
char g = 'A';
System.out.println("Char value: " + g);
}
}
- Boolean:
Stores true or false values
boolean h = true;
Program:
public class BooleanExample {
public static void main(String[] args) {
boolean h = true;
System.out.println("Boolean value: " + h);
}
}
Top comments (0)