This lecture is divided into hyperlinked sections
Introduction
Brief History of Java
What is Java?
Compiling the Code
Architectural Neutrality
Java Virtual Machine
Features of Java
Java Developments
Conclusion
Tutorial Questions
References
This section of the course is concerned with Java, a cross platform Object Oriented programming language.
We will see what Java is and the reason for its existence. We will see how it manages to provide functionality across a wide variety of hardware/ software combinations.
We will see how the networked code produced at compile time is handled by clients.
We will see other developments of the Java language.
Java is a high-level programming language that was designed
by Sun Microsystems. Java was originally called OAK, and was
designed for handheld devices and set-top boxes. Oak was unsuccessful so
in 1995 Sun changed the name to Java and modified the language to take
advantage of the burgeoning World Wide Web.
Java is an object-oriented language similar to C++, but simplified to eliminate language features that cause common programming errors. By using C++ (an object oriented language) to form the basis of Java, it eliminated the need for extensive retraining for programmers before they could use this new language.
Small Java applications are called Java applets and can be downloaded from a Web server and run on your computer by a Java-compatible Web browser, such as Netscape Navigator or Microsoft Internet Explorer.
The success of Java can be attributed to many of its capabilities, but the primary concern of most users is safety. Java was originally written to be a language that had no capabilities for causing damage to remote machines that were running the applets (small applications) written by programmers and transferred to the remote machines by the Internet. By the nature of the construction of the language, Java applications cannot gain unauthorized access to memory, which could happen in C or C++.
Other reasons for the success of Java are that at the time of its introduction there were no other competitors for active document technology. It is better at controlling multiple areas of the screen of the client machine.
Java gives better display capabilities by generating images
locally on the client machine which can then be displayed on the client
monitor. This is a faster process than creating the images at the server
and transmitting them via a network to the client for display.
Java source code files (files with a .java extension) are written by a Java programmer and when complete the files are compiled into a format called bytecode (files with a .class extension) on the programmer's computer. This bytecode is stored on web servers and reference to a particular applet is made within the HTML of a standard web page.
When a web page containing an applet is loaded onto a user's computer, the applet is also transferred to the user's computer. The applet can then be executed by a Java interpreter.
Compiled Java code can run on most computers because Java interpreters and runtime environments, known as Java Virtual Machines (VMs), exist for most operating systems, including UNIX, the Macintosh OS, and Windows.
Bytecode can also be converted directly into machine language instructions by a just-in-time compiler (JIT).
Across the world, computer users will be using a variety of different hardware to run their computers. The PC market uses the x86 series of processors with Intel, AMD and Cyrix also producing x86 clones. The Apple Mac began by using Motorola's 680x0 series of processors and then began to move toward the PowerPC family.
This is further complicated by the large choice of operating systems that are available for running the hardware. There are many versions of Windows, UNIX, Linux (and assorted offspring) and others to choose from.
This diversity of operating systems and hardware made it a hard job for a programmer if he/ she wanted to produce software to run on any particular system. It meant that he/ she would need to write several different versions of an application to suit the different environments.
Java has simplified this situation. The programmer need only produce one version of an applet and this will be sufficient for all platform combinations.
This is accomplished by passing the completed application through a compiler. The compiler produces bytecode and one version of this is stored on the web server. When a browser makes a request for the applet, the bytecode is delivered to the machine via the Internet and upon arrival this bytecode is translated into the code required for the platform by the Java Virtual Machine.
The price paid for this cross platform compatibility is encountered when the bytecode is translated into native machine code for the client that is running the applet. The bytecode interpretation is slower than C or C++.
The Java Virtual Machine is a piece of software that is run on the client machine. The JVM is responsible for running the output from the bytecode on the client machine. Various different implementations of the JVM are required depending on the operating system in use.
Currently it is possible to download the Java Runtime Environment (JRE) to suit Windows (all implementations), Solaris and Linux. The Java Runtime Environment includes the Java Virtual Machine, Java Core Classes, Java Plug-in and support files. This will allow the bytecode to be translated correctly for the platform in use.
Java is sometimes described as a "semi-compiled" language. This means that the first part of the compilation is carried out by the programmer after the program has been written. This generates the bytecode that is held on the server for clients to request.
The second part of the compilation is carried out on the client machine when the bytecode held on the server has been requested and delivered. The bytecode is translated into code that is compatible with the client's hardware/ software combination.
The execution engine performs the final translation of bytecode to native opcodes. The choices are different depending on the hardware and speed of execution required.
The easiest (default) method of translation is by using a bytecode interpreter. This takes the bytecode and translates it a line at a time, producing output for the JVM at a slow rate. If the program is run a second time it will have to be interpreted all over again.
Alternatively it is possible (for some hardware environments)
to make use of a Just-in-time compiler. When running in the JIT compiler
mode, the compiler converts Java bytecode into native RISC (Reduced Instruction
Set Computing) instructions; the JVM then executes those instructions.
Translation is needed only once during a run. This means that the next
time the JVM needs anything from the class, it goes directly to the native
code instead of to the Java bytecode. This makes the running of Java on
the client machine faster.
Programming using Java has been simplified in many aspects. One aspect is the management of computer memory while the program is running. When using C and C++, there is the problem of setting aside memory for the application to use and then removing data from memory when it is no longer needed. This was (and still is) the source of many problems when programming.
Java does not require that the programmer consider storage details. It has a feature that is known as 'automatic garbage collection'. This involves the computer automatically and periodically freeing memory that is not being referenced). By having this feature, programming becomes easier and it also dramatically cuts down on bugs in your code.
The price paid for the automatic garbage collection is paid for in processor time. The processor will have to spend time running the Java code and also perform memory management.
Networking using Java is made easy too by the availability
of a library of routines that can simplify working with protocol systems
such as TCP/IP and associated internal protocols like HTTP and FTP. The
task of programming applications that call upon network connections is
much easier than in C or C++. Java applications can open and access objects
across the net via URLs with the same ease that programmers are used to
when accessing a local file system.
PersonalJava and EmbeddedJava are available to control
small devices such as PDAs, copiers and even smart cards. Personal Java
extends Java to devices with displays but no keyboards, such as televisions
and copiers. EmbeddedJava extends Java to devices with embedded microprocessors
and limited memory, such as pagers and cell phones. Another development,
JavaCardtm brings
Java to smart cards, wallet-size cards that contain microprocessors.
Java is a general purpose programming language with a number of features that make the language well suited for use on the World Wide Web. It is architecturally neutral so that one version of an application will be portable to all different platform combinations.
Java was designed with many security features to ensure that applications written using Java cannot cause damage to clients' machines.
Java does not contain instructions to manipulate computer hardware such as the hard disk.
Java may be described as a 'semi-compiled' language because the compilation is carried out in two parts. At the time of writing the program, it is converted into a form known as bytecode by a compiler.
The bytecode is delivered to a web server.
Clients request the bytecode and it is transferred via the Internet.
Upon arrival, the bytecode is either translated into native code or it may be converted directly into native RISC instructions.
Memory management is automatic in Java, but the penalty paid is slower execution due to CPU sharing.
PersonalJava, EmbeddedJava and JavaCard are versions of
Java intended to control small or portable devices such as televisions,
cell phones and smart cards.
What choices of portable cross platform programming languages are available apart from Java?
Describe the steps a programmer would have to take to ensure that his C or C++ program could be used by all different hardware/ software combinations.
Explain why other languages such as C or C++ can produce programs that can cause deliberate damage to users computers e.g. formatting C drive.
Why is it impossible for Java to do this?
What encryption system is used in Java's authentication
procedure to identify and authenticate classes?
Comer, Douglas E, The Internet Book, Prentice Hall 1977
http://java.sun.com/
http://java.sun.com/docs/overviews/java/java-overview-1.html
http://webopedia.internet.com/TERM/J/Java.html