Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/

Books, Tools, FAQ, Links, etc.

Java Programming, Lecture Notes # 6, Typo corrected on 05/26/98. Note: These links are hopelessly out of date. A new set of links can be reached from the opening page of my tutorials.

Sun released the "final" version of their JDK 1.1 around February 18, 1997 and then released JDK 1.1.1 in late March. There were significant changes incorporated in the new version relative to the prior JDK 1.0.2 version. During the next few months, we should see a lot of activity from folks trying to get their products updated to comply with the new specification. The material in this document has not been updated to assure compliance with the release of JDK 1.1.

With the possible exception of the heyday of the IBM PC in the early 80's, this is the most exciting time in the entire history of the computer. (I can say that, because I have been involved during about ninety-eight percent of the commercial history of the computer.)

Much of that excitement centers around the Java technology (and the internet) which is advancing at an incredible rate.

The purpose of this document is to provide a place to record interesting developments until I determine whether to include them, and if so, how to include them into my Java teaching curriculum.

The page will be changing constantly, so you might want to visit it often and check the latest revision date in the header at the top of the page.

One of the areas of the most rapid technological change is in the area of development tools. Every day when I visit my favorite Java sites on the Web, I learn of new developments in this area. Some of those developments which are particularly interesting will be described here. No matter what other tools you decide to download or purchase, you will certainly want to maintain a set of the free tools from Sun Microsystems known as the Java Development Kit (JDK). Be sure to visit http://java.sun.com/ frequently to download a copy of the latest version of Sun's toolkit. While you are there, take a look at some of their other material which includes tutorials, white papers, etc. There is a virtual wealth of Java material at the Sun site. Only the folks at Asymetrix know where this product is really going. This is a powerful rapid development tool which uses drag and drop technology in the Visual Basic, Visual Cafe, Delphi, Optima++ style, but it has several surprises in store for the first-time user.

Among its features is the ability to produce executable files which will execute under Windows 95 without the need for a separate browser or interpreter. What does this mean? Is this a new direction for Java? Only time will tell. It does make it possible to take advantage of the Java programming language for the development of applications, apparently without the speed penalties normally associated with the Java interpreter.

Also apparently included is a feature to modify the source code for an executing applet and see the result of those modifications in the output without recompiling and restarting the applet. This feature is described in one of the demos that come with the product but this instructor hasn't yet taken the time to test it.

As of 11/30/96, the evaluation version available for download is missing some features, but the features that are included make it well worth the time to download it from Asymetrix http://www.asymetrix.com/ and to give it a try. (Update: In February of 1997, I was notified via e-mail from someone at Asymetrix that the product has been released, a 15-day trial evaluation is available, and the price is around $99.)

With this development software, you should be prepared to consume a lot of disk space every time you develop a new project, but after the project is fully developed, you can recover much of that disk space through judicious file deletions. Also be prepared to download a large file.

This Java development product is a "must see" for every serious Java programmer.

PowerSoft Jato

Here is another "must see, must try" product. Previously codenamed Starbuck, Powersoft put their Jato product up for downloading during February 1997. This product features a powerful drag and drop interface builder that is tailored after their very successful C++ product named Optima++.

Don't know how long it will be available, but as of February 20, you can download an evaluation copy at http://www.powersoft.com/.

According to IBM, the alphaWorks online laboratory at http://www.alphaWorks.ibm.com/ provides free access to developing Internet technologies. In addition, again according to IBM, you will find in-depth articles and interviews from internet leaders, programmers, and researchers, as well as glimpses into IBM's ongoing projects.

As of this writing on 11/30/96, there are several experimental Java development tools available there. Keep in mind that these tools are experimental in nature, but they may be an indication of what is to come in the future. This is another site that the serious Java programmer should visit often.

According to IBM, "with minimal programming knowledge and the Component Assembly Tool (C.A.T.) for Java, you can create Java-based interactive web "components", without writing a single line of Java code."

