Posts

Showing posts with the label Java Primitive Data Types

Primitive Data Types in Java with Size and Default Values

Primitive Data Types in Java Primitive data types are basic data types in Java that determine the type and amount of memory required to store a value. Java provides a fixed set of primitive data types for efficient memory usage. There are two main categories of primitive data types: Numeric Non-Numeric 1. Numeric Data Types Numeric data types are used to store numerical values. They are further divided into two types: a) Integer Data Types Integer data types store whole numbers (without decimal points). byte- 8 bits short- 16 bits int- 32 bits long- 64 bits b) Floating-Point Data Types Floating-point data types store decimal numbers. float- 32 bits double- 64 bits 2. Non-Numeric Data Types Non-numeric data types are used to store non-numerical values. char – Stores a single character and occupies 16 bits of memory boolean – Stores true or false (Memory size is JVM-dependent) Default Values in Java A default value is a value automatically assigned by the compiler when a data type is d...