Java Tutorial

A Brief History of Java

              Java has been around since 1991, developed by a small team of Sun Microsystems developers in a project originally called the Green project. The intent of the project was to develop a platform-independent software technology that would be used in the consumer electronics industry. The language that the team created was originally called Oak. 
           The first implementation of Oak was in a PDA-type device called Star Seven (*7) that consisted of the Oak language, an operating system called GreenOS, a user interface, and hardware. The name *7 was derived from the telephone sequence that was used in the team's office and that was dialed in order to answer any ringing telephone from any other phone in the office. This PDA-type device was intended to be sold to consumer electronics manufacturers who would distribute the boxes under their company name. In 1993, the team, then incorporated as FirstPerson, Inc., decided to gear their technology toward a new implementation for which demand was building in the entertainment industry-interactive television. They proposed their technology to Time Warner as an operating system for set-top boxes and video-on-demand technology that would decode the data stream that Time Warner would be sending to television sets around the country. In June of 1993, Time Warner selected Silicon Graphics' technology over Sun's. A later deal fell apart and FirstPerson decided to disband. Half of the members of the original FirstPerson team continued to work with the Oak technology, however, applying it to multimedia and network computing. 
              Around the time the FirstPerson project was floundering in consumer electronics, a new craze was gaining momentum in America; the crazewas called "Web surfing." The World Wide Web, a name applied to the Internet's millions of linked HTML documents was suddenly becoming popular for use by the masses. The reason for this was the introduction of a graphical Web browser called Mosaic, developed by ncSA. The browser simplified Web browsing by combining text and graphics into a single interface to eliminate the need for users to learn many confusing UNIX and DOS commands. Navigating around the Web was much easier using Mosaic. 
              It has only been since 1994 that Oak technology has been applied to the Web. In 1994, two Sun developers created the first version of HotJava, then called WebRunner, which is a graphical browser for the Web that exists today. The browser was coded entirely in the Oak language, by this time called Java. Soon after, the Java compiler was rewritten in the Java language from its original C code, thus proving that Java could be used effectively as an application language. Sun introduced Java in May 1995 at the SunWorld 95 convention. 
             Web surfing has become an enormously popular practice among millions of computer users. Until Java, however, the content of information on the Internet has been a bland series of HTML documents. Web users are hungry for applications that are interactive, that users can execute no matter what hardware or software platform they are using, and that travel across heterogeneous networks and do not spread viruses to their computers. Java can create such applications. 
Applets
             On the Internet, Java programs are called applets. Applets are Java applications that are embedded inside HTML files and can be downloaded into a Java-capable browser with the click of a mouse. Applets are different from regular Java applications. A Java application simply has a single main() method that indicates to the Java runtime system that it is an application. A Java applet is an application that includes several additional methods that the runtime system uses that tell it how to handle the applet, such as what to do when a user clicks an applet icon and how it looks on a page. 
Before your browser's runtime Java interpreter downloads and executes the applet's code, the Java interpreter verifies the code's integrity. Java is more than a tool to help you write applets, however. It is a new, powerful programming environment. 

Java's Features
                Sun describes Java as a "simple, object-oriented, interpreted, robust, secure, architecture-neutral, portable, high-performance, multithreaded, and dynamic language." 
Each of the features mentioned in this quotation from Sun's Web page is an important part of the Java development environment as well as a critical requirement for Web programming. The combination of these features makes Java a powerful and useful programming language that empowers you, the programmer, with the tools you need to easily create powerful programs for today's distributed environments.
Simple
                Java is simple to use for three main reasons: First, Java is familiar to you if you know C. Second, Java eliminates components of C that cause bugs and memory leaks and replaces their functionality with more efficient solutions and automated tasks, so you have a lot less debugging to worry about than you would using C or C++. Third, Java provides a powerful set of pre-tested class libraries that give you the ability to use their advanced features with just a few additional lines of code. 
Object-Oriented
                Java is an object-oriented programming language that uses software objects called classes and is based upon reusable, extensible code. This means that you can use Java's classes, which are sets of variables and methods, as templates to create other classes with added functionality without rewriting the code from the parent classes or superclasses. If you plan your application's class hierarchy well, your application will be small and easy to develop. The hierarchy of classes is explained later in this chapter. 
Robust
             Java is robust because the language removes the use of pointers and the Java runtime system manages memory for you. The problems with pointers in C and C++ was that pointers directly addressed memory space. In a distributed environment like the Internet, when code is downloaded to diverse systems, there is no way of knowing for sure that memory space addressed by pointers is not occupied by the system. Overwriting this memory space could crash a system. Java also gives you automatic bounds checking for arrays, so they cannot index address space not allocated to the array. Automatic memory management is done using the Garbage Collector, which is explained in detail in Chapter 4, "Creating Your Own Objects." 
Interpreted
               Java is interpreted, so your development cycle is much faster. As you learn later when the Java interpreter is discussed, you need only to compile for a single, virtual machine and your code can run on any hardware platform that has the Java interpreter ported to it. 
Secure
              Java is secure, so you can download Java programs from anywhere with confidence that they will not damage your system. Java provides extensive compile-time checking, followed by a second, multilayered level of runtime checking. " 
Architecture Neutral
            Java is architecture neutral, so your applications are portable across multiple platforms. Java's applications are written and compiled into bytecode for Java's virtual machine, which emulates an actual hardware chip. Bytecode is converted to binary machine code by the Java interpreter installed at the client, so applications need not be written for individual platforms and then ported from platform to platform. Java additionally ensures that your applications are the same on every platform by strictly defining the sizes of its basic data types and the behavior of its arithmetic operators. Operator overloading, the process of modifying the behavior of operators, is prohibited by Java. 
High Performance
             Java is "high performance" because its bytecode is efficient and has multithreading built in for applications that need to perform multiple concurrent activities. Although threads still require the use of classes, Java balances the addition of thread synchronization between the language and class levels. Java's bytecode is efficient because it is compiled to an intermediate level that is near enough to native machine code that performance is not significantly sacrificed when the Java bytecode is run by the interpreter. 
Dynamic
            Java is dynamic, so your applications are adaptable to changing environments because Java's architecture allows you to dynamically load classes at runtime from anywhere on the network, which means that you can add functionality to existing applications by simply linking in new classes. For example, if your applet is being run by a browser that doesn't have one of the classes included in your applet's byte code, the browser can download the appropriate class from the server that is storing your applet, check the byte code, and execute it. This is assuming your browser has not been configured with strict security.