Monday, March 07, 2005


The keywords in Java are defined in the grammar, and they are:

Keyword =
'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' ;
Keyword Purpose Programming Style
abstract Modifier Object-Oriented Programming
assert Structured Programming
boolean Primitive Type
break Structured Programming
byte Primitive Type
See: switch
Structured Programming
See: try
Structured Programming
char Primitive Type
Object-Oriented Programming
const Reserved Keyword
See: for
Iteration Structured Programming
See: switch
Structured Programming
See: for
Iteration Structured Programming
double Primitive Type
See: if
Structured Programming
extends Object-Oriented Programming
Modifier Object-Oriented Programming
See: try
Structured Programming
float Primitive Type
for Iteration Structured Programming
goto Reserved Keyword
if Structured Programming
implements Object-Oriented Programming
import Modular Programming
instanceof Object-Oriented Programming
int Primitive Type
interface Object-Oriented Programming
long Primitive Type
new Class instance Object-Based Programming
package Modular Programming
private Modifier Object-Oriented Programming
protected Modifier Object-Oriented Programming
public Modifier Object-Oriented Programming
return Procedural Programming
short Primitive Type
static Modifier
super Access Object-Oriented Programming
switch Structured Programming
synchronized Modifier
this Access Object-Oriented Programming
throw Exceptions
throws Exceptions
transient Modifier
try Exceptions Structured Programming
void Procedural Programming
volatile Modifier
See: for
Iteration Structured Programming

Note: The idea of reserving keywords by using bold type comes from Algol 60 (Barron 1977).

Bold type was probably used because reading underlined text is difficult (citation needed).

Most language designers tries to limit the number of keywords in order to make the language simpler and easier to learn. So, language designers reuse keywords in several grammar rules with somewhat similar interpretations in order to make the language look simpler.

Note: "Some languages reserve to themselves words like GOTO that are significant to the syntax. COBOL is the worst offender, having over three hundred words that the programmer must not use for his own purposes." (Barron 1977). See: "Number of keywords: 363"

However, if a keyword is reused in many grammar rules, it will be hard to remember how to use the grammar rules that the keyword is a part of. The grammar rules for the keyword public is harder to learn than byte, and you don't even have to learn about goto or const. The keyword final, can be used in 6 different ways, and goto can't be used at all, because it is used in no grammar rule.

No comments: