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.
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
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.
-> 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
|break|| double ||implements||protected|| throw
| byte||else||import ||public||throws
|char||final || interface||static||void
|const ||float ||native||super||while
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.
E.g. int i = 10;
Here 10 is a integer literal.
E.g. float f = 10.6f;
Here 10.6f is a floating point literal
E.g. char ch = 'a';
Here a is a character literal
E.g. String s = "Hello World";
Here Hello World is a string 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:
Single line comments are used by programmer for small comments.
E.g. // comment here
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.
/** 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.
System.out.println("value of i is.."+i);