Page 129 - Cs_withBlue_J_C11_Flipbook
P. 129

06                           PRIMITIVE VALUES,


                                                                        WRAPPER CLASSES,

                                                                       TYPES AND CASTING













                          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




                 In the previous chapter, we have read about objects and classes in Java. These are two basic components of
                 object-oriented programming. Apart from these, there are some more fundamentals that we should know before writing
                 programs. For example, primitive values, wrapper classes, and type casting. Let us read about these in this chapter.


                     6.1 TOKEN
                 In Java, every individual component used 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 us study them 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. These
                 identifiers should not resemble any keywords. Even if the words are the same, there should be a difference in at least
                 one alphabet.
                   class sum
                   {
                       public static void main()
                       {
                            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.


                                                                                                                       127
                                                                         Primitive Values, Wrapper Classes, Types and Casting   127
   124   125   126   127   128   129   130   131   132   133   134