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

Introduction of Java

 What is Java? Java is an object-oriented programming language developed by Sun Microsystem in 1995. It is a combination of C and C++ features with some essential and additional concepts. Java is suited for both standalone and web application development. Java can run on any hardware OR software environment which make it platform independent. Java Example:                                                                                           class Simple{     public static void main(String args[]){          System.out.println("Welcome In Java World");     } } In above example the 'Simple' is a Class name, public is access specifier , Main is a method with argument, St...

Java Package

 Introduction      A java package is a group of similar types of classes, interfaces and sub-packages. Package in java can be categorized in two form, built-in package and user-defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc. Here, we will have the detailed learning of creating and using user-defined packages. Simple example of java package The package keyword is used to create a package in java. //save as Simple.java   package mypack;   public class Simple{    public static void main(String args[]){       System.out.println("Welcome to package");      }   }   How to access package from another package? There are three ways to access the package from outside the package. 1. import package.*; 2. import package.classname; 3. fully qualified name. 1. Using packagename.*      If you use package.* the...

Access Modifiers in Java

 Introduction There are two types of modifiers in Java: access modifiers and non-access modifiers. The access modifiers in Java specifies the accessibility or scope of a field, method, constructor, or class. We can change the access level of fields, constructors, methods, and class by applying the access modifier on it. There are four types of Java access modifiers: 1. Private: The access level of a private modifier is only within the class. It cannot be accessed from outside the class. 2. Default: The access level of a default modifier is only within the package. It cannot be accessed from outside the package. If you do not specify any access level, it will be the default. 3. Protected: The access level of a protected modifier is within the package and outside the package through child class. If you do not make the child class, it cannot be accessed from outside the package. 4. Public: The access level of a public modifier is everywhere. It can be accessed from within the clas...