Mac Java Journal

Week One

2/13/96 Checked at the Java Web site and found that the Macintosh JDK was available. Downloaded the 3 meg hqx file and installed JDK. Read the notes about it. Watched some of the sample animations dance around in the Applet Viewer. Started this page.

2/14/96 Decided to take the approach of using a book called _60 Minute Guide to Java_ by Tittel & Gaither as a starting point for learning Java. Skipped immediately to page 74, Creating Your First Java Applet. I found that a little more complicated than I wanted for now so I put it aside temporarily opting to try a tutorial Website instead. Sun's Getting Started with Java. I ignored their suggestion to read the white paper on Java. I'm still itching to create an applet and watch it run. Skipped down to The Java Language Tutorial Then skipping down to The "Hello World" Applet -- Start here if you are interested in writing applets only. (Since this version of the JDK for Mac only allows you to create applets instead of stand alone applications.)

I copied the text of the script over to an editor and saved it. They include notes on how to create directories for Unix and Dos, but not for Mac, which we Mac users don't need anyway. They give a command "javac filename" to comile the file. But heck I just drag-and-drop the file onto the compiler. Took about 3 minutes to compile the 6 line file. This created a second file called HelloWorld.class. I drag-and-drop that onto my applet viewer instead of putting it into an html document, because Netscape has only enabled the Windows 95 browser with Java (grrrr.) and I haven't upgraded my WinTel machine yet. Got an error. Thought maybe the text file was screwed up from copying it from the Web page. Fixed it. Compiled it (another 3 minutes) and the same error again. So I've spent an hour now not being able to print "Hello World") Maybe it's time for me to hang around department store computers again typing:
10 ? "Hello World"
20 goto 10

Later that same morning (when I really should have switched over to actual money-making activities) I try the code that is for standalone applications. It works like a charm! So, although I can only create applets with this JDK, I can only view applications.

Will my "applications" run as applets?
Will my applets run ok with a browser even though they won't run on the Applet Viewer?
Or was there just something wrong with the code for the applet?
With these conundrumming in my head, I head out the door, singing, "I Owe. I Owe. It's off to work I go."

2/15/96 Today I'm a little less hyper about making Java do something, so I am running through the lesson called Object-Oriented Programming Concepts: A Primer. This is a very nice explanation of the basics (thus the term Primer.) None of it should come as much of a surprise to anybody who's fiddled around with Hypercard. (Hey, DOS boy, can you say, "Subroutine"? I thought that you could. And then Das Boot is a whole other sub routine.)

Ok, another glamorous day of database consulting under my belt, I'm ready to tackle some more Java theory. I'm sticking with the Website tutorial that is in actuality a draft of an upcoming book: The Java Language Tutorial by Mary Campione and Kathy Walrath. It seems to have grown out of the old Trail Map tutorial. It's very nicely done and I get a sense of being on the writing team, what with blank holding pages and promises of things to come. But I digress... The next lesson, I'm tackling is Java Objects Whoa, 15 minutes of theory and my brain hurts. Back to getting Java to do something again. So I take their little example " public Rectangle() {} and try to fit it into the HelloWorld applet that worked earlier. I get 12 errors in 4 lines of code. Gotta be a new record. The compiler seemed to totally ignore any trivial attempts at holding down the Command key and pounding the period. I even tried Ctrl-C and Esc to no avail. Javac don't stop for nobody. Menu File Close works, but it kicks you all the way out of the compiler. Also, I changed the File Properties menu item to point to SimpleText for editing. It also suggested BBEdit and Metrowerks for editors.

A pet peeve of mine is when author's give an example and neglect to tell you whether the names they use are part of the programs command set or whether they are the author's own clever variable names.

I quickly find that I have plenty of time to pursue theory and even write this journal while javac is trying to make this 68k Mac compile a simple little program. Luckily all those years of television training me to utilize the commercial break time wisely enables me to multi-process. Or sometimes I just stare at the screen waiting. There's a productive approach.

I am leafing through the 60 Minute Guide to Java book and find a list of keywords on page 33. Now that's the kind of info that makes me feel secure. They have 50 listed. None of them is rectangle. So screw the rectangle. I'm going back for more theory!

Interesting description of how the Java garbage collector works. For the Mac, though, I think they should rename it the TrashMan-ager. That's the Java Objects lesson and I'm getting really antsy. I guess I still don't get Java. But I will keep slapping it back and forth between my right-brain and my left like some game of biochemical Pong. Right now I'll surf the Web.

SunWorld's new Webzine, Java World, hit the virtual newstands today. The first issue has some really good solid features. The Nuts and Bolts section shows a lot of promise. It also has some really good links on its Java Jumps page. The only complaint I have about it is that it creates such weird long URLs that the Applet Viewer can't even read the URL much less access the page.

2/16/96 This morning, I'm back to hands-on stuff with the compiler (which should be called Error reporter). I've found that the comiler doesn't remember the preferences I set and defaults to Metrowerks for an editor every time I close the program. It is helpful in that it provides a little housetop under the location of the error. My current strategy is to take the now two programs that have worked for me (Hello World, and Current Date) and fiddle around with them to see what kind of syntax causes an error and which doesn't. Here are the files that work with my Applet Viewer:

