Posts

Showing posts from April, 2025

Data Types in Java

  In Java, data types define the type of data a variable can hold. They are mainly divided into two categories: 1. Primitive Data Types These are the most basic data types in Java: Type Description Size Example int Integer numbers 4 bytes int age = 25; float Decimal numbers (single precision) 4 bytes float temp = 36.5f; double Decimal numbers (double precision) 8 bytes double price = 99.99; char Single character 2 bytes char grade = 'A'; boolean True or false 1 bit boolean isJavaFun = true; byte Very small integers 1 byte byte x = 100; short Small integers 2 bytes short y = 10000; long Large integers 8 bytes long z = 100000L; 2. Non-Primitive (Reference) Data Types These are objects or classes that store references (memory addresses) to the actual data. String – a sequence of characters: String name = "John"; Arrays – stores multiple values of the same type. Classes, Interfaces, Enums – user-defined types used in object-oriented programming. Und...