Write about Java Data Types (Primitive)

Java Data Types (Primitive)

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Data Types (Primitive)
Java Data Types (Primitive)

Write about Java Data Types (Primitive)

There are mainly 8 Primitive Data Types

Primitive data types are the basic and built-in types in Java.
Java has 8 primitive data types:


✅ 1. byte

  • Stores whole numbers

  • Size: 1 byte

  • Range: −128 to 127

  • Good for saving memory

Example:

public class Main {
public static void main(String[] args) {
byte age = 20;
System.out.println(age);
}
}

✅ 2. short

  • Stores small whole numbers

  • Size: 2 bytes

short marks = 250;

✅ 3. int

  • Most commonly used

  • Stores normal whole numbers

  • Size: 4 bytes

int price = 5000;

✅ 4. long

  • Stores very large whole numbers

  • Size: 8 bytes

long population = 1400000000L;

✅ 5. float

  • Stores decimal numbers

  • Size: 4 bytes

  • Must end with f

float rating = 4.5f;

✅ 6. double

  • Stores big decimal numbers

  • Size: 8 bytes

  • More accurate than float

double temperature = 36.987;

✅ 7. char

  • Stores a single character

  • Written in single quotes

char grade = 'A';

✅ 8. boolean

  • Stores true or false

boolean isJavaEasy = true;

⭐ Full Program to Show All Primitive Data Types

public class DataTypesExample {
public static void main(String[] args) {

byte age = 20;
short distance = 1200;
int amount = 50000;
long population = 1400000000L;

float height = 5.7f;
double weight = 62.456;

char letter = ‘J’;
boolean isLearningJava = true;

System.out.println(“Age: ” + age);
System.out.println(“Distance: ” + distance);
System.out.println(“Amount: ” + amount);
System.out.println(“Population: ” + population);
System.out.println(“Height: ” + height);
System.out.println(“Weight: ” + weight);
System.out.println(“Letter: ” + letter);
System.out.println(“Learning Java: ” + isLearningJava);
}
}

OUTPUT:-

Age: 20
Distance: 1200
Amount: 50000
Population: 1400000000
Height: 5.7
Weight: 62.456
Letter: J
Learning Java: true

Leave a Reply

Your email address will not be published. Required fields are marked *