Introduction

The trouble with the key-words of the Java™ language is that they look like English. We Anglophones think we understand them, but much of the time we don’t. Sometimes the Java meaning is the reverse of the English meaning. Here, in alphabetical order, are a few words that make the most trouble.

abstract

An abstract method has a signature but no body. A class with one or more abstract methods must be declared as an abstract class. There is no connection that I know of between these and abstract painting.

class

A class is a little like the struct of the C language or the record of the Pascal language. However, a class can contain not only numbers and strings and other such data, but also methods. It has nothing to do with social class, classification, or classical music.

extends

In this example:
public class Jjj extends Throwable
{
char initial='S';
}
which class is the superclass of the other? The correct answer is, Throwable is the superclass of Jjj. No fooling. You extend a superclass and you get something less super. That is, extending is the same as subclassing.

Beware. The expressions “inner class,” “member class,” and “local class” are not synonymous with subclass. The inner class and member class are within the curly braces of some other class. The local class is within the curly braces of a method within the curly braces of some other class.

final

Immutable and final have no relation to each other. An immutable object cannot be changed, so it must be replaced by another object. An enclosing-class local variable referred to by an anonymous class or other local class must be final, but the object in that variable need not be immutable. String objects are immutable, but String variables are usually not final, though they can be. Variables containing arrays are sometimes final, but arrays are never immutable.

Just remember that immutable is something that objects are or are not, and final is something that variables are or are not.

import

The word import is a compile-time command to javac to look outward to a package for help in completing names of classes. It is most certainly not a load-time command to java to bring in a whole library. On the contrary, only the needed parts of the package are brought, and the rest are ignored.

interface

An interface is much like an abstract class, but there are some differences. I have no idea what two things an interface is supposed to be between.

null

The null is an improper reference, because it does not refer to anything. If a variable is suitable to refer to an object, but it does not refer to any object, then we (and Java) say the variable contains null. The null is not a zero. Zero is a number, but null is not a number.

static

A static method belongs to a class, not to objects instantiated from that class. A static field ditto. A static method may refer to a static field, but not to a non-static field. For example
public class Aaa
{
static double bbb;
double ccc;

	public static void main( String[] args )
	{
	bbb=1.23; // This is legal.
	ccc=5.6789; // This is not legal.
	}

}
So what about a static class? Let us try:
public class Ddd
{
static class Eee{ double fff=5.432; }
class Ggg{ int hhh=98765; }

	public static void main( String[] args )
	{
	Eee e=new Eee(); // Legal or not?
	Ggg g=new Ggg(); // Legal or not?
	}

}
Which line is not legal? Did you guess that Ggg g=new Ggg(); was not legal? Good for you. I got it wrong when first I tried it. Eee e=new Eee(); is legal. The reasoning is the same as above.

synchronized

If a program has two or more threads, they may be running selfishly and not cooperating with one other. They are said to be unsynchronized. The synchronized keyword is used to force each to wait politely for its turn to use a resource.

For more on this word, study the java.util.Hashtable<K,V> and java.util.HashMap<K,V> classes. The former has some synchronized methods, so it is the one to use in multi-threaded programs.

License, revision date, and e-mail address

The present file is in the public domain. (Java™ is of course the property of Sun.) The date of this revision is 3 July 2007. Comments both constructive and destructive come to me, Harold Kaplan,
       at        dot
smtw2gh  toadmail   com
For other links to Harold Kaplan’s programs, click on programming.htm.