This is indeed a powerful development environment. The problem, as of 11/30/96, is that if you make a mistake, you will end up with bad source code and ordinary compilation errors which you must fix. Unless you understand how to program in Java, it is unlikely that you will be able to fix the problems. If you already know how to program in Java, this product may be a good vehicle to eliminate some of the tedious programming effort involving the Graphical User Interface (GUI).

This situation regarding the requirement to cope with ordinary compiler errors may improve with time and we may see in this product the beginnings of a line of programming tools which truly don't require any knowledge of programming.

According to IBM you can "Produce Java applications and applets in your Windows 3.1 environment and run them over any hardware platform or operating system."

This is a very interesting product. As of 11/30/96, all other Java development products known to this author require a 32-bit system such as Windows 95. If you are using Windows 3.1, you should definitely check this one out, but be prepared to need about 16 megs of RAM in order to run it successfully.

Update: February 20, 1997. Several recent posts in the newsgroups have indicated that this experimental product has been significantly improved during the past several months. Since I no longer have ready access to anything running Windows 3.1, however, I haven't been able to follow up on those reports.

This is another rapid development tool which uses drag and drop technology to make it easier to develop the graphical user interfaces which computer users have come to expect. This is another heavyweight development tool which every serious Java programmer should evaluate. As of 11/30/96, an evaluation copy is available for download from Symantec at http://cafe.symantec.com/.

Update: February 20, 1997. The website no longer indicates that evaluation copies can be downloaded, at least not that I could find. However, the volume of discussion in the newsgroups would suggest that this product and its sister product named Symantec Cafe probably hold the top spot in terms of large-scale development systems actually being used by programmers doing real work, with Microsoft's J++ running a close second. (Or it maybe its the other way around.)

Microsoft Visual J++

February 20, 1997: Unquestionably a heavy-hitter, Microsoft is making a strong play to dominate the market, including "Publisher's Editions" of the software on CD-ROMS in the back of books.

I never managed to get my hands on an evaluation copy, so I don't know much about it. However, from what I gather from various discussions, this product apparently doesn't have the rapid development drag and drop interface that Microsoft pioneered in their Visual Basic product, and that many other companies such as Symantec, Powersoft, and Borland have successfully emulated. If I am incorrect on this, please send me an e-mail so that I can make a correction.

What Is Borland Doing

February 20, 1997. I'm really not sure. About a year ago, they tacked a Java capability onto their Version 5.0 C++ for Windows product. I have a copy of that product, love the C++ part, and never use the Java part. I was never able to get the debugger to work properly, and didn't get any information that was helpful from their technical support people. Aside from the fact that it has a nice editor, the Java portion of the product doesn't offer much of substance that I can determine.

I believe that was a stopgap measure anyway because since then I have heard a little about Borland's J-builder being on the way along with something called Borland Latte. However, there is virtually no discussion of Borland in the Java newsgroups which would indicate that they haven't made the market yet.

But don't count them out. They have a strong C++ product line, and their Delphi product is reasonably well accepted, and they have the potential for catching up in the Java world in a hurry. The are demonstrating their C++ Builder product now which is a rapid development Drag and Drop product similar to their Delphi product. A similar Java product may not be far behind.

November 1996: Jade is a simple but interesting development tool which is currently available at a variety of general download sites. This product integrates into the Sun JDK and provides a Windows-style interface to the Sun Java development programs. There is nothing fancy about this tool, but for development and simple compilation of applications and applets, it makes the Sun tools easier to use than with the command-line environment.

The tool is small, and definitely worth the download time.

One problem as of 11/30/96 is that if you execute an application, the DOS box disappears from the screen as soon as the application terminates. You need to put something at the end of the application to cause it to pause so that you can see what is on the screen.

November 1997: JavaMaker is similar to Jade, but seems to be limited to applets only. Also, as of 11/30/96, it seems to have some bugs. Although it is small, unless it is improved, it isn't worth the download time.November 1996: Evaluation copies of JPad and JPadPro are available on a variety of general download sites or at the vendor's site: http://www.sni.net/express/. You can download them and determine if they are worth the asking price. Two versions are available: JPad and JPad Pro. The Pro version claims to have several nice features not included in JPad. Note however that as of 11/30/96, although the evaluation copy of JPadPro claims to be fully functional, an evaluation copy downloaded from the vendor's home page did not include some of the features listed below. Apparently the evaluation copy is purposely crippled at this time.

