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

Popular posts from this blog

Decision Making and Branching Statements / Control Statements

 Introduction     Java is a set of statements which executed sequentially in the order in which they appear. This will happen when option or repetitions of certains are not necessary. However, We have a number of situation, where we may have to change the order of execution of statement on bases of certain conditions. This involves a kind of dicision making to see the particular condition occured or not and the direction of execution will execute according to it.     When program braks the sequential flow and jump on the another part of code then it's called branching . When branching is on particular condition then it's called conditional branching . If branches executes without any particular conditions then it's call unconditional branching .     Java supports such decision making capabilities and supports following statements known as Control statement or Decision making statement .     if statements     switch statement   ...

Static and this keyword

Static Keyword:      Most of the time static keyword in java use for memory management. We can use static keyword with variables, methods and also with block (Static block) . 1. Static with variables:     If we declare static keyword with variables then it's called static variables . Static variables are use to access or refer common properties of all objects. The static varibels gets memory only once at the time of loading class loading. It makes program more efficient i.e., It saves memory. For example,     static int length=100; 2. Static with method:     If we use static keyword with method then it's called static method . The static method is belong to class rather than object of class. Static method can invoke or call without creating instance or object of class. For example,     static void print(){          System.out.println("Welcome in Java");     } Examples of static variable, method an...

Jump Statements in java

    Introductions       Loopes perform a set of operations repeatedly until the control variable fails to satisfy the test condition. But in some times we need to skip some of the part of loop then we use the jump statements . For breaking the loop we use continue and break statement . Continue Statement:     When the continue statement called, it will break or stop the current itteration of loop on sameline and start the new iteration. Format of this statement is below:          continue; Brak Statement: After call this statement in the body of loop, it will sop or break the loop on current loop on same line and control goes to the next line after that loop. Format is below:     break; We mostly use this statement in while, do, and for loop concept.