Java Documentation
"What the books don't tell you"

There are a ton of books on Java, but there are a few key issues and items that are not clearly explained. I'll document a few of them here.

By Reference or By Value?

Many books will tell you that primitive variables are passed by value and objects are passed by reference. Nice, this is important, so important it should be emphasized and explained clearly!

Pseudo code:

  a = // "a" has some value;
  method1(a); // changes the value of "a" within the method
  // what is the value of "a" at this point?

Now if "a" is a primitive (integer, float, etc) then method1 will not change the value! But if "a" is an object then "a" will have the changes made to it inside method1!

Distribution

Java is great as a developers language. But for widespread deployment in an uncontrolled environment it is a disaster. While installing Java (and some non-standard extensions) is extremely easy, this easy process is a source of confusion and difficulty for customers (end users). Heck it even confuses many developers (who struggle when they get multiple JVMs on their system). Add in that Java by default now "auto updates" (and breaks existing code that was working fine) and you've got a complete disaster. For the past couple years I've looked at alternate languages that did native compiling just to get around this issue. Unfortunately I kept coming back to the fact that Java, even with it's flaws (and there are many) is still far and away better than any other programming language option.

Solving this issue actually is quite easy. Just distribute a copy of the JRE with your application. How do you do this?

Let's assume your company will distribute it's applications in a directory named for your company, so as subdirectories to this include the bin and lib directories of the JRE and start your program via "bin\java -jar MyProgram.jar". An example directory structure could be:

\Starfire\MyProgram.jar
\Starfire\RunIt.bat (batch file containing "bin\java -jar MyProgram.jar")
\Starfire\bin (from the JRE)
\Starfire\lib (from the JRE)

The relatively large size of the JRE could be an issue. Thus we may want to look at ways to reduce it's size. You may want to use Java 1.4 rather than Java 1.5 and you might want to leave out "javaws" (webstart).

Static vs Passing References

One issue that can come up is having a half dozen classes that all need to communicate with each other. One approach is to have the main program create instances and pass references to each other in the constructors. This can be very clumsy and troublesome as the number of classes gets large (like four or more) (especially when you get into the issue of which was constructed before which).

More and more I'm switching to making certain classes static. Thus I may have a class that handles my database and a class that handles my GUI. If both are static then they can communicate with each other easily. Usually I'll only make portions static (such as the GUI might have a TextArea that is static and thus can be updated by other classes).

There can be a lot of "chicken and the egg" issues (which was created first) so be careful of multi-threading usage especially.