Tokens, conventions and literals in the java programming language

 

Tokens, conventions and literals in the java programming language

Tokens

 Smallest element at programming language which helps a programmer to compose instruction

   

        I.            Keywords:

§  Compiler aware words called keywords.

§  Keywords have predefine meaning

§  Keywords cannot alter by programmer or any other

§  Keywords are written in in lower case

§  Keywords cannot use any other purpose e.g. class, public, static, void

§  51+ keywords present in java

      II.            Identifiers:

                     Names given by the programmer to the component of java such as class name, method name, package name, interface name, variable name called identifier.

 

 Note: Rules are mandatory to follow. compiler checks for rules at compile time. If the rules are not followed, we get compile time error.

 

Rules:

a.      Any identifier should not start with number

Example:

·        
Program1                      Valid

·        
1program                        Invalid

b.      In identifiers special characters are not allowed other than “$” (dollar) and “_” (underscore)

Example:

·        
My_program$    

c.       Character spaces are not allowed while naming an identifier

Example:

·        
Madman                              

d.      We cannot use keyword like Static, Public while naming identifier 

  Example:

·        
Program                           

Conventions

            Conventions are the nothing but the culture followed by writing the identifier. conventions are  not mandatory but highly recommended. Compiler will not shut for conventions. If conventions are not followed, we don’t get any compile time error.

·         Conventions for the class name

§  If the class name is single word. Forst character is in uppercase and remaining is in lowercase.

§  If class name is multiword. The first character of every word should be in uppercase & remaining in lowercase

·         Conventions for method name

§  If method name is single word all characters should be in lowercase.

§  If the method name is multi word first character of first word should be lowercase from second word every first character is uppercase and remaining characters are in lowercase.

Literals

 

Note:  characters are enclosed with single quotes. e.g  ‘ a ’, ‘ %’

Special characters:

            Apart from characters and digits rest are special characters.

String:

            Group of characters called string. Strings are enclos4d with double quotes (“ “).

Class:

            Class is a blueprint or prototype that defines the variables and methods

             Example:

                        Class Blueprint {

                        Public Static void main (String [] args) {

                                    int a = 10;

                                    System.out.println(a);

}

                        }

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
https://otieu.com/4/9433883
https://otieu.com/4/9433883