Return to index

 

An Introduction to Java

 

Java is an object-oriented programming language developed by Sun Microsystems, a company otherwise best known for its high-end Unix workstations. Modeled loosely after C++, the Java language was designed to be small, simple, and portable across platforms and operating systems, both at the source and at the binary level.

 

The origins of Java

James Gosling, Patrick Naughton and a group of engineers at Sun Microsystems, Inc. were interested in designing a small computer language that could be used for consumer devices like cable TV switchboxes. Given the lack of memory capacity, and also the fact that such devices are short on power, the language needed to be very small and generate very tight code. Further, to accommodate different Central Processing Units (CPUs), they knew they could not tie themselves to any single architecture. The project was given the code name "Green".

The requirement for small, tight code led the team to resurrect the model that a language called UCSD Pascal had tried in the early days of PCs and that Niklaus Wirth had previously pioneered. The idea was to design a portable language that generated intermediate code for a hypothetical machine (often called a 'virtual machine'). This could then be used on any machine that had the correct interpreter. Since both the code and its interpreter could be really small, the main issue of size was solved.

Sun and its people are from a Unix background, hence they based their language on C++ rather than Pascal. The idea was to make it fully object-oriented. Gosling (presumably loving the way the Oak tree outside his window looked at Sun) named his language "Oak". This was 1991.

The efforts of the team came out in 1992 under the name '*7'. This was an extremely intelligent remote control. It had the power of a SPARCstation in a box that was just 6" by 4" by 4". Unfortunately no one was interested in producing this at Sun and from here started the battle to sell the technology. The Green Project (now christened as "First Person, Inc.") spent all of 1993 and a fair amount of 1994 looking for a customer ready to buy the technology. Patrick Naughton accumulated 300,000 miles trying to market and sell the technology. First Person was dissolved in 1994.

While all of this was going on, the internet was getting bigger and bigger. Marc Andreessen, an undergraduate student on a work-project at the University of Illinois, helped create 'Mosaic' - which quickly became the most commonly used browser. Its ease of use helped the internet attain an ever-greater popularity.

The language developers at SMI realized that they could come up with a really cool browser by putting their technology to work inside it. So they did. Patrick Naughton and Jonathan Payne built the actual browser and it evolved into the 'HotJava Browser'. It was written in Java to show off its capabilities and the power of what we now refer to as 'applets'. This 'proof of technology' exhibited at SunWorld in May 1995, and quite suddenly interest in Java mushroomed.

In January 1996, Netscape 2.0 was released, Java enabled. And from then on everyone followed suit. Microsoft was not to be left behind, but did not follow the general consensus and came up with its own implementation (it later distanced itself from Java, preferring to create its own parallel technologies).

The first version of Java as a programming language and development kit was released by Sun Microsystems later in 1996 and was quickly followed by 1.02 after just a couple of months. However, Java was not yet ready for prime time, although at the JavaOne conference that year Sun came out with a clear vision for the future.

However, it took almost two more years to get it to perform adequately and deliver on the promise of 'write once, run anywhere'. The collaboration with Netscape continued, with Netscape helping to write the Swing GUI packages.

The release of Java 1.2 in 1998 at the JavaOne conference was the breakthrough. It was amazing, though people were still skeptical, how in such a short span of time so much had been achieved. Java transformed from early toy-like GUI and graphics toolkits into a sophisticated language with a comprehensive library. Java had finally arrived.

 

Java Today

Java's goals from the beginning were to be small, fast, efficient, and easily portable to a wide range of hardware devices. It is these same goals that made Java an ideal language for distributing executable programs via the World Wide Web, and also a general-purpose programming language for developing programs that are easily usable and portable across different platforms. This is the major reason why Java is said to be the most successful platform independent language.

Java as a language has significant advantages over other languages and other programming environments that make it suitable for just about any programming task. Some of them are listed below.


Platform Independence

Platform independence is one of the most significant advantages that Java has over other programming languages, particularly for systems that need to work on many different platforms. Java is platform-independent at both the source and the binary level. Platform-independence is a program's capability of moving easily from one computer system to another.