Despite the above, even with some of the features crippled, even the less-expensive JPad provides a very useful programming environment

Jpad and JPad Pro provide a Windows-style interface to the Sun software and do so very effectively. Between them, they have a number of interesting features including:

This product is definitely worth the time required to download and evaluate it.

Vibe

Another popular development tool is the product named Vibe. As of February 1997, a beta or evaluation copy of this product was available for downloading at http://www.visix.com/. According to the material on their website,As of February 1997, this author has no experience with this product.

Chickory

According to information on the website,As of February 1997, a copy of Chickory can be downloaded at http://www.cerc.wvu.edu/chicory/. This author has no experience with this product as of this time.Update: February 1997. There are at least three sites which support compilation of Java programs on line:In other words, you can submit your source code to these sites and have it compiled there (the first of the three apparently isn't intended to be open to the public).

Although this capability doesn't seem to be of too much interest as of 11/30/96, it could become very interesting as soon as Netscape starts delivering a Java-aware version of Netscape Navigator which will run under Windows 3.1. An early release version of such a program is already available to Netscape "DevEdge" development partners.

The combination of on-line compilation and execution under Windows 3.1 will open the world of Java programming up to the millions of individuals who are still running Windows 3.1 and who won't or can't upgrade to Windows 95/NT.

Update: February 1997. Netscape is now delivering a Java-compatible browser which runs under Windows 3.1.

There are many good books already available on Java programming, and new books appear on the bookshelves every day. This section will mention but a few that have caught this author's attention. Not only does this book provide an excellent vehicle for learning to program in Java, it is available in its entirety at no cost on the JavaSoft web page http://java.sun.com/. You can download the book in any of several different formats at http://java.sun.com/nav/download/index.html#tutorial. While you are at the JavaSoft page, be sure to take a look at the many other outstanding technical documents and articles which are also available there.

If you prefer, you can read the book online at http://java.sun.com/books/Series/Tutorial/TOC.html.

Or, if you prefer, you can go to the bookstore and purchase it. The authors are Mary Campione and Kathy Walrath.

While not a tutorial, this book is particularly useful as a reference book after you gain some knowledge of how to program using Java. The writing style is clean and crisp and an awful lot of valuable information is packed into relatively few pages. The Table of Contents for this book is available at http://www.ora.com/info/java/javanut/toc.html.

A very good description of the Java programming language and the class libraries is provided by this book.

Sams Publishing is putting many of their new books on the Web. As of 11/30/96, they claim to have more than 50 books in electronic form on line including: As you can see, the list includes a large number of books on Java and JavaScript programming. This is only a small part of the list which includes many other related books as well. These books can be found online at http://w3.mgr.com/samsnet/home.html.

In every case, the entire book is available, including all figures and graphics. Apparently the only thing missing is the price tag, the index, and the CD from inside the back cover.

For those who pay for their internet service by the hour, reading the books online may not be practical. The books can be downloaded to a local disk for off-line reading with a modest effort. The HTML-edit mode of Netscape 3.01 Gold provides a good tool for downloading the individual chapters of the books. (Simply ask Netscape to let you edit a page and then follow the instructions for downloading.) An evaluation copy of Netscape 3.01 Gold is currently available (11/30/96) at http://home.netscape.com/. Be sure to download the Gold version which includes the WYSIWYG HTML editor.

Without some additional tools beyond a browser like netscape, it isn't real easy to get all of the text and all of the graphics and to keep them all properly linked. This does require some effort. A good Java programming project would be to develop a Web Crawler Robot that can download an entire book with all of its graphics properly linked without straying off into some other part of the Web. As of this writing, this author hasn't figured out how to accomplish the latter part of that specification on a general basis (without straying into some other part of the Web).

There is a commercial product known as Flashsite http://www.incontext.ca/demo/flash.html which can be used to download this material and keep it intact. An evaluation copy is available as of this writing (12/05/96) but it expires on December 30.

