Page 109 - computer science (868) class 11
P. 109
• boolean: The Boolean data type is used to store only two possible values: true or false. It specifies one bit of
information. The default value is “false”.
Type Size Range Default value Example
byte 1 byte/8 bits -128 to +127 0 byte b = 10
short 2 bytes/16 bits -32768 to +32767 0 short s = 1234
31
31
int 4 bytes/32 bits -2 to 2 -1 0 int i = 123456
long 8 bytes/64 bits -2 to 2 -1 0L double d = 123456L
63
63
float 4 bytes/32 bits -3.4E+38 to 3.4E+38 0.0f float a = 10.67f
double 8 bytes/64 bits -1.7E+308 to 1.7E+308 0.0 or 0.0d double b = 1234.87674
char 2 bytes/16 bits 0 to 255 \u0000 char c = 'a'
char d = '\u0041'
boolean 1 bit true/false false boolean a = true;
• char: It stores character constants in the memory. The char data type is a single 16-bit Unicode character. It assumes
a size of 2 bytes, but basically it can hold only a single character because char stores Unicode character sets. It has
a minimum value of ‘\u0000’ (or 0) and a maximum value of ‘\uffff’ (65,535).
Type Size Default value Example
char 2 bytes \u0000 char c='a'
char d= '\u0041'
Java uses Unicode system, which includes ASCII code system and other characters from languages around the world.
To represent Unicode system, 8 bits is not enough to represent all characters, so Java uses 16 bits or 2 bytes for
characters.
Note: A word or a sentence includes more than one character, hence, it is called a String whose size
belongs to the number of characters together held. For example, if the word is “India”, then the size is 2
bytes × 5 characters = 10 bytes
Non-Primitive Data Types
Non-primitive data types are defined by the user. But they are built on primitive data types, i.e., they basically
concatenate two or more same or different types of primitive data types. For this reason, they are known as the
Derived data types. The different types of user-defined data types are String, class, array and interfaces. They are also
known as reference data types or composite data types or user-defined data types.
Non-Primitive
Class Array Interface string
Now, we will discuss the non-primitive data types in detail.
Class
A class is a prototype created by the user from which the same type of objects are created. All the data members and
the methods of the class are common to all the objects have been created. For example,
class sum
{
107
Primitive Values, Wrapper Classes, Types and Casting 107

