Prof. Bill's Coding Notes

I found myself making little Post-it reminders all the time while I was coding. Finally, I decided to create this page instead. The notes are sorted by topic.

Java

I will post Applet and non-Applet (main() method-based) program templates on the k: drive. You should (almost) never start with an empty screen. Get a starting template for a new class or applet and start with that. Show me your template(s) when you have them.

jGRASP

All things said, I really like jGRASP... it's lean and mean. Notice that it only adds a single file to your folder to take care of its business. The things I don't like so much:

  • the actual text editor is a bit, um, clunky
  • I can't believe they don't have a "make" facility to "Save, then build, then run" in a single command. At least Build saves before you compile, but if you change your source code and "Run", it does not do a "Build" first.

At North Central, jGRASP can be found in the "Network Programs" menu under Start.

Get proficient, get in a groove and always use:

  • ^B to "Build", and
  • ^R to "Run"

When generating your Javadoc documentation (it's in the Project/Generate Documentation menu), add the -author option to "Additional Command Flags". I have looked at the options page for Javadoc trying to find a way to make the pages less verbose (like cutting out the "Nested Class Summary", for example), but I have not been successful.

Speaking of Javadoc, the tags I want to see everyone use are:

  • @author for your class
  • @param for each method parameter
  • @return for each method's return value
  • @throws for each exception

When you build or compile and get an error, double-click on the error in the status window at the bottom and the cursor will move to that line of code in your editor window.

Applets

When viewing Applets in your internet browser, beware the "hard caching" that browsers like Firefox do with Applets. If you change your Applet and do a reload in the browser, it won't load in your new Applet code. The only way I know of to get the browser to actually re-read your applet Java is to quit the browser and start it up again. The browser's refresh only updates the HTML the browser reads, not the Java.

You must get comfortable working with both Applets and Java application programs (that use main()). In general, I use main() while I'm coding because it's faster (^B, ^R, rinse, repeat). Once I have a stable version, then I may turn my application into an Applet. Remember, an Applet is just a fancy Frame.

To add an Applet to a web page, you need to add a single line of HTML code. Here's how I added my RTreeApplet to a web page:

<applet code="RTreeApplet.class" width="500" height="500"></applet>

In this case, RTreeApplet.class must be in the same folder as the web page. Doing this is a nice way to post your Applets on the internet and also print the output of an Applet.