Leon's Introduction to Java

Introduction

Features

Should I Learn Java?

Introduction

Top of page

Java is a new object oriented programming (OOP) language based on C++ from Sun Microsystems. Java has many features that make it ideally suited for writing programs that can be easily distributed over the Internet. Java was originally designed as a simple, easy to use, easy to learn, language to create embedded systems, but it really took off when Netscape included a Java virtual machine (VM) with its popular Navigator browser. Java is one of the most commonly used technologies for creating interactive, dynamic web sites. To view Java programs on web sites, you will need a web browser that includes a Java virtual machine. The latest browsers from Microsoft and Netscape will do just fine. Although Java can be used to write regular applications, it is mostly used as a way to distribute programs over the Internet via web browsers. Sun is working very hard to make it more than just a web programming language. The ultimate goal of Java is to become a standard way of developing and running all programs across all computers and operating systems, not just applets (mini-applications) that spice up web pages.

Features of Java

Top of page

So what is all the hype over Java? Well here are the major features that Java has going for it.

Easy to learn - The syntax is basically a simplified version C++. If you know C++, you will learn how to write syntactically correct Java very quickly because it is almost taken directly from C++. The steepest part of the learning curve is not in the syntax, but is in becoming familiar with the many class libraries that come with the Java Development Kit (JDK). Of course, there are differences. The most notable difference being that Java completely eliminates the use of pointers and memory management issues. Instead of pointers, Java makes heavy use of reference variables, with very strict type checking. After writing a few programs, I must say it is certainly nice to be able to allocate memory freely and not worry about having to free it. Java uses garbage collection techniques to clean up after you.

Easily Distributed - By seeing how widely used Java is on the Internet, you can probably guess that this language was designed to run over a network. Running Java programs is as easy as typing in a web address.

Secure - Since Java was designed to run over a network, the designers put a lot of effort into making this a secure language. The VM checks the downloaded code before it is run. The VM also puts lots of restrictions on downloaded programs. Applets can not access the file system and can not see the underlying memory structure.

Cross Platform Compatibility - This is probably one of the most important features. Java programs are interpreted, not compiled like C++ programs. Java source code is translated into a series of byte codes that the VM interprets and runs. Therefore, only the Java VM needs to be ported to the native hardware and operating system and all Java programs will run on it (at least in theory). Therefore, you can view and run Java applets and applications regardless of what kind of hardware and OS you are using as long as you have a virtual machine. This is the basis for Sun's slogan "Write once, run anywhere!"

For more information about Java, see the Sun's Javasoft site. If you are looking for applets take a look at my JSnake. JARS is another excellent resource for applets and the latest news on Java.

Should I Learn Java?

Top of page

Is Java going to replace C++ as the workhorse programming language? Or is will it remain in its limited role as the Internet programming language. It's too early to say right now. It certainly is easier to use and easier to learn than C++, but is it powerful enough? Are the advantages of Java enough to offset its shortcomings? Consider these points:

Slow performance - Since Java is an interpreted language, performance is noticeably slower. Although Just-In-Time (JIT) compilers will help greatly, it is still slower than native code. The real question is will it be fast enough to write large, full-blown applications.

Security vs. Power vs. Trust - Although you can be reasonably sure that the Java applet you just downloaded won't destroy your data, the security severely limits the functionality of web applets. You can't save a local copy of the stuff you create with applets because the Java VM will not allow it. The other option is to digitally sign the applet, so you know who wrote that program. If you trust the party on the digital certificate, then you can allow that program full access to your computer. This allows a whole new possibility of applications, but it does open the door for damage caused by buggy programs or viruses if your trust is misplaced. The current implementation of Java places more emphasis on security than power.

Cross Platform Incompatibility - In theory, you should be able to develop and debug your Java program on just one platform and be confident that it will run correctly in every other VM. In practice, each VM behaves slightly differently from another VM. Therefore, you can't be sure that your Java program will run correctly on a particular VM unless you test it. Even with my relatively simple JSnake program, I got significantly different results with Netscape, Internet Explorer, and the applet viewer included with Sun's JDK. Although Sun can define what is correct behavior, the behavior in products widely such used as Navigator and Internet Explorer will become the de-facto standard. Writing a Java VM is a complex process and it is questionable if vendors will ever be able to standardize on a VM. Furthermore, the need cross platform development may not be so great anymore because the vast majority of computers in use today are based on the Wintel (Windows and Intel) architecture.

Inability to take advantage of native hardware - Since Java was designed to be a cross platform language; it is very difficult to take advantage of the special features of a particular architecture. For example, you may want to use Intel's MMX instructions to speed up your multimedia operations. Well once you do that, then your program will not be cross-platform anymore. History tells us that users want to be able to take full advantage of their hardware and not be hampered by the lowest common denominator.

Competing technologies - Java is facing strong competition from Microsoft's ActiveX technology. While Microsoft states that ActiveX does not compete directly with Java, it does threaten to make Java irrelevant if it catches on. ActiveX does not have any security checks on code it runs and relies on digitally signed certificates (a trust based model). ActiveX currently does not have any cross platform support. You must be running Windows 95 or NT with Internet Explorer to use ActiveX. While Java is platform independent, ActiveX is language independent. You may use C++, Visual Basic, or even Java to create ActiveX applets. ActiveX allows you to create more powerful applets, in a variety of languages by sacrificing platform independence and security. ActiveX is based on Microsoft's OLE technology, which has been around since Windows 3.1 and is a very mature technology.

Java is still a new language and therefore still has many bugs and shortcomings that Sun needs to deal with. Nevertheless, it has gained a tremendous amount of momentum from academic community and industry leaders in a very short period of time. As Java of this writing, Java is about 2 years old. Should you spend the time to learn Java? If you already know C++, then my answer would be yes. Java will leverage your C++ knowledge to give you the ability to create applications that are distributed over the Internet. If you're new to programming, I would learn C++ first, even though it is harder to learn than Java because it is currently widely used in the industry. Java's future as a full-fledged programming language is still unclear because of the points I have stated. If you are just starting to learn how to program, C++ is a safer bet.

Leon's Home Page | Leon's Java Page

Send email to Leon at: leonfu@remus.rutgers.edu

Last revised June 27, 1997.