Page 62 - TP_iPlus_V2.1_Class8
P. 62
Data Type Size (in bits) Minimum Value Maximum Value
double 64 4.9E –324 1.7976931348623157E308
boolean 1 True or False
Non-Primitive Data Types
The non-primitive data types are derived from primitive data types. The non-primitive data types
are also known as reference data types. Some of the examples of non-primitive data types are
class, interface, and array.
Literals
A literal denotes a constant value. Java has various types of literals. They are as follows:
• Character Literal: A character literal is enclosed in single quotes and must have exactly one
character. For example, ‘a’ is a character literal that means the letter a.
• String Literal: A string literal is always enclosed in double quotes. For example, “Hello World.”
• Integer Literal: An integer literal is any number without a fraction. For example, 10 and 012
• Floating-Point Literal: Any number with decimal points, like 3.12, is treated as a floating-point
literal.
• Boolean Literal: Boolean literals can have either true or false values. They do not correspond
to 0 or 1 values as in C/C++.
Variables
Variables are the memory locations used to store values. When a variable is created, some space
is allocated for it in the memory. This memory space is referred to by the name that we give to
the variable. It is easy to create a variable in Java.
Declaring a Variable
In Java, a variable needs to be declared before use. Declaring a variable involves two steps: giving
the variable a name and stating what type of data is to be stored in the variable.
For example,
int age;
String name;
float temp;
double price;
Here, four variables named age, name, temp, and price are declared with the int, String, float, and
double data types, respectively.
Initialising a Variable
Intitialising means assigning a value to the variable at the time of declaration. We can initialise
variables in the following way:
int age = 30;
String name = "Nisha";
60
iPlus (Ver. 2.1)-VIII

