Which And What Utilities
This essay does not describe an existing computer program, just one that should exist. This essay is about a suggested student project in
Java programming. This essay gives a rough overview of how it might work. I have no source, object, specifications, file layouts or anything
else useful to implementing this project. Everything I have prepared to help you is right here.
This project outline is not like the artificial, tidy little problems you are spoon-fed in school, when all the facts you need are included, nothing extraneous is mentioned, the answer is
fully specified, along with hints to nudge you toward a single expected canonical solution. This project is much more like the real world of messy problems where it is up to you to fully the
define the end point, or a series of ever more difficult versions of this project and research the information yourself to solve them.
Everything I have to say to help you with this project is written below. I am not prepared to help you implement it; or give you any additional materials. I have too many
other projects of my own.
Though I am a programmer by profession, I don’t do people’s homework for them. That just robs them of an education.
You have my full permission to implement this project in any way you please and to keep all the profits from your endeavour.
Please do not email me about this project without reading the disclaimer above.
This is similar to the PathTool project. These are some simple command line diagnostic
Your what utility might be expanded to tell you interesting facts about other types
of file. Eg.
- which p.exe This searches the current path for the given
executable file (fully qualified). It then displays all the occurences it finds, i.e.
the fully qualified directories where it found that file and sets the return code to
the number of instances it finds.
- which X.Y.P.class does the same thing, but search the
classpath, including any jars in the classpath for instances of X.Y.P.class. You can
use simple wildcards such as *.P.class to look for the class in any package. *.*.class
would get you a list of all classes available on the classpath. The search is case
insensistive, but since Java is case-sensitive, only case-sensitive matches appear in
the count. Case mismatches are highlighted.
- which getSize.method does the same thing, but search the
classpath, including any jars in the classpath for instances of classes containing a
getSize method. More elaborate versions would let you specify a more specific method
signature. The utility should take a -cp option on the
command line, defaulting to the SET classpath if there is none.
- what C:\temp\ThisFile.class Displays the fully qualified
classname of the class corresponding to the file.
- what C:\temp\ThisJar.jar Displays the fully qualified
classnames of all the classes in the jar.
Ideally this is runs on any platform unmodified, though if you find yourself needing
JNI (Java Native Interface), try at least to support both Windows and Linux, using
JWS (Java Web Start) to select the correct native class.
- exe : what OS/memory model is it for. Look for file
signatures for various Windows, Linux, etc executable file formats. You can look for
bytes without needing platform-specific code.
- txt: word and line count.
- doc: which version of MS Word created it.
- You can get the current classpath with: System.getProperty(java.class.path)
- In Windows, you get get the path with System.getenv(
- ClassLoader.findResource may