Que Publishing On-Line Books and Java Resources

February 1997. Like Sams Publishing discussed above, Que publishing has begun putting books on-line. They have several Java books on-line at http://www.mcp.com/que/javarc/. While they don't have as many books online as Sams, they have begun making other Java resources available as well. You will definitely want to visit this URL.
NOTICE: The following is the partial text from a message received from a reader. My thanks go out to this reader for providing this feedback. As a personal note, I make heavy use of the "Online Bookshelf" described below.
=========================
Abdon Pijpelink wrote:

Dear Mr. Baldwin,

Surfing on your (excellent) Java site, I came upon two links that were expired. These are the links to Sams' and Que's online books in the "Links" section.

Sams and Que have made accessing their online books a little different. They now require every user to register. After the free(!) registration, every user gets a personalised "Online Bookshelf". Each user can select 5 books (out of the 150 they have got currently online, of which many Java books) and read those for free for a period of 90 days. The online Bookshelf can be found at http://www.mcp.com/personal/.

Bruce Eckel is the author of an outstanding book entitled Thinking in C++. Eckel is currently writing a similar book entitled Thinking in Java. As of 11/30/96, he has published a "work in progress" version of that book at his Web page, http://www.zone.org/Eckel/. Although the book is still a little rough as of this date, it promises to be just as good as his C++ book when he finishes it. Even in its current state, it is packed with information and insights. Of particular interest is his interpretation of the practical aspects of the use of a Garbage Collector and the lack of true "destructors" as are available in C++. There are so many articles and tutorials on Java programming available on the Web that it is difficult to determine which to pay attention to and which to ignore. As time goes on, I will be adding links in this section to articles and tutorials that I consider worthwhile. JavaWorld, http://www.javaworld.com/, is an outstanding source of good articles and tutorials. Go to the link shown, and then explore their "Nuts & Bolts" section. There you will find excellent technical articles as well as links to back issues going as far back as March of 1996 (in the world according to Java, that is almost the beginning of time).

Frequently Asked Questions (FAQ)

Mr. Elliotte Rusty Harold publishes a list of Frequently asked Questions from several of the Java newsgroups. As of February 1997, you can access Harold's FAQ at http://sunsite.unc.edu/javafaq/javafaq.html.

In addition to publishing an excellent series of books on Java, Peter van der Linden publishes a list of Frequently Asked Questions (with answers). As of 3/20/98, the URL was http://www.afu.com/javafaq.html.

Also as of February 1997, http://oberon.ark.com/~roedy/ authored by Roedy Green contains links to about half a dozen other sites which publish FAQs.

Class Libraries

The actual Java language is fairly small and compact. Much of the functionality of Java derives from the use of class libraries. A core set of class libraries is delivered with the Java JDK. Other interesting class libraries are becoming available on the web which extend the functionality of the Java programming environment. Some are free, others are not.

Acme Software

As of February 1997, a fairly large set of very interesting classes were available for free downloading from Acme Software at http://www.acme.com/java/software/. Before expending the effort to develop anything, you should definitely check out this resource to see if there is already a class there that will do what you want to do.

JRad Technologies

Another source of free class libraries is the JRad Technologies page at http://www.jrad.com/. As of February 1997, the free package currently includes ToolBar, ImageButton, ToolTip, FolderTab and GroupBox classes. All of these classes are useful in giving your applications and applets a professional look and feel.

On-Line Java Quiz

As of February 1997, you can take a Java quiz on-line at http://www.iconixsw.com/java/ to find out how much you really know about Java. Although knowing how to publish Web pages using HTML is not a requirement for this course, it is necessary to know a little about HTML in order to publish applets on a Web page. It is probably to be expected that many serious Java programmers will also have a strong interest in HTML and Web publishing.

This author needs to know quite a bit about HTML, and to have some pretty good tools to be able to publish these lecture notes using HTML. As time goes on, I will share what I learn about HTML tools in this section for those who may be interested.