1.
                    class HelloWorldApp {
                        public static void main (String args[]) {
                            System.out.println("Hello World!");
                        }
                    }

2.
import java.util.Date;

class DateApplication {
     public static void main(String args []) {
           Date current = new Date ();
                   System.out.println(current);
}
}
That "public static void main(String args []) {" line seems vital to an application's success. I noticed that the S in System really did need to be capitalized. It doesn't seem to matter if the ( open-parens has a space before it or not. I'm not sure if the indenting is important or not yet. It seems that any line that doesn't end with { must end with ;

I went back to the 60 minute Java Guide for the DateApplication. Typing in programs like those old Basic listings in Commodore magazine.

When I first tried, the Sample Applets that came with the JDK worked on the Applet Viewer. Now those same ones won't work on the Viewer. What gives? I've tried to making copies of an applet and recompiling them with no luck. Now I've added the magical "public static void main(String args []) {" line to the NervousText program to see if that will compile.
A rule (I think). The name of the file e.g. HelloWorldApp.java must be the same as the class that you define within the file e.g. class HelloWorldApp {

The compiler doesn't count all the way down to 0%. After it writes the .class file it goes to idle. Also, the viewer slows down its loading a lot when you try to do something else (like write this journal.)

2/18/96 After a day out in the 3D world driving along the coast and into the mountains, noticing how the different shades of green are rendered and how cow objects are instantiated on the hillsides in such variety and indeed how god uses OO message passing paradigms to create herd-behavior in the moo-cow objects...and how the wife object tells me to "CUT THAT OUT!"

OK, back to Java. I've been sort of aimlessly going back and forth through 60 Minute Guide, the tutorial and the API to get a "feel" for the concepts and technics. Now I'm tackling the lesson in the tutorial called The Anatomy of a Java Application. One analogy that occurs to me is that the class is like a function(). It seems I was right about the importance of the line "public static void main(String args[])" to applications. Perhaps the word "main" should have been a clue. Each class that is imported from the Java packages has a main method. Also, I was wrong about the text file being required to have the same name as the resultant compiled application. It is a convention, but the name of the .class file that is created is determined by the name of the class that you give within the text file.

So my limited understanding so far seems to indicate that there are Java packages (like Libraries?) that contain a set of classes (functions?) that can be imported into program files (text files with .java extensions) and then defined in terms of data (variables?) and methods (commands?).

This lesson also tells how to run a Java application in Dos and Unix. For Mac, of course, it is double-click the .class file or drop and drag onto the applet viewer.

This lesson has an excellent combination of practical and theoretical info. Excited by the progress in understanding that I think I've made I'm continuing on to the next lesson The Nuts and bolts of the Java Language What's one more cobweb on the rollerblades or one less pound of pressure in the bike tires? Ok, I took a break to go blading, but I'm back now. (My wife only knocked me down once. Never marry a former Roller Derby Queen.)

When I dropped two text files on the compiler at the same time, it compiled each in sequence and produced the proper .class files. When I dropped two on the applet viewer it processed them each in sequence also.

When I tried to compile the two counting programs from this lesson, Java gave me a whole bitload of error messages about exceptions. I'll have to figure out what that's all about. It seems to have to do with something in the throws java.io.IOException statement. The writers threw in "throw" into the text without explaining it.

Well, I'm understanding more, but I still can't troubleshoot applets. I don't know whether something is a typo, a version problem or applet vs application problem.

2/19/96 Alright break-through time! I was just fiddling around with all the options I could think of and discovered: To open an applet with the AppletViewer you must have it embedded in an html document. Then you open the AppletViewer and select File Open Local to load the html which then runs the applet. That is the way to look at the Sample Applets. To run an application you have to drag and drop the .class file onto the AppletViewer icon. This allows me to test applets that I want to embed into my html documents. I am a happy boy. This was actually a re-discovery since I did the same thing the first night I got the JDK. I just forgot. (I thought I had the flu, and it turned out to be just a case of the dumbass.)

Back in antsy mode, I decided to adapt Daniel Wyszynski.s NervousText so that I could put it on one of my pages (The Infinite Goof. ) I duplicated the two files: NervousText.java & example1.html and put them into a separate folder. I opened up Nervoustext.java and changed the class to GoofText.class. I saved it under the new name GoofText.java. I opened up example1.html and changed the lines :

<applet code="NervousText.class" width=200 height=50>
<param name=text value="Hot Java-beta">
</applet>
to
<applet code="GoofText.class" width=300 height=50>
<param name=text value="The Goof">
</applet>
Then I put some explanatory text around the lines of code and implanted them into my html page. Now I know that the new applet works on the Applet Viewer, but I don't know for sure it works on the Website, because I don't have a Java-enabled browser. So I'm repeating it here, please let me know if it works or not. TIA-Thanks in advance.

Lessons from Week One

  1. You can drag and drop html files onto the Applet Viewer, but not .class files.
  2. This version of the JDK 1.0 Beta only does applets not applications (except for very simple ones).
  3. Use the viewer to view your pages to see if the applets will run while embedded in the html.
  4. A good approach is to copy-and-modify existing applets and substitute your own images or text.
  5. You can use the Applet Viewer to see all those applets out there for Windows & Sun by opening the URLs with it.
  6. Parameters are passed within the html code.

Back to MacJava