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

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

3 minutes ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

2 days ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

3 weeks ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

1 month ago

Select a Random Element from a Stream

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

1 month ago

Estimate π Using Monte Carlo Method

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

2 months ago