Literally dozens and perhaps hundreds of HTML authoring tools are available via the Web. Some are free, and some are not. Some are WYSIWYG, while others require the author to deal with raw HTML. Some of the tools fall between those two extremes.

Having no desire to become an HTML expert, this author prefers to use a WYSIWYG tool instead of a raw HTML tool.

As of 11/30/96, I am using Netscape Navigator 3.01 Gold, http://home.netscape.com/,to author these lecture notes. If I find something better, I will switch to it later, but for the time being, this product serves my needs very well.

One of the best things about the product is stated on the Netscape download page: "Students, faculty, and staff members of an educational institution ... may use Netscape Navigator free of charge."

As mentioned earlier, to get the WYSIWYG HTML editor, you must have the Gold version.

Another WYSIWYG product that works very nicely is the Internet Assistant add-on for Microsoft Word. This software can be downloaded free of charge at http://www.microsoft.com/msword/internet/ia/.

However, this author has consistently experienced problems with the Microsoft Word on-line Help system whenever the Internet Assistant add-on was installed using the Windows 3.1 version of Microsoft Office under Windows 95. Therefore, the use of this product was abandoned in favor of Netscape Navigator Gold.

Wasted Disk Space

If you have a hard drive larger than about 500 mbytes in a single partition and are not already familiar with this issue, prepare yourself for a shock and try the following experiment.

Go to a DOS prompt, execute a DIR command, and record the amount of free disk space remaining on your disk.

Create one very small file (one or two bytes, see instructions below) using a non-existing file name. Then execute the DIR command again and record the amount of free space remaining on your disk after creation of the small file.

Subtract the two numbers. This difference is the actual amount of disk capacity consumed in the storage of your small file which only contains one or two bytes of valid data.

On my computer which has a two-gigabyte hard drive, 32,768 bytes are consumed for the storage of a single file containing only one or two actual data bytes.

How to Create a Small Disk File

A good way to create the small file is to execute the following command at the DOS prompt: Then type a couple of characters, press the F6 key, and press the Enter key. If you use the DIR command to determine the size of the file it should be a small number like 2 or 3.

Another Experiment

If the previous experiment got your attention, try another one. Go to a DOS prompt and make the root directory your current directory. Then enter a DIR/S command at the DOS prompt.

Quite a bit of material will be displayed on your screen. At the end, you will get a report of the total number of files, the total size of all those files, and the total free space remaining on your disk.

Add the two totals together and compare the sum with the size of the hard drive that you purchased. You may be shocked to find that the total is substantially less than the amount of disk capacity that you paid for.

On my computer as of this writing:

Something is definitely wrong here. I purchased a computer with a hard drive having a capacity of approximately 2,148 mbytes. I would hope that the sum of the space used and the space available would approximate the amount of disk capacity that I paid for.

I am missing approximately 493 mbytes of capacity or almost fifty-percent of the total space reported to have been used. And this was right after I spent several hours working to alleviate the problem.

Let me hasten to add that there are other ways to lose disk space as well as the primary topic of this section: bad spots on the disk, etc. However, on a well-maintained disk, that should be a very small percentage of the total disk capacity. Another approach to this measurement indicates that I am only missing about 420 mbytes of capacity due to the primary topic of this section rather than the 493 mbytes indicated above.

Description of the Problem

What is the problem here?

In a nutshell, regardless of what the Windows File Manager, Windows Explorer, or DOS DIR may report as the sizes of the various files on your disk, every file, no matter how small will consume the minimum amount of disk capacity determined from the first experiment above (32,768 bytes for a two-gigabyte hard drive with a single partition).

Furthermore, with a two-gigabyte hard drive, every file will consume an amount of disk capacity which is a multiple of 32,768 bytes. Therefore, unless the number of bytes in a file is an exact multiple of 32,768, every file will consume an amount of wasted disk capacity at the end of the file ranging from zero to 32,768 bytes.

For files which are greater than this 32,768 bytes in size, one might reasonably expect that on the average, every file will waste approximately half this amount at the end. Note, however, that in my case, the wasted disk capacity was approximately 28 kbytes per file. This is because a large percentage of the files in the total of 15,139 files are very small files.

