Java Programming

Tokens in Java (Keywords, Identifiers, Literals)

Well, we all know that a program is a collection of statements which are combined together. Similarly, the tokens are the collection of predefined meaning given to any word or any special symbol (eg- “+”). In this post, I will try to explain the use of tokens or the importance of tokens in Java programming.

JAVA TOKENS

The concept of Java Tokens

Java Tokens are the predefined terms or the smallest individual unit which are used to build a program. In simple words, tokens are the words or the symbols whose meanings are predefined in Java libraries. We only need to call it in our program by just using its name or symbol. The compiler identifies these token easily because their meanings are predefined in the compiler. These tokens are defined using Unicode characters. Learn – What is Unicode?

For example-

int number; – Here compiler automatically identifies that the int is the keyword and number is the variable here.

There are basically 5 types of tokens are available in Java programming-

  1. Keywords
  2. Identifiers
  3. Literals
  4. Operators
  5. Separators

Keywords

Keywords are the special reserved words having its own meanings which are predefined. It conveys special meaning to the compiler.

In simple words,

Keywords = Special Words with some meaning or function.

In Java programming, there are total 50 words are reserved as the keywords. We cannot use these keywords as a variable, classes, etc because they have their own definitions. Keywords are case-sensitive i.e., all the letters in any keyword must be in small alphabets. Please clear your concept – Difference Between Keywords and Identifiers.

Here’s the list of all 50 keywords available in Java,

Void throw Super
return package interface
implements float enum
char break default
try this structfp
public new int
if finally else
continue catch boolean
while transient synchronized
static protected native
instanceof goto final
double const case
assert volatile throws
switch short private
long import for
extends do class
byte abstract  

Identifiers

Identifiers refer to the naming of various programming elements such as classes, methods, variables, etc. It is used to give the unique identity to any element in the program so that one can again call these elements or identifies these elements by its name directly

There are certain rules which we need to follow to make an identifier. Java programming language has the following rules-

  1. Identifiers are case sensitive i.e., we must have to follow uppercase as well as lower case alphabets.
  2. Identifiers may be alphabets, underscore, digits & the dollar sign.
  3. They must not start with any digit. For example – 1num ( Incorrect ).
  4. There are no any limitations on the length of the identifier.

Literals

Literals are the representation of constants values assign to an integer, boolean, characters, etc whose values can’t change during the execution of the program. There are basically 5 types of literals present in Java programming language,

  • Integer Literals
  • Floating Point Literals
  • Character Literals
  • String Literals
  • Boolean Literals

For more clarification, please refer – Literals in Java

Operators

Operators in Java refers to the special symbols with some predefined meaning or functions. These specials symbols are generally used for performing operations in the program. The operation may be arithmetic or logic based on the condition.

In Java, Operators are classified into 8 categories-

  1. Arithmetic Operators ( eg.- + , – , * , / , % )
  2. Relational Operators ( eg.- < , > , <=, != )
  3. Logical Operators ( eg.- && , || , ! )
  4. Assignment Operators ( eg.- = )
  5. Increment/Decrement Operators ( eg.- ++ , — )
  6. Conditional Operator ( eg.- ?: )
  7. Bitwise Operator ( eg.- >> , << , ^ )
  8. Special Operators ( eg. – dot operator )

Seperators

Seperators are the symbols which are used to divide or arrange the code. These are predefined symbols which generally used to give the shape of our function or the program.

There are various types of separator available in Java,

  • Parenthesis() – Generally used to add parameters in the functions.
  • Braces{} – Generally used to define the classes or functions and also used to initialize the arrays.
  • Brackets[] – Generally used for indexing of an array.
  • Comma “,” – It is used to separate different elements in the program such as identifiers,
  • Semicolon “;” – It is used to end any statement in the program.

 

ALSO READ

 

Leave a Reply