Page 44 - CA_Blue( J )_Class10
P. 44
Boolean Type
The boolean data type stores only two possible values true or false. This data type is used for simple flags that track
true/false conditions. The boolean data type specifies one bit of information.
Type Size Default value Range of values that can be stored Format
boolean 1 bit false true or false boolean a=true;
Note: • Integer type and Float-point type are numeric data types.
• Character type and Boolean type are non-numeric data types.
3.5.2 Non-Primitive Data Types
Non-primitive data types are also called reference data types or composite data types. They contain a memory address
of variable value because the reference types won't store the variable value directly in memory. They are defined by
the programmer according to the requirement of the program. Different types of non-primitive data types are strings,
objects, arrays and interfaces.
3.5.3 Difference between Primitive Data Types and Non-Primitive Data Types
Primitive Data Type Non-Primitive Data Type
They are built-in data types. They are user-defined data types.
To use them "new" operator is not required. The use of "new" operator is mandatory.
The size of a primitive type depends on the data type. Size may vary.
Primitive data types can store only single value at a The non-primitive data types are used to store the group
time. of values.
3.6 VARIABLES AND CONSTANTS
Variable is the name of an area reserved in computer memory for an identifier to store a value. In other words, it is
the name of a memory location. As the name suggests, the value of a variable can be changed during the program
execution. It may take different values at different points of execution which depends on the logic of the program.
It is suggested that the names of the variables should be explanatory which means that the variable names describe
their purpose. For example, to store the age of a person, the best suitable name for the variable is 'age' instead of using
variable names like x or y.
3.6.1 Declaring a Variable
Before using a variable, we need to declare it at the beginning of the program. If a variable is not declared, we cannot
use it. If you try to use a variable that is not declared, the Java compiler displays an error message. Syntax to declare
a variable is:
<data type> <name of the variable>;
Where, the <data type> specifies any primitive or non-primitive data type and the name of the variable should be a
valid Java identifier. For example:
int roll_no;
Here, int is the data type and the roll_no is the variable name. As you know that every statement is terminated with
semicolon. Hence, the declaration statement is also terminated.
We can also declare multiple variables of the same type simultaneously. All the variables named should be separated
by a comma. For example:
int roll_no, marks, age;
4242 Touchpad Computer Applications-X