Furthermore, this is a trend. Modern software development packages for C++ and Pascal use project managers which often generate dozens of different files in order to produce a single executable file. In addition, these modern development packages are often delivered and installed with hundreds of small icon and image files and hundreds of example projects.

Before I did some cleanup work recently, my Borland C++ for Windows, Version 5.0 was consuming more than 233 mbytes of disk capacity when it is advertised to consume a maximum of 130 mbytes of disk capacity. The advertised figure is probably simply the sum of the file sizes reported by Windows Explorer, not taking wasted disk capacity into account. I was able to reduce this figure to about 200 mbytes by archiving some of the example programs installed with the package.

I'm not meaning to pick on Borland. My copy of Powersoft Optima++ has similar capacity problems, and I suspect that if I had Microsoft Visual C++ installed, it would be about the same.

Unfortunately, some of the new Java development packages are beginning to follow suite, so you need to be wary at installation time and also be wary as you develop Java applets and applications to make certain that you are not leaving a lot of small files laying around consuming disk capacity.

Commercial software packages consist of hundreds of different files, many of which are relatively small. Thus, it is very difficult these days to avoid the proliferation of many hundreds of different files on your hard drive. As shown above, even though the various file managers may report these as small files, the total disk capacity consumed can be enormous due to the minimum allowable file size and the wasted capacity in the final cluster of a larger file.

Sample Program

What does this have to do with Java you are probably asking? And rightly so.

Later I will give you some hints as to how to alleviate the problem. However, it is often necessary to gain a better understanding of the problem before you can alleviate it. The following Java application can be useful in that regard.

This Java application will help you to localize problem areas within your disk directory structure. (When your hard drive contains 1,500 or more individual files, some help is needed to localize problems.)

The purpose of the program as well as instructions for its use are contained in the comments at the beginning. You can copy and paste this source code into a Java source file. Then compile and execute it to learn more about how actual disk consumption is distributed among the various directory trees on your hard drive. This will better prepare you to deal with the problem.

Also if you will study the program and develop an understanding of how it works, you will learn quite a bit about Java programming.

A number of interesting modifications could be made to the program to make it even more useful as a diagnostic tool. For example, it would be easy to modify it to produce a histogram for each directory tree showing the number of files in different size categories such as 0-32k, 32k-64k, etc. If a directory tree were found to contain a very large number of very small files, that directory tree would be a good candidate for some effort to alleviate the problem.

The following program really isn't very long. It just contains a lot of lengthy comments causing it to appear to be very long.


//

/*File DirSize.java

Copyright 1997 Richard G. Baldwin



Used to calculate true file size including the fact that 

the minimum cluster size is 32k bytes on a 2-gbyte drive.

  Not valid for other drive sizes, but could be 

made valid by changing the value of the constant named

clusterSize.  The value should be 16384 for a 

1-gbyte drive and 8192 for a 0.5-gbyte drive.



Can be used in conjunction with the DOS command dir/s 

to determine the amount of disk space being wasted 

within any directory tree including the entire 

disk.  The DOS dir/s command reports the total 

number of data bytes stored in the directory tree, 

ignoring the fact that the final cluster in every file

consumes 32kbytes of disk space regardless of the number

of valid data bytes in the cluster.



This application reports the total number of data 

bytes consumed in the directory tree taking the wasted 

space in the final cluster into account.



The total amount of wasted space is the difference 

between the value reported by this program and the 

value reported by the DOS dir/s command.



The output from this program goes to the standard 

output device which can be redirected to a 

file.  The numeric output is structured such that 

the DOS sort filter can be used to sort the results 

in order to make it easier  to identify the 

directory trees which are consuming large amounts of disk

space.



Usage:



java DirList [Directory displayDepth]



The optional parameters are as follows:



Directory specifies the directory tree for which you 

want to determine the   disk space consumed.

  

displayDepth specifies the depth to which you want 

to display the results.

  A value of 0 will display only the total 

disk space consumed in the 

  specified directory tree.  A value 

of 1 will display that value plus the 

  space consumed by each of the directory 

trees one level down.  Larger

  values will display the results even 

further down in the directory tree.



If you do not provide the parameters, the 

Directory parameter will default to C: and the 

displayDepth parameter will default to 1 showing 

the  disk space consumed by each of the 

directory trees which begin in the root

directory and the total disk space consumed on 

the C-drive.   

*/



