Categories: Java

Token and keywords

Token

The smallest individual unit in a program is known as a token. In fact, every unit that makes a sentence is a token.

Java has the following token:

  • Keywords
  • Identifiers
  • Literals
  • Punctuators
  • Operators
Keywords

Keywords are the words that convey a special meaning to the language compiler. These are reserved for special purposes and must not be used as normal identifier names.

The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers:

abstractdefaultifprivatethis
booleandoimplementsprotectedthrow
breakdoubleimportpublicthrows
byteelseinstanceofreturntransient
caseextendsintshorttry
catchfinalinterfacestaticvoid
charfinallylongstrictfpvolatile
classfloatnativesuperwhile
constfornewswitch
continuegotopackagesynchronized

The keywords const and goto are reserved, even though they are currently not in use. This may allow a Java compiler to produce better error messages if these Java Keywords incorrectly appear in programs.

While true and false might appear to be keywords, they are technically boolean literals. Similarly, while null might appear to be a keyword, it is technically the null literal. Thus true, false and null are not keywords but reserved words.

Note: also read about the Simple Hello World Program

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

1 day ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

3 weeks ago

Longest Substring with K Distinct Characters

Given an integer k and a string s, write a function to determine the length…

3 weeks ago

Staircase Climbing Ways

There is a staircase with N steps, and you can ascend either 1 step or…

4 weeks ago

Autocomplete System Implementation

Build an autocomplete system that, given a query string s and a set of possible…

4 weeks ago

Job Scheduler Implementation

Design a job scheduler that accepts a function f and an integer n. The scheduler…

4 weeks ago