Names

What is the difference between an identifier and a name? An identifier is just a sequence of letters and digits that don't match a keyword or the literals “true,” “false,” or “null.” A name, on the other hand, can be prefixed with any number of further identifiers to pin-point the namespace from which it comes. An identifier is thus the simplest form of name. The general case of name looks like the following:

package1.Package2.PackageN.Class1.NestedClass2.NestedClassM.memberN

Since packages can be nested in packages, and classes nested in classes, there can be an arbitrary number of identifiers separated by periods, as in:

java.lang.System.out.println( "goober" );

That name refers to the java.lang package. There are several packages in the java hierarchy, and java.lang is the one that contains basic language support. One of the classes in the java.lang package is System. The class System contains a field that is an object of the PrintStream class, called out. PrintStream supports several methods, including one called println() that takes a String as an argument. It's a way to get text sent to the standard output of a program.

By looking at a lengthy name in isolation, you can't tell where the package identifiers stop and the class and member identifiers start. You have to do the same kind of evaluation that the compiler does. Since the namespaces are hierarchical, if you have two identifiers that are the same, you can say which you mean by providing another level of name. This is called qualifying the name. For example, if you define your own class called BitSet, and you also want to reference the class of the same name that is in the java.util package, you can distinguish them like this:

          BitSet myBS = new BitSet();
java.util.BitSet theirBS = new java.util.BitSet();

java.util qualifies the class name BitSet.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.157