import java.io.*;



class DirSize{

  //cluster size for 2gbyte drive

  public static final long clusterSize = 32768; 

  

  public static void main (String[] args) {

    //holds top level directory to be processed

    String directory; 

    //holds desired directory depth to be displayed

    int displayDepth = 0;  

    

    //test for command-line arguments

    if (args.length < 2) { 

        //No args, use default directory

        directory = new String("c:"); 

        displayDepth = 1;// and default display depth

    }else { 

      //use directory and depth specified on command line

      directory = new String(args[0]);

      try{ //convert input string to integer depth

        displayDepth = new Integer("0").parseInt(args[1]);

      }catch(NumberFormatException e){

        System.out.println(

          "Not a valid depth value.Terminating program.");

        System.exit(0);

      }//end catch block

    }//end else clause

    

    if(new File(directory).exists() ) 

      //if specified directory exists

      //Make a call to the method which does 

      // all the processing

       new ListDir().makeList( directory,0,displayDepth );

    else System.out.println("Not a valid directory.");

    System.out.println("Terminating program");

  }//end main method

}//end class DirSize



///////////////////////////////////////////////////////////

class ListDir{



///////////////////////////////////////////////////////////

//  This method processes all the files in the directory 

//  passed in as dir and makes a recursive call to itself

//  to process each subdirectory. The depth parameter 

//  indicates the depth in the directory tree.  The

//  printDepth parameter indicates the depth in the 

//  directory tree towhich the user wants to display 

//  results.

///////////////////////////////////////////////////////////  

  long makeList(String dir,int depth,int printDepth){

    //used to accumulate total size of the tree

    long totalSize = 0;  

    //depth specification for next level down

    int nextDepth = ++depth;  

    //length taking 32kb cluster size into account

    long actualLength;  

    long reportedLength;  //number of good bytes in a file

    

    //get a directory listing

    String[] dirList = new File(dir).list();  



    //Loop and process each file or directory in the list 

    // of files

    for(int fileCnt = 0; fileCnt<dirList.length;

                                               fileCnt++){



      if(  new File(dir + "/" + dirList[fileCnt])

                                           .isDirectory())

        //This is a directory.  Make a recursive call to 

        //  get the total size of all the files and 

        //  subdirectories in the directory and add that 

        //  value into the accumulated total. 

        totalSize += new ListDir().makeList( 

            dir + "/" + dirList[fileCnt],nextDepth,

                                              printDepth);

      else { //this is a file, not a directory

        //Calculate the actual space consumed by the file 

        //  on a 2gbyte drive taking into account that 

        //  the final cluster will be 32kb in size 

        //  regardless of the number of good bytes 

        //  stored in that cluster.

        //First get the reported length

        reportedLength = new File(dir + "/" 

                             + dirList[fileCnt]).length();

        //Now calculate the actual length for 32kb 

        // cluster size

        actualLength = 

          ( (reportedLength/DirSize.clusterSize)+1 )

                                    * DirSize.clusterSize;

        //Add actual length to the total for all files

        totalSize += actualLength;

      }//end else



    }//end for(fileCnt = 0...)

    // All files and directories in this directory have 

    //  now been processed.



    //Display results down to specified directory depth.

    //  Display inmegabytes and insert spaces to line 

    //  up the decimal point.

    if( (depth-1) <= printDepth){

      double sizeInMegs = (double)totalSize/1000000;

      //used to line up the decimal point

      int intSizeInMegs = (int)sizeInMegs; 

      //used to to line decimal point up in output

      String spaces = "";  

      //zero to left of decimal

      if(intSizeInMegs < 1) spaces =          "   ";

      else if(intSizeInMegs < 10) spaces =    "   ";

      else if(intSizeInMegs < 100) spaces =   "  ";

      else if(intSizeInMegs < 1000) spaces  = " ";

      else if(intSizeInMegs < 10000) spaces = "";

      System.out.println(spaces + sizeInMegs + "" 

                            + " = sizeInMegs for " + dir);

    }//end if(depth...

    return totalSize;

  }//end method makeList()

}//end class ListDir
//