Java binary files called byte-codes are also platform-independent and can run on multiple platforms without the need to recompile the source. Byte-codes are a set of instructions that look a lot like machine code, but are not specific to any one processor. Because of them, compilation happens just once; interpretation occurs each time the program is executed. Java byte-codes help make "write once, run anywhere" possible. More on this later.


Simplicity

In addition to its portability and object-orientation, one of Java's initial design goals was to be small and simple, and therefore easier to write, easier to compile, easier to debug, and, best of all, easier to learn. Keeping the language small also makes it more robust because there are fewer chances for programmers to make difficult-to-find mistakes.

Despite its size and simple design, however, Java still has a great deal of power and flexibility. Although it has grown to have a large API, at its core it has maintained a simplicity and robustness.


The Better Cousin of C and C++

Java is partly modeled after C and C++, and much of the syntax and object-oriented structure is borrowed from the latter. If you are familiar with C++, learning Java will be particularly easy for you, because you have most of the foundation already.

However, although Java looks similar to C and C++, most of the more complex parts of those languages have been excluded from Java, making the language simpler without sacrificing much of its power. There are no pointers in Java. Nor is there pointer arithmetic. Strings and arrays are real objects in Java. Memory management is automatic. To an experienced programmer, these omissions may be difficult to get used to, but to beginners or programmers who have worked little in other languages, they make the Java language far easier to learn.


An Object Oriented Programming Model

Java is object-oriented, which is a way of organizing programs into flexible, modular units that facilitates code reuse. Like most object-oriented programming languages, Java includes a set of class libraries that provide basic data types, system input and output capabilities, and other utility functions. Because these class libraries are written in Java, they are portable across platforms as are all Java applications.


Applets

Applets appear in a Web page much in the same way as images do, but unlike images, applets are dynamic and interactive. Applets can be used to create animations, figures, or areas that can respond to input from the reader, games, or other interactive effects on the same Web pages among the text and graphics. Java enabled browsers can successfully run applets and thus give a truly rich experience at the user end.

 

Servlets

The most common types of programs written in the Java programming language are applets and applications. If you've surfed the Web, you're probably already familiar with applets. An applet is a program that adheres to certain conventions that allow it to run within a Java-enabled browser.

An application is a standalone program that runs directly on the Java platform. A special kind of application, known as a 'server', serves and supports clients on a network. Examples of servers are Web servers, proxy servers, mail servers, and print servers.

Another specialized program is a servlet. A servlet can almost be thought of as an applet that runs on the server side. Java Servlets are a popular choice for building interactive web applications, replacing the use of CGI scripts. Servlets are similar to applets in that they are runtime extensions of applications. Instead of working in browsers, though, servlets run within Java Web servers, configuring or tailoring the server.

 

The Java platform provides all the essentials:

  • Objects, strings, threads, numbers, input and output, data structures, and system properties.

  • Both low and high level security, including electronic signatures, public and private key management, access control, and certificates are also provided by the Java platform.

  • Networking management, Java Database Connectivity (JDBC), and Remote Method Invocation (RMI) and other features.

It was, or at least used to be, said that Java is slow. However, the introduction of JIT ('Just In Time') technology in the Java interpreter has helped close the gap on fully compiled languages. In reality, most programs spend most time waiting for user input.

Although Java will not be first choice for situations requiring large-scale, real-time computation, for most applications Java is a very good choice. Its robustness, being less prone to programming errors, and being easier to write and maintain, give Java the speed advantage when it comes to software development.

So, from small beginnings, Java has evolved to become a multi-purpose language that has grown to ever greater popularity - and for good reasons.

Computer programming is not an easy, run-of-the-mill task. One needs a special aptitude to do it. You may not be required to know every class and method listed in the Java Application Programming Interface, but you do need to know some basic ones in order to put Java to real work. You will also need to know the syntax of Java and also an understanding both of object oriented design and good programming practice. TJI's guide will help you with all that.

 

NOTE : This document was partly based on articles by Deepak Chandrasekaran and Neeraj Mathur.


Return to index