JAVA Reserved Word
A reserved word is a special word reserved either by a programming language or by a program. These are called as reserved words because they cannot be used as variable names. For example, in programming languages such as BASIC and COBOL, the IF word is reserved and has a special meaning attached to it.
As you have just seen in the example given above, reserved words have special meanings. The list of these words is defined when a computer language is developed. Not only this, the reserved words are predefined in the specification of the programming language. Programming constructs such as loops, blocks, conditionals, and branches are also identified by using the reserved words.
The programming language’s specification can also include reserved words that could be used in its future versions. For example, ‘const’ and ‘goto’ are reserved words that have no meaning are not used in the current versions of java. However, these words are intended to be used in the future versions only and therefore cannot be defined as identifiers. In such a case, there is no need to break the older Source code of Java. Not only this, a programmer can’t also redefine the reserved words.
Some programmers can use the term reserved word and keyword interchangeably. However, there is a difference between keywords and reserved word. The keyword is special only in certain cases, a reserved word is always a special word that can’t be used in a variable or a constant name defined by a user.
The Java programming language reserves the programming words. You can’t use these words as programmer-defined identifiers also. The reserved words are the words that are already used by the syntax of the Java programming language.
// you can’t use assert as it’s a reserved word!
class assert
{
public static void main()
{ //any JAVA code you wish to put here …
}
}
This Java code will not compile and will display the following error message:
<identifier> expected
Some of these reserved words are:
| abstract | assert | boolean | break |
| byte | case | catch | char |
| class | const | continue | default |
| do | double | else | enum |
| extends | false | final | finally |
| float | for | goto | if |
| implements | import | instanceof | int |
| interface | long | native | new |
| null | package | private | protected |
| public | return | short | static |
| strictfp | super | switch | synchronized |
| this | throw | throws | transient |
| true | try | void | volatile |
| while |