Page 94 - 2617_JSSPS_C-6
P. 94

Rules for Naming Identifiers

              The rules for naming an identifier are:
                  An identifier can consist of letters, digits 0–9, underscore ( _ ), and dollar ($) symbol.

                  An identifier cannot start with a digit.
                  Keywords cannot be used as an identifier.
                  No special symbols like !, @, #, %, etc. can be used in an identifier.

                  Identifiers are case-sensitive, which means ‘name’ and ‘NAME’ are two different identifiers.
              Examples of some valid  identifier  names are Employee123,  mygood_book, _address93, FirstName,
              age, etc.

              Examples of some invalid identifier names are 1_Name, @Address, 1234, –Age, etc.
              Keywords


              Keywords  are the reserved words that cannot be used as identifier  names as they carry a special
              meaning for the Java compiler. Some of the Java keywords are given below:
                                                           Java Keywords
                 abstract            class               final                interface           static

                 assert              const               float                long                switch
                 boolean             continue            for                  new                 this
                 break               default             if                   private             throw
                 byte                do                  implements           protected           throws
                 case                double              import               public              try

                 catch               else                instanceof           return              void
                 char                extends             int                  short               while

              Although reserved as a keyword in Java, const is not used and has no function.

              There are three more reserved words in Java: true, false, and null. Technically, they are literal values
              and not keywords. However, they cannot be used as identifiers, and they have a specific meaning to
              the Java compiler.

              Data Types

              A data type is used to define the size and type of value that a variable can store. The Java language is
              rich in its data types. Java provides two types of data types: primitive and non-primitive.

              Primitive Data Types

              Java provides eight basic data types, which are as given in the following table:

                Data Type       Size (in bits)          Minimum Value                    Maximum Value
               byte          8                   –128                            127
               short         16                  –32768                          32767
               int           32                  –2147483648                     2147483647







                 92     Premium Edition-VI
   89   90   91   92   93   94   95   96   97   98   99