Tokens in Java

Token is a smallest unit of java which is very important without token, we cannot write any java program.

Token is classified into 4 types:

  1. Keywords

  2. Identifiers

  3. Separators

  4. Literals


Keywords:

  • Keywords are predefined words

  • Keywords has it's own task

  • They are reserved words

  • We can use keywords, but we can't modify it.

  • Keywords are written in lowercase.

  • They are 50+ keywords. (around 67 )

  • E.g. public, class, static, void, etc.

Identifiers:

  • A name given by a programmer to the components of java

  • E.g. program name, class name, variable name, etc.

  • Rules to follow while writing Identifier:

    1. Identifiers should not start with the numbers; but we can see the number in between the identifier or in the end of the identifier; which is known as alphanumeric.

    2. We cannot use any special character except dollar($) and underscore(_)

    3. Character space is not allowed in identifier

    4. We cannot write keyword as an identifier

💡
If any of the above rule is not followed by a programmer then it will bear compiler time error.

Separators:

Separators are used to separate the set of instruction. E.g. {}, [], (), :, ;

Literals:

  • Literals are the value/ data which we use in java program to perform a task

  • Literals are classified into

    1. Primitive Literal

    2. Non- Primitive Literal

  1. Primitive Literal:

    The primitive literal is classified into following types

    e.g.

    1. Number Value:

      Integer e.g. 100, 5008

      Float e.g. 10.55, 12.9, 15.3

    2. Character Value:

      Anything which is enclosed in a single quote

      e.g. 'c', '1', 't', '@'

    3. Boolean Value:

      It is used for condition making.

  2. Non - Primitive Literal:

    The address or reference of an object is known as non-primitive literal/ non-primitive value.

    e.g. String

    Any value which is enclosed in a double quotes

    Doesn't have a size limit.