Java Tokens

See below java hello world program and notice all the words, characters, symbols used in the program. It’s very important to know why all these characters used in program, what are their meanings and what we call them. Let’s see simple program.

Java Tokens

Java Hello Word program

Now look above code, we have used words like class, static, void, out, Hello, HelloWord etc. and symbols like {, " ", ; etc. do you know what these words and symbols are called. If you closely observe, you will that the whole program is collection of words, characters, symbols and these are called as tokens.

Output

Java Tokens

Java tokens are the smallest units of program. When we write a java program, we use words, symbol, numbers etc. all these things are called as java tokens. Java tokens are divided in 3 categories.

  1. Keywords
  2. Identifiers
  3. Literals

Keywords

In java programing there are some pre-defined words which have pre-defined meanings and functionality, these pre-defined words are called as keywords. There are around 50 keywords are in java. For example – class, public, static, void etc. Below we have listed all keyword used in java.

Note: keywords must be written in lowercase while using them in programs.

IMP: Java is case-sensitive programming language for example Class is different than class.

abstract assert boolean
break byte case
catch char class
const continue default
do double else
enum extends final
finally float for
goto if implements
import instanceof int
interface long native
new package private
protected public return
short static strictfp
super switch synchronized
this throw throws
transient try void
volatile while

Meanings and behaver’s of all above listed keywords are pre-defined in java class library functions. Latter we will learn in deep all about those java class library functions, we also call them java packages.

Identifiers

Programmer defined words in a program are called as Identifiers, for example names of class, variable, package, interface etc.

Rules

  • An identifier can be alphanumeric, only &, $ and _ are allowed in special characters.
  • An identifier can be stats from a alphabets or from allowed special characters (&,$,_).
  • An identifier cannot be start from a number.
  • Space is not allowed in identifier.
  • A keyword cannot be used as an identifier.
  • It is good practice to write first letter of identifier in uppercase but it is not mandatory.

Literals

Literals are value used in programs. In java programing there are 4 types of literals which are listed below.

  1. Numeric Literals
  2. Character Literals
  3. String Literals
  4. Boolean Literals

Numeric Literals

A number used in java programming called as numeric literal for example 2, 7, 22, 33.6 etc.

Character Literals

Any single character of keyboard enclosed within single quote is called as character literal, for example ‘M’, ‘7’,’a’,’3’ etc.

String Literals

Single or group of characters enclosed within double quote is called as string literal or in other words anything which is enclosed within double quotes are called as string literals. For example “Hello”, “world237”, “year 2050”, “ I am good my age is 19” etc.

Boolean Literals

In java programming there are two Boolean literals that are true and false. Boolean literals are used to take decision. Boolean literals are also called as reserved words.

  • True is used for correct decision
  • False is used for wrong decision

Java Class Libraries

When we install JDK in our computer along that so many class libraries are get installed. In these classes program supporting codes are pre-written. For example in program the line

System.out.println(“Hello”);

It gives us Hello as output so now question is how it working, how it get knows that it have to print what ever written in “ ”.

When we install JDK there is a class which name is System is also get installed with other class libraries. In this System class there are two pre-defined methods println() and print(), these two methods are responsible to print output in java. So in this way classes are very useful in java program. A class can contain another class, methods etc.

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)