Java OverviewJava is a portable language created by Sun that creates distributable, tokenized objects. If you need to write programs that are transparently portable across the Internet, Java is the way to go.
Unlike portable scripting languages like PERL or TCL, Java is a complete object-oriented programming language that may be interpretted, tokenized or compiled -- it will even run natively on custom Java chips.
Java is very similar to C++, with the major difference being that Java does not use pointers -- it uses named objects -- which makes it better suited for running on distributed, internet environments. Java is currently missing digital object signing, but a draft proposal is under way to add it. Until encryption and digital signing is available on all common Java platforms, distributable Java Applets will be limited in functionality, for security reasons.
So what is the major advantage of Java over C++ or any other object-oriented language? Its portable class library. No other class library is so extensive or available on so many platforms. Its class library provides threading, URL retrieval, image handling, 2D graphics, 3D modeling... Java makes portable pragramming as easy as native C++.
Java is also the standard language adopted by the Virtual Reality Modeling Language to add behaviors to 3D objects.
Java GotchasAs in any programming language, programmers need to watch out for memory leaks and runnaway threads. However, this is especially true with any applet that can be transparently installed on a user's machine.
A user can be cruising through a series of sites that have Java applets, and if several applets keep themselves loaded and fail to release memory, or if they continue to process intensive threads, the user's performance will seriously degrade.
Since Java makes it easy for any novice programmer to post applets on the Web, and since the user is often unaware that an applet has been loaded (much less which applet might be causing their performance problems), it is very critical for programers to watch out for these issues, and for users to be careful regarding what applets they allow to be loaded on their computers.
Creating Java AppletsThe best way to see Java applets in action is to get Netscape's Navigator 3.0 and cruise around some Java sites.
The easiest way to start working with Java is to get the free Java Developer's Kit and poke around in its sample code. If you are familiar with C++, this will be pretty straight-forward.
If you are ready to start serious development of Java applications, Symantec's Cafe' provides an integrated Java development environment with a runtime debugger.
Compiling Java Applets (Windows)If you are using an early version of Java Development Kit on Windows, there are few things to keep in mind:
After downloading and installing the JDK, set your PATH to include the java\bin directory and the CLASSPATH environment variable to the java\lib directory.
Then use the javac compiler to tokenize your application/applet:
Note: while the compiler is not case sensitive in finding your source file, it will fail if the case doesn't match the public name defined in the source -- after it has spent several minutes compiling your applet!
Remember to use getCodeBase and getDocumentBase to find auxiliary files, if they are not guaranteed to be in the same directory as the referring URL calling the applet.
Embedding Java Applets in HTMLJava applets are exposed in Java-capable browsers via the APPLET HTML tag:
The applet code (JavaApplet.class) and any auxiliary files are assumed to be in the same directory/folder as the HTML document refering to it.
Here's a more complex example of an APPLET tag:
CODEBASE indicates the location of the applet's code and the PARAM tag passes parameters to the applet. The BLOCKQUOTE tag is ignored by Java-compliant browsers, but displayed by browsers that do not support Java.
The complete syntax for the APPLET tag is: