Lexical Tokens in java:

The low level language elements in java are called lexical tokens or tokens in short. A java program consists of a set of tokens. They are the building blocks for a programming language.

Following are the examples of tokens:

1.Identifiers 2.Keywords 3.Literals 4.Comments 5.Data Types 6.Operators


All the names provided by the programmer/developer in a java program is called as identifier. For example: variable name, class name, method name etc.
 public class Abc 
       int i;
       String name;
       public void testMethod() 
In the above program Abc, i, name, testMethod() are identifiers as these are given by the programmer.


Every programming language has some predefined words and those words are called as keywords. E.g. int, float, class, void etc.

Important points about keywords:

-> It expresses the language feature. -> Programmer must not use keywords as naming purpose of variables, methods or classes. -> Keywords composed of lowercase letters. -> As java is a case sensitive language so the keywords with all or some letters in uppercase can be treated as variable name.

Keyword List:

break double implementsprotected throw
byteelseimport publicthrows
catchextendsintshort tr
charfinal interfacestaticvoid
const float nativesuperwhile


The values that we store in a variable are called as literals. A literal contains a sequence of characters such as digits, alphabets or any other special symbols.
Literals are the code representation of a primitive data type values.

Types of literals in java :

1.Integer literal:

E.g. int i = 10; Here 10 is a integer literal.

2.Floating point literal:

E.g. float f = 10.6f; Here 10.6f is a floating point literal

3.Character literal:

E.g. char ch = 'a'; Here a is a character literal

4.String literal:

E.g. String s = "Hello World"; Here Hello World is a string literal.

5.Boolean literal:

E.g. boolean b = true; Here true is a boolean literal.


Programmer/Developer use comments to clarify source code. Comments make the program easy to understand. When the program is easy to understand, it becomes easy to debug and maintain the code. There are three types of comments in Java:

1.Single line comment:

Single line comments are used by programmer for small comments. E.g. // comment here

2.Multi line comment:

Multi line comments are used by programmer for large and complicated explanations. E.g. /* comment here */

The documentation comments are used to prepare automatically generated documentation. This is generated with the javadoc tool. E.g.
        /** documentation comment */    
          * This is multiline comment
 public class CommentsDemo

         * this is documentation comments
         * @param args
          public static void main(String[] args)
	      //we will declare all local variables here - single line comment.
	       int i=10;
	       System.out.println("value of i is.."+i);