Java Reserved Words

In languages, some words are reserved to represent some meaning or functionality. In english for example, the word "cat" is reserved to represent a type animal, "dog" is a reserved word to represent a type of animal, "apple" is a reserved word to represent a type of fruit, "eat" is a reserved word to represent a type of action. In English, there a many such reserved keywords, take the dictionary for example it has an entire book of reserved English language keywords.

In the Java programming language there are 53 reserved words to represent some meaning or functionality. In the 53 reserved words, 50 of them are keywords and the other 3 are reserved literals. The difference between keywords and literals is, a keyword is a reserved word that is associated with functionality whereas a reserved literal is a reserved keyword that is only used to represent some value. In the 50 keywords, 48 are used keywords and the other 2 are unused keywords.

Java Reserved Words
KeywordsReserved Literals
Used KeywordsUnused Keywords
Enum keywordReturn type keywordObject related keywordsClass related keywordsException handlingModifiersFlow controlData types
enum(v1.5)voidnewclasstrypublicifbooleanconstfalse
instanceofinterfacecatchprivateelsebytegotonull
superextendsfinallyprotectedswitchchartrue
thisimplementsthrowstaticcasedouble
packagethrowsfinaldefaultfloat
importassert(v1.4)abstractwhileint
synchronizeddolong
nativeforshort
strictfp(v1.2)break
transientcontinue
volatilereturn

Although only 11 modifiers are shown in the table above, there are 12 modifiers in total. The 12th modifier is "default", which is the default modifier when no other modifiers are used.

In Java a method return type is mandatory, hence why the "void" keyword is there. So if a method does not return anything, it should be declared with "void" return type. But in C language, return type is optional, and the default return type is "int".

As for the unused keywords, the usage of goto created several problems in old languages and hence some people banned this keyword in Java. as for "const", use final instead of "const". "goto" and "const" are unused keywords, and if you try to use them, there will be a compile time error.

As for reserved literals, "true" and "false" are values for boolean data type. "null" reserved literals is the default value for object reference.

Enum is used when defining a group of named constants.

import java.lang.*;

enum Month {
    JANUARY,
    FEBRUARY,
    MARCH,
    APRIL,
    MAY,
    JUNE,
    JULY,
    AUGUST,
    SEPTEMBER,
    OCTOBER,
    NOVEMBER,
    DECEMBER;
}

Conclusions