7. Tokens and Industry Standards.

 Tokens 

Tokens are the smallest unit of java programming language.

They are classified into two types: -

1) Keyword's

2) Identifiers 

let's learn them in detail.......

1.  Keywords

 - The words which are aware by the compiler are known as keywords.

 - They have pre-defined meaning, and we cannot alter (change) them.

 - There are 50+ keywords in java.

 -  Every keyword must be written in lower case.

The below table is the list for keywords.








  



2.  Identifier   

Identifiers are names given by the programmer to various elements in a Java program. 

These elements can include classes, interfaces, variables, methods, packages, Enums, and more. 

 Examples of identifier

1)   Class Names: 'class MyClass { ... }'

2)   Interface Names: 'interface MyInterface { ... }'

3)   Variable Names: 'int myVariable = 10;'

4)    Method Names: 'public void myMethod() { ... }'

5)    Package Names: 'package com.example;'

6)    Enum Names: 'enum MyEnum {VALUE1, VALUE2;}'.

Rules of Identifier                                                                                          

 [Note - If we don't follow rules of identifier, we will get compile time error]

1) We cannot use keywords in place of identifier.

2) It cannot start with a number.

3) Character spaces are not allowed.

4) We can use only 2 special character that are '$' and '_'.

Note - 

1) underscore is allowed because we cannot use character spaces in between.

2)  We cannot use underscore as an identifier name because underscore represent a space and also it is a reserve word (similar like Keyword) also it is a reserve word from TDK 1.9.

3) '$' dollar are used to represent inner class and inner space


Industry Standard

Industry standards mean convention which we need to follow while creating an identifier.

1. Convention for Class -

  • If a class name is a single word first character must be in uppercase.
  • If a class name is multiword then every words first character must be in uppercase.
  • The way of writing a class name is called Pascal case.
  • Convention for an interface is same as class.
example of pascal case  -

  • 'MyClass'
  • 'EmployeeDetails'
  • 'StudentRecord'

2. Convention for Method -

  • If a method name is a single word, it must be in a lower case.
  • If a method name is multiword from second word onwards every words first character must be in uppercase.
  • The way of writing a method name is called Camel case.
  • Convention for variable is same as method.

example of camel case  -

  • 'myVariable'
  • 'calculateSum'
  • 'employeeName'

Comments