Software Sue

Link to Simply Sue
Link to Sustainability Sue
location: software/java/keywords Skip navigation : Home  

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):


















KeywordDetails
abstractAn abstract class does not have its own instances, but provide variables and methods that subclasses can inherit.
booleanBoolean 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.
breakA break statement is to break out of loops and switch statements.
bytebyte is a data type consisting of an 8 bit two's complement integer with values between -128 and 127.
byvalue*
caseSee 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.
catchA 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.
charfloat 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.
classA class consists of an object's variables and methods.
const*
continueA continue appears within an iteration block (do, for or while) and is used to skip the rest of the current iteration.
defaultSee switch.
doA do statement, which has a while clause at the end, executes its statements at least once before evaluating the while. For example:
do {
    System.out.println("More!")
   } while (stage.status != "empty");
doublefloat is a data type consisting of 32 bit single precision floating point number.
elsePart of the if statement. If (something) then (instructions) else (alternative instructions);
extendsMakes one class a subclass of another, for example class subclass extends superclass.
finalThe final modifier prevents the definition of a subclass, making variables constant and preventing a subclass from overriding a method.
finallyA 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.
floatfloat is a data type consisting of 64 bit double precision floating point number.
forA 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:
public class TestFor {  

  public static void main(String[] args)
  {
    for (int day=0, hour=0; day <7;){
	if (hour > 23) {
	  System.out.println("Day = " + day + ", hour = " + hour);
	  hour = 0;
	  day++;
	}
	else {	 
	  System.out.println("Day = " + day + ", hour = " + hour);
	  hour++;
	}
    }
  }
}
future*
generic*
goto*
ifThe simple if statement tests a Boolean variable or expression, and executes code if it is true. For example:
if (day = "Sunday") {
	System.out.println("today is a day of rest");
}
implementsPart of a Java class declaration. A class implements an interface.
importTo 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*
instanceofThis 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!");
intint 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.
interfaceAn 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.
longlong is a data type consisting of a 64 bit two's complement integer with a huge range of values.
nativeNative 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.
newThe new operator is used to create a new instance of a class, for example:
birthday = new date()
nullNull represents a condition where there is no value. Booleans cannot be null.
operator*
outer*
packageThe package keyword assigns the contents of a file to a package. It is used to group classes.
privateThis is an access control modifier that limits access to within the class itself.
protectedThis 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.
publicThis is an access control modifier that allows any class to access a variable or method.
rest*
returnA 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.
shortshort is a data type consisting of a 16 bit two's complement integer with values between -32,768 and 32,767.
staticIndicates 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.
superRefer's to a class's immediate superclass.
switchA switch statement passes control to one of several statemnt blocks depending on the value of an expression. For example:
switch (day) {
case 1:
	System.out.println("I hate Mondays");
	break;
case 2:
	System.out.println("Thank goodness Monday is over");
	break;
case 3:
	System.out.println("Half way through the week");
	break;
case 4:
	System.out.println("Only one more day to go");
	break;
case 5:
	System.out.println("Friday at last");
	System.out.println("TGIF!!!!!!!!!!");
	break;
default:
	System.out.println("It's the weekend. :-)");
}
synchronizedPrevents more than one thread from executing inside a method at once.
thisRefers to the current class.
throwA throw statement causes execution to be suspended. It signals a run-time exception. Its argument is an object.
throwsA method throws an exception, for example:
void turnOff()throws java.lang.Exception{
   try {
        computer.switchoff();
       }
   catch (Exception e) {
       // code to deal with the problem
       throw e;
       }
}
transient 
tryA 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*
voidA return type meaning that no information is returned by a method, for example:
static void toggleLight() { lightOn = !lightOn; }
volatile 
whileA 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:
while (today.weekend !=true){
	System.out.println("Get up! You have to go to work!");
}

* not used in Java 1.0, but still reserved and should not be used: