![]() |
Java Project
J040603 |
|
We establish that the interface definition can be compiled easily. It is also shown that we have some flexibility in the naming of the files so that different expressions of the interface definition don't have to employ conflicting file names.
1. Objectives
2. Two Versions
2.1 Num-0.01.java
2.2 Num-0.01a.java
3. Package-Internal Access Confirmed
4. The Num-0.01a.java Num.class File
5. Compilation Environment
The files employed in this experiment are archived in J040603b.zip (WinZip file). File J040603b.txt is the manifest carried in the current archive.
We are going make some leisurely confirmation of Java compiler characteristics. If we succeed in our experiments, these will assist us in working informally with experimental and ALPHA code while anticipating the more rigorous package structure that we intend to end up with.
The objective of this exercise is to confirm that we can compile units of a package without much concern for the package name that we choose. In particular, we would like to use the production package name although we are operating within a single directory and working with user-created compilation units all for the same package.
In addition, we don't want to be locked into a specific source-program name, even though the compiled interface class will always be a Num.class file.
Finally, we want to see how forgiving the compiler will be with respect to Class Path requirements in the early stages of development. We would like to minimize the branching of directory trees, and be able to work with new versions at the same time there is a production version of a package also being used. We do not confirm any of that here; that is done in the next experiments we must undertake.
The ALPHA materials are exploratory, and this area is more of a laboratory than a vehicle for delivering stable software. When ALPHA material is mature enough to be made into a stable release, that release is pulled-together on the main package tree without supplanting any current stable production version of a package.
The file Num-0.01.java holds the version that Bill Anderson created in wanting to understand how the proposed interface was intended to work.
package com.orcmid.cs.pa; public interface Num { public int next(); public int pred(); public boolean is0(); } /* sent by band@acm.org on 2004-05-22-1846 -0700 This version reflects an interesting and very instructive misunderstanding of what I had in mind. $Header: /Java2/com/orcmid/llc/pa/pn/Num.java 1 04-05-23 9:27 Orcmid $ */Because I wanted to give different versions of the file different names so that they could be kept together, if desired, I had changed the name of the file from Num.java. I knew this could work, but I had forgotten how I did it before.
As Java developers can predict, this interface definition is not acceptable to the Java compiler.
[0]C:\java2\projects\com\orcmid\LLC\pa\pn> javac Num-0.01.java Num-0.01.java:3: class Num is public, should be declared in a file named Num.jav a public interface Num ^ 1 error
The only objection is that a public (interface) class must be compiled from a file with the same name. The file Num-0.01a.java is exactly the same as the 0.01 version except that the interface is not declared to be public. Again, the file name is not the same as the name of the interface.
/* Num-0.01a.java Experimentation with compilation options. */ package com.orcmid.cs.pa; interface Num { public int next(); public int pred(); public boolean is0(); } /* sent by band@acm.org on 2004-05-22-1846 -0700 This version reflects an interesting and very instructive misunderstanding of what I had in mind. 2004-09-14-09:52 I corrected the name in a comment. I have not adjusted this file at all. It is just for experimenting with what the compiler assumes. $Header: /Java2/com/orcmid/llc/pa/pn/Num-0.01a.java 2 04-09-14 9:54 Orcmid $ */Making the new file, above, and removing the public access modifier on the interface leads to an acceptable compilation:
[0]C:\java2\projects\com\orcmid\LLC\pa\pn> javac Num-0.01a.java [0]C:\java2\projects\com\orcmid\LLC\pa\pn>The file Num.class is produced without any warnings or error messages.
Notice that the package name (com.orcmid.cs.pa) and the file location where we compiled Num-0.01a.java (... com\orcmid\LLC\pa\pn) are not directly related, and we have encountered no difficulty with that so far.
There are two factors that govern how the use of the package name for our ALPHA development will work:
- When a class (or interface) is not declared public, it is only accessible from within the package in which it is defined [Java2: 6.6.1, 6.6.3, 6.6.4]. That is useful because we don't want these ALPHA definitions to be widely usable, we want them to only be confirmed and tested within their own under-development package.
- When a class (or interface) is not declared public, its name is not required to have any relationship to the name of the file that contains its declaration. The compiler will produce a class file with the correct name, so that it can be found when compiling and executing other units of the same package, and that is sufficient. (Exception: It is permissable for a compiler to require that a class that is referred to from another compilation unit of the same package be in a file of the same name [Java2: 7.6]. This is not a requirement of the compiler implementation that we are using. There will be no difficulty so long as we arrange to explicitly compile the Num.class that we intend to use.)
The second case is more a matter of the compiler design and use of file systems. We are going to take advantage of this tolerance in the Java implementation that we are using. We will also confirm it in an additional experiment.
There is a certain degree of trial-and-error about how a given Java implementation behaves, and how it recognizes and enforces the Java package system.
We are ignoring the impact of any additional requirements that using a package name will impose on using the interface, even from within the package. That is also to be confirmed by experiment.
Inspection of the binary Num.class file produced from Num-0.01a.java reveals how little is retained:
Num.class ¦ F1 Help ¦ Commands: BFGHINPWX ¦ Col 0 Line 1 0%0000 0000 CA FE BA BE 00 00 00 2E 00 0C 07 00 0A 07 00 0B Êþº¾......▫..▫.. 0000 0010 01 00 04 6E 65 78 74 01 00 03 28 29 49 01 00 04 ▫.▫next▫.▫()▫▫.▫ 0000 0020 70 72 65 64 01 00 03 69 73 30 01 00 03 28 29 5A pred▫.▫is0▫.▫()Z 0000 0030 01 00 0A 53 6F 75 72 63 65 46 69 6C 65 01 00 0E ▫..SourceFile▫.▫ 0000 0040 4E 75 6D 2D 30 2E 30 31 61 2E 6A 61 76 61 01 00 Num-0.01a.java▫. 0000 0050 14 63 6F 6D 2F 6F 72 63 6D 69 64 2F 63 73 2F 70 ▫com/orcmid/cs/p 0000 0060 61 2F 4E 75 6D 01 00 10 6A 61 76 61 2F 6C 61 6E a/Num▫.▫java/lan 0000 0070 67 2F 4F 62 6A 65 63 74 06 00 00 01 00 02 00 00 g/Object▫..▫.▫.. 0000 0080 00 00 00 03 04 01 00 03 00 04 00 00 04 01 00 05 ...▫▫▫.▫.▫..▫▫.▫ 0000 0090 00 04 00 00 04 01 00 06 00 07 00 00 00 01 00 08 .▫..▫▫.▫.▫...▫.▫ 0000 00A0 00 00 00 02 00 09 ...▫..
The computer used for this compilation is Compagno, a Dell Inspiron 7000 with Intel Pentium II and Windows XP (Build 2600) SP1
The Java 2 platform used is Java 2 Platform, Standard Edition v 1.4.1 SDK (1.4.1_02) for Microsoft Windows.
The command line interface used is JP Software 4NT Command Processor version 5.00 (Build 101). At the time of the compilation exhibited here, the following settings were in effect:
[0]c:\comando\orcmid> ver 4NT 5.00U Windows XP 5.1 [0]c:\comando\orcmid> path Path=C:\JAVA2\SDK1.4.1.02\BIN;C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\WINDOWS\SYSTEM32 \WBEM;C:\COMANDO\TOOLS [0]c:\comando\orcmid> set CLASSPATH=. COMPUTERNAME=COMPAGNO ComSpec=C:\comando\4NT\4nt.exe HOMEDRIVE=C: HOMEPATH=\Documents and Settings\Dennis E. Hamilton LOGONSERVER=\\COMPAGNO NUMBER_OF_PROCESSORS=1 OS=Windows_NT PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 6 Model 5 Stepping 2, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=0502 PROMPT=[$z]$P$g$s SESSIONNAME=Console USERDOMAIN=COMPAGNO USERNAME=orcmid USERPROFILE=C:\Documents and Settings\Dennis E. Hamilton windir=C:\WINDOWS [0]c:\comando\orcmid>
You are navigating Orcmid's Lair |
created 2004-06-12-14:09
-0700 (pdt) by orcmid |