Java Tokens

 

  Java tokens are smallest individual units in a program

 

 


                                                                          

Keywords: 

        These are the pre-defined reserved words of any programming language.

         Each keyword has a special meaning.

         It is always written in lowercase.

e.g. class, while, for, interface, abstract…..

Identifier:

         Identifiers are used to name a variable, constant, function, class, and array.

         It is usually defined by the user.

        It uses letters, underscores, or a dollar sign as the first character.

        Identifier names must be different from the reserved keywords.

 

There are some rules to declare identifiers are:

     The first letter of an identifier must be a letter, underscore or a dollar sign. It cannot start with digits but may contain digits.

     The whitespace cannot be included in the identifier.

     Identifiers are case sensitive.

        Some valid identifiers are:

         PhoneNumber  

        PRICE  

        radius  

        a  

        a1  

 Invalid Identifiers

        1sum

        Sum 1

 

Literals: 

        literal is a notation that represents a fixed value (constant) in the source code.

        It can be categorized as an integer literal, string literal, Boolean literal, etc.

        It is defined by the programmer.

        Once it has been defined, it cannot be changed.

Java provides five types of literals are as follows:

      Integer

      Floating Point

      Character

      String

      Boolean

Operators: 

        operators are the special symbol to perform mathematical operations or logical manipulations

        Java provides different types of operators that can be classified according to the functionality they provide.

There are eight types of operators in Java, are as follows:

        Arithmetic Operators

        Assignment Operators

        Relational Operators

        Unary Operators

        Logical Operators

        Ternary Operators

        Bitwise Operators

        Shift Operators


Separators: 

        The separators in Java is also known as punctuators.

         separators in Java, are as follows:

        ; (semicolon)

        , (comma)

        . (dot)

        { } (braces)

        [ ] (bracket)

        ( ) (parenthesis)

 

Comments:

Comments are used to describe the program

         Single Line Comment (// Double Slash)

// This is an example program to add two numbers

// Java program to illustrate the addition of numbers

 

          Multi-line Comment (/*     */)

/*This is an example

 program to

add two numbers */


Constants

      Constants are the fixed values that never change during the execution of a program.

       Various types of constants:

      Integer Constants

         An integer constant is nothing but a value consisting of digits or numbers

         Example : 111, 1234

      Floating point Constants

         constants that contain a decimal point or a fraction value. 

         Example: 223.14, 400.054

      Character Constants

         A character constant contains only a single character enclosed within a single quote (‘ '). 

         Example: ‘A’ , ‘m’, ‘9’

      String Constants

        A string constant contains a sequence of characters enclosed within double quotes (“ “).

         Example: “Welcome”, “Hello”

  


Post a Comment

0 Comments