Alleviating the Problem

This problem does not have a single best solution. It seems that each solution creates other problems.

The most obvious approach to alleviating the problem is to format your hard drive in such a way that it is partitioned into several different partitions. If you partition it so that each partition is less than 500 mbytes, you will not have eliminated the problem, but you will have reduced the magnitude of the problem by about a factor of four. The amount of wasted capacity in each file increases with the size of the disk partition.

The downside to partitioning is that unless you partition the disk when it is new, the effort to uninstall all of your software, back up all of your data, reformat the disk with partitioning, reinstall all of your software, and rebuild the disk on the basis of several partitions is a non-trivial task. It is even possible that you may not even be able to find your installable copies of some of the software.

Short of partitioning, the next objective should be to reduce the total number of files on the disk because every individual file probably incurs a significant amount of wasted disk capacity. This can be accomplished by combining individual files into archive files such as the typical zip files produced by a number of different software vendors. This can be very beneficial. You not only get the benefit of eliminating wasted disk capacity for every file, some of the files may be highly-compressible.

However, the downside to archiving is that when you want to use one of those files, you must extract it from the archive file which can be a bother.

An interesting product named ZipFolders is available which can alleviate that bother in some but not all cases. This product provides a window into a zip file and makes it possible for other programs to read files directly from the zip file and write files directly into the zip file. In this case, the zip file looks logically like a directory (with an extension). If your application allows you to specify a source and destination directory for all the files that it needs, and if that directory is allowed to have an extension, then this may be the product for you. It is available at a nominal cost.

What is the downside? Undoubtedly, using ZipFolders for this purpose would cause your applications to read and write to the disk more slowly because of the extra overhead involved.

Another approach which may accomplish the same objective, except on a much larger scale, would be to use one of the commercially available disk-compression packages such as Microsoft's Doublespace. As I understand it, these packages typically combine all but a subset of critical files on the disk into a single large file and then manage the reading and writing of pseudo-files from within that large file. Since this process significantly reduces the number of files on the disk, it would seem that it would also eliminate the wasted disk capacity associated with each individual file.

I haven't had the nerve to try this yet, and I'm not certain that it would work, but I will probably try it before I expend the effort to reformat, partition, and rebuild my hard drive when it becomes full.

As to the downside, as with ZipFolders, this will probably slow down disk access because of the additional overhead involved.

Glossary of Java Terms

As of February 1997, Roedy Green has developed a glossary of Java terms and has made it available at http://oberon.ark.com/~roedy/. In addition, this site contains dozens of free software downloads as well as links to many other Java resources on the web.

-end-


These tutorials were developed by Richard Baldwin and are the copyrighted property of Richard Baldwin. You have permission to print one copy for your own use, but may not, without written permission from Richard Baldwin, redistribute the tutorial documents.

The base material in these lessons is believed by the author to be in the public domain. If you use these lessons for any purpose, you are using them at your own risk, and this author assumes no responsibility or liability for any damages that you may incur.

Java, Sun, HotJava and various other related symbols and names are registered trademarks of Sun Microsystems, Inc. Macintosh is a registered trademark of Apple Computer, Inc. OS/2 is a registered trademark of International Business Machines Corporation. Microsoft, MS-DOS, Visual Basic, Windows, Windows NT, Internet Explorer and Visual J++ are registered trademarks of Microsoft Corporation. Netscape and JavaScript are trademarks of Netscape Communications Corporation. All other trademarks and service marks that may have been inadvertently used in these lessons without proper credit being given are the property of their respective owners. If you feel that your trademark or copyright has been compromised, please notify this author immediately, and an appropriate correction to the document will be issued.


© 1996, 1997, 1998, 1999 Richard G. Baldwin