What are primitive types?
Primitive types are the simplest, indivisible data values stored directly in memory. In computing, they represent basic hardware-level data (like numbers or single characters). In Java, primitive types are built-in, non-object values with fixed sizes and efficient storage.
What are the three types of primitive data?
Depends on the programming language, but usually:
Numeric (int, float)
Character (char)
Boolean (true/false)
How many bits does each primitive type use?
A (Java — fixed sizes except boolean):
byte — 8 bits (−128 to 127)
short — 16 bits (signed)
int — 32 bits (signed)
long — 64 bits (signed)
float — 32 bits (IEEE 754)
double — 64 bits (IEEE 754)
char — 16 bits (UTF-16 code unit; may form surrogate pairs for some Unicode characters)
boolean — size not specified by Java; conceptually 1 bit, but actual storage depends on the JVM/implementation (often 1 byte in arrays, promoted to int for operations)
B (General computing — common conventions):
boolean — conceptually 1 bit (true/false)
integer sizes vary by language/platform (common modern conventions): byte 8, short 16, int 32, long 64
floating point: float 32-bit, double 64-bit (IEEE 754)
character storage depends on encoding: ASCII/UTF-8 uses 8-bit code units; UTF-16 uses 16-bit code units; Unicode code points may require more than one unit.
What are the numeric primitive data types in Java?
A: Java has 6 numeric primitive types:
Integral types (whole numbers):
byte — 8 bits
short — 16 bits
int — 32 bits
long — 64 bits
Floating-point types (decimal numbers):
float — 32 bits (IEEE 754)
double — 64 bits (IEEE 754)
What is the boolean data type?
Boolean = primitive logical type with two values: true/false. Conceptually 1 bit, but Java does not define its size. Used for conditions and control flow.
Example of using a byte in Java and how many bits does the Java byte use?
```java
byte b = 100;
System.out.println(b); // prints 100
~~~
- Size: 8 bits
- Range: -128 to 127
Example of using a short in Java and how many bits does the Java short use?
```java
short s = 20000;
System.out.println(s); // prints 20000
~~~
- Size: 16 bits
- Range: -32,768 to 32,767
Example of using an int in Java and how many bits does the Java int use
```java
int i = 100000;
System.out.println(i); // prints 100000
~~~
- Size: 32 bits
- Range: -2,147,483,648 to 2,147,483,647
Example of using a long in Java and how many bits does the Java long use
```java
long l = 10000000000L;
System.out.println(l); // prints 10000000000
~~~
- Size: 64 bits
- Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Example of using a float in Java and how many bits does the Java float use
```java
float f = 3.14f;
System.out.println(f); // prints 3.14
~~~
- Size: 32 bits
- Single-precision decimal numbers
Example of using a double in Java and how many bits does the Java double use
```java
double d = 3.14159265359;
System.out.println(d); // prints 3.14159265359
~~~
- Size: 64 bits
- Double-precision decimal numbers
Example of using a char in Java and how many bits does the Java char use
```java
char c = ‘A’;
System.out.println(c); // prints A
~~~
- Size: 16 bits
- Stores a single Unicode character
Example of using a boolean in Java and how many bits does the Java boolean use
```java
boolean flag = true;
System.out.println(flag); // prints true
~~~
- Values: true or false
What are the 8 primitive data types in Java?
Type Size Range / Values Description
byte 8 bits -128 to 127 Small integers
short 16 bits -32,768 to 32,767 Larger integers than byte
int 32 bits -2³¹ to 2³¹-1 Standard integer type
long 64 bits -2⁶³ to 2⁶³-1 Large integers
float 32 bits Approx. ±3.4e38, 7 decimal digits Single-precision floating-point
double 64 bits Approx. ±1.7e308, 15 decimal digits Double-precision floating-point
char 16 bits ‘\u0000’ to ‘\uffff’ (Unicode) Single character
boolean 1 bit* true or false Logical values
What is the size and range of byte in Java?
Size: 8 bits
Range: -128 to 127
What is the size and range of short in Java?
Size: 16 bits
Range: -32,768 to 32,767
What is the size and range of int in Java?
Size: 32 bits
Range: -2,147,483,648 to 2,147,483,647
What is the size and range of long in Java?
Size: 64 bits
Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
What is the size and range of float in Java?
Size: 32 bits
Range: approximately ±3.40282347E+38F
Single-precision decimal numbers
What is the size and range of double in Java?
Size: 64 bits
Range: approximately ±1.79769313486231570E+308
Double-precision decimal numbers
What is the size and valid values of char in Java?
Size: 16 bits
Range: 0 to 65,535 (Unicode characters)
Example: ‘A’, ‘Ω’, ‘\n’
What is the size and valid values of boolean in Java?
Size: JVM dependent (typically 1 bit)
Values: true or false
Primitive Data Type (Definition)
The most basic, fundamental data type built into a programming language, representing a single, simple value.
Alternative Definition for what is primitive data type.
Small blocks of data that are fundamental to the Data Structures.