Java Keywords
Avoid the boolean values (tokens) true and false in program names.
Do not use the following as names in your programs, as they are reserved keywords in Java (please scroll down):
| Keyword | Details |
|---|---|
| abstract | An abstract class does not have its own instances, but provide variables and methods that subclasses can inherit. |
| boolean | Boolean literals can only take the values true and false (not even null). Boolean variables are of type Boolean and so can only take the values true or false. |
| break | A break statement is to break out of loops and switch statements. |
| byte | byte is a data type consisting of an 8 bit two's complement integer with values between -128 and 127. |
| byvalue | * |
| case | See switch. |
| cast | * A cast operator is a unary operator converts the value of its operand to the type named within its brackets, for example: a + ((int(b/c) + d. |
| catch | A guarding statement, used to set up exception handling around a method that might generate an exception. It has an exception handler object as an argument. |
| char | float is a data type consisting of a 16 bit Unicode character. For alphanumerics, these are the same as ASCII with the high byte set to 0. |
| class | A class consists of an object's variables and methods. |
| const | * |
| continue | A continue appears within an iteration block (do, for or while) and is used to skip the rest of the current iteration. |
| default | See switch. |
| do | A do statement, which has a while clause at the end, executes its statements at least once before evaluating the while. For example: |
| double | float is a data type consisting of 32 bit single precision floating point number. |
| else | Part of the if statement. If (something) then (instructions) else (alternative instructions); |
| extends | Makes one class a subclass of another, for example class subclass extends superclass. |
| final | The final modifier prevents the definition of a subclass, making variables constant and preventing a subclass from overriding a method. |
| finally | A guarding statement, used to set up exception handling around a method that might generate an exception. It permits wrapping up, e.g. by closing files, before excecution is halted. |
| float | float is a data type consisting of 64 bit double precision floating point number. |
| for | A kind of iteration statement that starts with an initialising clause, and performs a block of code as often as required while incrementing variable(s) and testing expressions to see if it is time to stop. For example, the following code prints out the day number and hour for each hour in a week: |
| future | * |
| generic | * |
| goto | * |
| if | The simple if statement tests a Boolean variable or expression, and executes code if it is true. For example:
|
| implements | Part of a Java class declaration. A class implements an interface. |
| import | To use classes from packages other than java.lang, use an import statement for each one that you need. You can then refer to such a class by its class name. Otherwise you would need to specify the full path to each class each time you referred to it |
| inner | * |
| instanceof | This is a binary operator which takes 2 operands; an object on the left and a clss name on the right. It returns Boolean true if the object on the left is an instance of the class on the right or any of its subclasses, otherwise it returns false. For example:
if (your_answer instanceof ValidAnswers) System.out.println("You get a point!"); |
| int | int is a data type consisting of a 32 bit two's complement integer with values between -2,147,483,648 and 2,147,483,647. |
| interface | An interface is a collection of methods and variables that other classes can implement. A class implementing an interface provides the implementation for all of the methods in the interface. |
| long | long is a data type consisting of a 64 bit two's complement integer with a huge range of values. |
| native | Native methods are declared in Java, but implemented in another language. They generally do something the Java API does not, for instance interface with hardware. They are not portable, so applets cannot use them. |
| new | The new operator is used to create a new instance of a class, for example:birthday = new date() |
| null | Null represents a condition where there is no value. Booleans cannot be null. |
| operator | * |
| outer | * |
| package | The package keyword assigns the contents of a file to a package. It is used to group classes. |
| private | This is an access control modifier that limits access to within the class itself. |
| protected | This is an access control modifier that limits access to a class, the package and its subclasses, although a subclass cannot use its superclasse's protected variables. |
| public | This is an access control modifier that allows any class to access a variable or method. |
| rest | * |
| return | A return statement in a method, constructor or static initialiser returns control to whatever called it. If a method's return statement is not declared as void, it may have a parameter of the same type as the method. |
| short | short is a data type consisting of a 16 bit two's complement integer with values between -32,768 and 32,767. |
| static | Indicates tht a variable is a class variable that is allocated once per class, so if one changes, it changes for every instance of the class. |
| super | Refer's to a class's immediate superclass. |
| switch | A switch statement passes control to one of several statemnt blocks depending on the value of an expression. For example:
|
| synchronized | Prevents more than one thread from executing inside a method at once. |
| this | Refers to the current class. |
| throw | A throw statement causes execution to be suspended. It signals a run-time exception. Its argument is an object. |
| throws | A method throws an exception, for example: |
| transient | |
| try | A guarding statement, used to set up exception handling around a method that might generate an exception. It is like a switch statement with a block of code instead of an integer parameter. |
| var | * |
| void | A return type meaning that no information is returned by a method, for example:
static void toggleLight() {
lightOn = !lightOn;
}
|
| volatile | |
| while | A while statement tests a Boolean variable or expression, executing its statement block repeatedly until the variable or expression is false, when control is passed to the next statement after the statement block. The while statement's statement block may not be executed at all, if the Boolean variable or expression is false at the outset. For example: |
* not used in Java 1.0, but still reserved and should not be used:
