Java Break
Volume Number: 12
Issue Number: 5
Column Tag: Getting Started
By Dave Mark
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
Over the next few months, we’re going to take a break from PowerPlant and play
around with the Java programming language. Why spend time on Java? Java is
extremely popular. Java is a cool language. Many people think Java is a better
language than both C and C++. Java offers an elegant mechanism for developing
software that will run on a Mac, Windows machine, or a Unix box, all without
recompiling.
If you are even a little interested in the World Wide Web, you should definitely
learn Java. While you’ll use HTML (or an HTML-generating program) to create your
web content, you can greatly enhance your Web pages by calling up Java applets from
within your HTML.
Java Is Not C++
You will frequently see Java compared to C++. Though Java is very similar to C++,
there are many major differences. For starters, Java doesn’t support pointers, is
designed to support multi-threading, and does its own garbage collection and dynamic
memory management. To add a user interface to a C++ program, you’ll take advantage
of a Toolbox designed for a specific platform (in our case, we use the Mac Toolbox). To
add an interface to a Java applet, you’ll take advantage of a Java-specific,
platform-independent interface library called the AWT (advanced windowing toolkit)
that ships with your development environment.
Java is, however, very similar to C++. As we go through our Java examples,
you’ll find very few clues that this isn’t straight C++ code. Of course, I’ll do my best
to point out the differences.
Before you read on, you might want to take some time to get a bit of background on
the Java language. The March issue of MacTech Magazine had an excellent article by
Richard Cardona called Writing Java 102 that is definitely worth a read. Of course,
there have been a number of other Java articles, and there is also a steadily increasing
deluge of Java books hitting the market. Check ’em out, pick one you like, dig in and
learn the basics.
Getting Java on Your Machine
Before you can work with Java, you’ll need to get hold of a Java development
environment. There are several choices. For starters, you can visit Sun’s Java web
site (http://java.sun.com) and download the Macintosh version of the Java Development Kit (JDK). The JDK is free (except, of course, for any internet access
fees) and fairly straightforward to use. It consists of all the files you need to do Java
development, along with a Java compiler and an applet runner called Applet Viewer.
The real problem with the JDK is that it is not a development environment, but rather