The Java programming language reserves certain identifier names for use as keywords. Any attempt by you to use a reserved keyword as an identifier will result in a compiler error. The reserved keywords, along with brief descriptions, are presented in table 6-2. Do not try to learn them by heart just yet. You will recognize several from their use in the source code examples presented in the text thus far and you will gradually be exposed to the others as you progress through the book.
Reserved Keyword | Description |
---|---|
abstract | Used to declare a class or method that is not completely defined. |
assert | Allows you to test assumptions about how your code should behave. |
boolean | Primitive Java data type representing true and false values. |
break | Used to exit a containing code block. Can be used with named blocks. |
case | Tests a value to select a possible execution path in a switch statement. |
catch | Used in conjunction with the try keyword to trap exceptions thrown from a try/catch block. |
char | Primitive Java data type representing 16-bit characters. |
class | Used to declare a new class type. |
const | Reserved, but not currently used in the language. |
continue | Used inside iteration statements for, while, and do to quit the current iteration and start a new one. |
default | Denotes the default case in a switch statement. |
do | Iteration statement that executes a code block at least once. |
double | Primitive Java data type denoting 8-byte floating point numeric values. |
else | Used in conjunction with the if statement to specify an alternative execution path. |
enum | Used to declare enumerated types in Java 5 |
extends | Used in a class declaration to specify a base class from which to inherit functionality or behavior. |
final | Used to declare Java variables that cannot be changed (constants) and in method and class declarations to prevent overriding and subclassing. |
finally | Used in conjunction with try/catch blocks to specify a block of code that must always be executed when an exception is thrown. |
float | Primitive Java data type denoting 4-byte floating point numeric values. |
for | Iteration statement used to execute a block of code a specified or indefinite number of times. |
goto | Reserved, but not currently used in the language. |
if | Allows conditional execution of a block of code based on the evaluation of an expression. Can contain an else clause that provides an alternative execution path. |
implements | Used in class declarations to specify what interfaces the class adopts. |
import | Used to provide abbreviated name access to classes contained in packages. |
instanceof | A Java operator used to test the types of objects. |
int | Primitive Java data type denoting 32-bit integer values. |
interface | Used to declare an interface type. |
long | Primitive Java data type denoting 64-bit integer values. |
native | Used to declare methods that will have an implementation in a language other than Java. |
new | Used to allocate memory for objects during program execution. |
package | Used to specify what package name a class belongs too. |
private | Visibility modifier. Used to specify class, member, or attribute visibility. |
protected | Visibility modifier. Used to specify class, member, or attribute visibility. |
public | Visibility modifier. Used to specify class, member, or attribute visibility. |
return | Used to return a value from a method. |
short | Primitive Java data type denoting 16-bit integer values. |
static | Used to declare class-wide methods or attributes. |
strictfp | Rarely used modifier. Used to specify that all floating point computation performed by a method must conform to the IEEE 754 standard. |
super | Used to gain access to a class’s immediate base class. Used in three ways: 1) to call base class constructors from derived class constructors, 2) to call a base class method vs. it’s overridden method, and 3) to access a base class attribute that’s hidden by a subclass attribute of the same name. |
switch | A flow control statement used to provide several alternative execution paths. Used with the case and default keywords. Used in place of multiple nested if/else statements where appropriate. |
synchronized | Used as a statement and modifier. Specifies that code belonging to an object, array, class, or method must be treated as a critical section and not accessed simultaneously by different threads. |
this | Used to explicitly indicate same-class field and method access. |
throw | Used to explicitly raise an exception condition. |
throws | Used in a method definition to specify what, if any, exceptions may result from its execution. |
transient | A field modifier that specifies a field is not part of the persistent state of an object and therefore should not be serialzied. |
try | Introduces a block of code that, when executed, may result in a checked-exception being thrown. Used in conjunction with the catch and finally keywords. |
void | Used to specify that a method does not return a value. |
volatile | Field modifier that specifies the field may be accessed by unsynchronized threads. |
while | Iteration statement that will evaluate an expression prior to executing a code block. The expression may evaluate to false which would result in the code block not being executed. |
true, false, null | These are not reserved keywords but can be though of as such. |