Page 136 - ComputerScience_Class_11
P. 136
Primitive valueS, wraPPer
claSSeS, tyPeS aNd caStiNg
6
Learning Objectives
6.1 Token 6.2 Escape Sequence
6.3 Data Types 6.4 Arithmetic Expression
6.5 Type Conversion 6.6 Wrapper Class
6.7 Class as Type of the Object 6.8 Class as Mechanism for User-Defined Type
In the previous chapter, we studied objects and classes in Java. These are two basic components of object-oriented
programming. Apart from these, there are some additional fundamentals that we should know before writing programs,
these includes primitive values, wrapper classes and type casting. Let us read about these in this chapter.
6.1 TOKEN
In Java, every individual component of a program is known as a token. It is the fundamental unit of the code. Tokens
are also known as the building blocks of Java programs. There are different types of tokens used in Java which are as
follows:
• Identifiers • Literals • Punctuators
• Separators • Operators
Let’s explore these in detail.
6.1.1 Identifiers
The user-defined names which are used as the names of classes, variables or methods are known as Identifiers.
Identifiers must not be the same as Java keywords. However, they may be similar to keywords as long as they are not
exactly the same.
class sum
{
public static void main(String[] args)
{
int a = 5,b = 4,s;
s = a+b;
System.out.println("Sum of two numbers: "+s);
}
}
Here, the name of the class “sum” and the variables “a”, “b” and “s” are known as identifiers.
134 Touchpad Computer Science (Ver. 3.0)-XI

