Skip to main content

Java Tokens

 Java Tokens


    A java programes is basically a collection of classes. A class is defined by a set of declaration statements and methods containing executable statements. Most statements contain expression which describe the actions carried out on data. Smallest individual units in a program are know as token. The compiler recognizes them for building up expressions and statements.

    In a simple terms, a java program is a collection of tokens, comments and white spaces. Java language includes five type of token.
  •     Reserved Keyword
  •     Identifiers
  •     Literals
  •     Operators
  •     Separators

Reserved Keyword:

    Keywords are an essential part of language definition. Keywords are the words whis defination is already known to java. They implements specific featues of language. Java has 50 reserved keyword.


 These keywords, combined with operators and separators according to syntax, from definiton of java language. These keywords have some specific meaning in java, we can not use as names for variables, method, classes and so on. All keywords should be written in lower-case letters.

Identifiers:

    Identifiers are programmer-design tokens. They are use for naming classes, methods, variabels, objects, labels, package and interfaces in program. Java identifiers should follow some rule those are:

  •     They can have alphabets, digits, underscore and dollar sign charactors.
  •     They must not being with a digit.
  •     Uppercase and lowercase letters are distinct.
  •     They can be of any length.
    Name of all public methods and instance variables start with a leading lowerclass letter. 
For example, 
        average
        sum
    When more than one words are used in name, the second and subsequent words are marked with a leading uppercase letters. 
For example,
    dayTemperature
    totalMark
    It should be rememnered that all these are conventions and not rules.

Literals:
    Literals in java are subsequence characters that represent constant value to be store in variables. Java specifies five major types of literals. They are as folloes:
  •     Integer literals
  •     Floating_point literals
  •     Character literals
  •     String literals
  •     Boolean literals
    Each of theam has a type associate with it. The type describe how the value behave and how they are store. 

Operators:
    An operator is a symbol that takes one or more arguments and operators on them to produce result. (We will discuss this topic in a next section with details)

Separators:
    Separators are symbols use to indicate where group of code are divided and arranged.


Comments