Java language. Introduction.

For a long time, it was difficult to imagine a computer magazine without an article devoted to the Java language. Even such popular newspapers and magazines as The New York Times, The Washington Post and Business Week wrote about him.

It's impossible to remember National Public Radio ever devoting a ten-minute program to a programming language. Whether this is good or bad depends on your point of view. A $100 million investment in production software created using a specific programming language?! Television companies CNN, CNBC and other media only talked, and are still talking, about how the Java language can and will do this.

However, this book is intended for serious programmers, and since Java is a serious programming language, we have a lot to cover. So, we will not dive into the analysis of advertising promises and try to find out what is true and what is fiction. Instead, we will describe the Java language in some detail as a programming language (including, of course, the features that allow it to be used for working on the Internet, which, in fact, caused so much advertising hype). After that, we'll try to separate reality from fantasy by explaining what the Java language can actually do and what it can't.

At first, there was an abyss between advertising promises and the real capabilities of the Java language. As it matured, the technology became more stable and reliable, and expectations dropped to reasonable levels. The Java language is now increasingly being used to create "middleware" that supports communication between clients and server resources (such as databases).

Although these important applications are not amazing, this is where Java has proven to be most useful due to its machine independence, multi-threading, and network programming capabilities. In addition, the Java language has taken the lead in the field of embedded systems, becoming the de facto standard portable devices, virtual kiosks, on-board car computers, etc. However, the first attempts to rewrite widespread programs for personal computers in Java were not successful - the resulting applications turned out to be low-power and slow. With the advent of the new version, some of these problems were solved, but it must still be recognized that users, in general, do not care at all what language the programs they purchase are written in. We believe that the main benefits of the Java language will come from creating new kinds of devices and applications, rather than from rewriting existing programs.

Java language as a programming tool

As a programming language, Java has delivered on its advertising promises. Without a doubt this is one of the best languages, accessible to serious programmers. Java has the potential to become a great programming language, but it's probably too late now. When appears new language programming, the unpleasant problem of its compatibility with software created earlier immediately arises. Moreover, even if changes can be made to these programs without interfering with their text, it is difficult for the creators of a language that is so warmly welcomed by the public, such as Java, to say outright: “Yes, we may have made a mistake in developing version X, but version Y will be better." As a result, while awaiting further improvements, we must state that the structure of the Java language will not change significantly in the near future.

The obvious question is: " How did you improve the Java language?"It turns out that this was done not by improving the programming language itself, but by fundamentally changing the libraries of programs written in the Java language. Sun Microsystems changed everything: starting with the names of individual library functions (making them more meaningful) and the way graphics modules work ( changing the way it handles events and partially rewriting worker programs), and ending with the creation of new language features, such as printing facilities, that were not present in Java 1.0. The result was a much more useful software platform than all previous versions Java language.

Microsoft has released its own product called J++, related to the Java language. The J++ language is interpreted by a virtual machine compatible with the Java Virtual Machine when executing bytecode, but the interfaces with external code differ significantly between these languages. J++ and Java languages ​​have almost the same syntax. However, Microsoft has created additional language constructs. All of them are of rather dubious value, with the exception of the interface Windows API. In addition to the fact that these languages ​​have the same syntax, their core libraries (strings, utilities, network programming tools, multithreading tools, math libraries, etc.) are essentially the same.

However, the graphics libraries, user interface, and access to remote objects are completely different between these languages. Currently, Microsoft no longer supports the J++ language, having developed a new language, C#, which has many similarities with Java, but uses a different virtual machine. This book does not cover either the J++ language or the C# language.

Benefits of the Java Language

1) One of the main advantages of the Java language is independence from the platform on which programs are executed: the same code can be run under operating systems Windows, Solaris, Linux, Machintosh, etc.
This is really necessary when programs are downloaded over the Internet for later execution under different operating systems.

2) Another advantage is that The syntax of the Java language is similar to the syntax of the C++ language, and programmers those who know languages C and C++, learning it is easy. True, for programmers who speak Visual Basic, this syntax may be unusual.

If you have never programmed in C++, some of the terms used in this section will not be clear to you. In this case, you can skip it. By the time you get to the end of Chapter 6, these terms will become familiar to you.

3) Also, Java - a fully object-oriented language, even more so than C++. All entities in the Java language are objects, with the exception of a few primitive types, such as numbers. (Because object-oriented programming is easy to develop complex projects, it has replaced the older structured programming. If you're new to object-oriented programming, Chapters 3-6 will give you everything you need to know about it.)

However, developing another, slightly improved, dialect of the C++ language is not enough. Crucially, it is easier to develop error-free programs in Java than in C++. Why? The developers of the Java language spent a long time wondering why programs written in C++ were so error-prone. They provided the Java language with tools to eliminate the very possibility of creating programs that would hide the most common errors. To do this, the following is done in the Java language.

4) The possibility of explicitly allocating and freeing memory is excluded.
Memory in Java is freed automatically using the garbage collection mechanism. The programmer is guaranteed against errors related to improper use of memory.

5) True arrays were introduced and pointer arithmetic was prohibited.
Now programmers in principle cannot erase data from memory due to incorrect use of pointers.

6) The possibility of confusing the assignment operator with the equality comparison operator has been eliminated.
Now you can't even compile the if(ntries = 3) statement. . . (Visual Basic programmers may not notice any problem here at all, since this error is the source of most confusion in C and C++).

7) Multiple inheritance is excluded. It has been replaced by a new concept - an interface, borrowed from the Objective C language.
The interface gives the programmer almost everything he can get from multiple inheritance, while avoiding the complexities that arise when managing class hierarchies.

Features of the Java Language

Simple
Interpretable
Distributed
Reliable
Safe
Machine independent
Object-oriented
High performance
Multithreaded
Dynamic
Independent of computer architecture

We already touched on some of these points in the last section. In this section we will: provide quotes from the Java language manual that reveal the features of the language; We will share with readers our thoughts on individual properties of language, based on own experience working with its latest version.

Simple

We wanted to create a system that is easy to program, does not require additional training and takes into account established programming practices and standards. Therefore, although we considered C++ unsuitable for these purposes, Java was designed to be as similar as possible to make the system more accessible. Java lacks many of the lesser-used, obscure, and obscure features of C++ that we believe do more harm than good.

Java syntax is essentially a distilled version of C++ syntax. This language does not have header files, pointer arithmetic (and pointers themselves), structures, unions, operator overloading, virtual base classes, etc. (The differences between Java and C++ are described in notes on the C++ language scattered throughout the book.) However, the developers did not try to correct all the shortcomings of the C++ language.

For example, the syntax of the switch statement in Java remains unchanged. Knowing the C++ language, it will be easy to move on to the Java syntax.
If you typically use a visual programming environment (such as Visual Basic), you may find Java difficult.
Its syntax often looks quite strange (although it is not difficult to understand the meaning of the expression). More importantly, there is a lot more programming involved when working in Java. The beauty of Visual Basic is that its visual programming environment allows you to create application infrastructure almost automatically. Achieving the same result using Java requires programming by hand, but produces much shorter programs.

There is, however, a third type of programming environment that allows you to create programs using drag-and-drop technology.

Another aspect of simplicity is brevity. One of the goals of the Java language is to enable the development of programs that can be run completely independently on small machines. The size of the main interpreter and class support is about 40 KB; standard libraries and thread support (especially the self-contained microkernel) take up another 17:KB.
This is a huge success. Note, however, that the GUI support libraries are much larger.

Object-oriented

Simply put, object-oriented programming is a programming method that focuses on data (i.e. objects) and the means to access them. To use a carpentry analogy, the object-oriented craftsman is primarily focused on the chair he is making and only secondarily concerned with the tools needed to make it; at the same time, a non-object-oriented carpenter thinks only about his tools. The object-oriented properties of Java and C++ are essentially the same.

Object orientation has already proven its value over the past 30 years, and it is impossible to imagine a modern programming language without it. Indeed, the object-oriented features of the Java language are comparable to the C++ language. The main difference between them is the multiple inheritance mechanism, for which the Java language has The best decision, as well as in the metaclass model of the Java language.

Reflection (Chapter 5) and object serialization (Chapter 12) provide durable objects and tools for creating graphical user interfaces from ready-made components.

If you've never programmed in an object-oriented language, read Chapters 4-6 carefully. These chapters introduce the fundamentals of object-oriented programming and show its advantages over traditional, procedure-oriented languages ​​such as C or Basic when developing complex projects.

Distributed

Java has a large library of programs for transferring data based on TCP/IP (Transmission Control Protocol/Internet Protocol), such as HTTP (Hypertext Transfer Protocol) or FTP (File Transfer Protocol). file transfer protocol). Applications written in Java can open and access objects over the network using andURLs (Uniform Resource Location) are as easy as local network.

The Java language provides powerful and convenient tools for networking. Anyone who has ever tried to write programs for the Internet in other languages ​​will be pleasantly surprised by how easily the most difficult tasks, for example, opening network connections (sockets), are solved in Java. An elegant mechanism consisting of so-called servlets makes the work on the server extremely efficient.

Servlets are supported by many popular Web servers. (Networking will be covered in Volume 2.) Communication between distributed objects in Java is provided by the calling mechanism remote methods(this topic is also covered in the second volume).

Reliable

The Java language is designed to create programs that should work reliably in any situation. The main focus of Java is on early detection of possible errors, dynamic checking (during program execution), and elimination of error-prone situations... The only significant difference between Java and C++ is the pointer model adopted in Java, which eliminates the possibility of overwriting a memory section and damaging data.

This property is also very useful. The Java language compiler detects errors that in other languages ​​are detected only during program execution. In addition, programmers who have spent many hours searching for a bug that caused memory corruption due to an invalid pointer will be very glad to know that such problems cannot arise in principle in the Java language.

If you've previously programmed in Visual Basic or COBOL, which don't explicitly use pointers, you may not understand why this is so important. C programmers are much less fortunate. They need pointers to access strings, arrays, objects, and even files. When programming in Visual Basic, none of this is required, and the programmer does not have to worry about allocating memory for these entities. On the other hand, many data structures are very difficult to implement in a language without pointers. For regular structures like strings and arrays, pointers are not needed. The full power of pointers only comes into play when you can't do without them, for example, when creating linked lists. A Java programmer is forever free from bad pointers, bad allocations, and memory leaks.

Safe

The Java language is designed for use in a networked or distributed environment. For this reason, much attention was paid to safety. The Java language allows you to create systems that are protected from viruses and outside interference.

In the first edition we wrote: “Never say never,” and we were right. A group of security experts from Princeton University discovered the first security flaws in Java 1.0 shortly after the first version of the suite went on sale. tools JDK. Moreover, they and other specialists continued to subsequently find more and more new errors in the security mechanisms of all subsequent versions of the Java language.

The positive side to this situation is that the Java language team has declared that they have zero tolerance for any security bugs and have immediately begun fixing any problems found in the applet security mechanism. In particular, by publishing the internal specifications of the Java language interpreter, Sun made it much easier to find hidden security bugs and attracted independent experts to find them.

This increased the likelihood that any errors in the security system would be discovered soon. In any case, it is extremely difficult to defeat the Java language security system. The bugs discovered so far have been almost subtle, and their number is (relatively) small.

Sun's security web page has the following URL: http://java.sun.com/sfaq/.

Let's list some situations that are prevented by the Java language security system.

1) Stack overflow of an executable program, which was caused by the notorious "worm" that spread on the Internet.

2) Damage to memory areas located outside the space allocated to the process.

3) Reading and writing local files when using a secure class loader, such as a Web browser, that prohibits such file access.

All of these safety measures are appropriate and usually work flawlessly, but it never hurts to be cautious. Although the bugs discovered so far have been far from trivial, and the details of their discovery are often kept secret, it must be recognized that it is probably still impossible to prove the security of the Java language.

Over time, new protections were added to the language. Starting with version 1.1, the Java language introduced the concept of digitally signed classes. By using a digitally signed class, you can be sure of its author. If you trust it, you can grant this class all the privileges available on your machine.

An alternative code delivery mechanism proposed by Microsoft relies on ActiveX technology and uses only digital signatures for security. Obviously, this is not enough; any user of Microsoft software can confirm that the programs are widely famous manufacturers often terminate abnormally, thereby creating the risk of data corruption. Java security is much stronger than ActiveX technology because it controls the application from the moment it is launched and prevents it from causing damage.

Architecture independent

The compiler generates an object file, the format of which does not depend on the computer architecture - the compiled program can be executed on any processors controlled by the Java program execution system. To do this, the Java language compiler generates bytecode commands that are independent of the specific computer architecture. The bytecode is designed in such a way that it can be easily interpreted on any machine or translated into machine dependent code on the fly.

This is not a new idea. More than 20 years ago and in the implementation system Pascal language, developed by Niclaus Wirth, and the UCSD Pascal system used the same technology. Using bytecodes gives a big gain in program execution (although synchronous compilation in many cases compensates for this). The Java language developers have done a great job of developing a set of bytecode commands that work great on most computers. modern computers, easily translating into real machine commands.

Machine independent

Unlike C and C++, the Java specification does not have implementation-specific aspects. Both the size of the main data types, and arithmetic operations above them are precisely defined.

For example, the int type in Java always means a 32-bit integer. In the C and C++ languages, the int type can mean either a 16-bit or a 32-bit integer, as well as an integer of arbitrary size, at the choice of the developer of a particular compiler. The only limitation is that the size of an int type cannot be less than the size of a short int type and greater than the size of a long int type. The fixed size of numeric types avoids many of the hassles associated with running programs on different computers. Binary data is stored and transmitted in a fixed format, which also avoids misunderstandings associated with different byte order on different platforms ("big endian/little endian" conflict). Rows are stored in standard format Unicode.

Libraries, which are part of the system, define a machine-independent interface. For example, the language provides an abstract Window class and its implementations for Unix, Windows, and Macintosh operating systems.

Anyone who has ever tried to write a program that runs equally well on Windows, Macintosh, and ten flavors of Unix knows that it is a very difficult task. The Java version made a valiant attempt to solve this problem by providing a simple toolkit that adapts common user interface elements to a wide variety of software platforms. Unfortunately, the library, which took a lot of work, did not achieve acceptable results on different platforms. (At the same time, on different platforms in graphics programs various errors appeared.)

However, this was just the beginning. In many applications, machine independence is much more important than the sophistication of a graphical user interface. These are the applications that benefited from the release of Java 1.0. However, the GUI toolkit has now been completely redesigned and is no longer dependent on the user interface on the host computer. The new version is more meaningful and, in our opinion, more attractive to the user than the previous ones.

Interpretable

The Java language interpreter can be sent to any machine and execute bytecode directly on it. Because editing links is an easier process, program development can become much faster and more efficient.

This may be an advantage when developing applications, but the above quote is a clear exaggeration. In any case, the Java compiler included in the JSDK (Java Software Development Kit) is quite slow. (Some third-class compilers, such as those from IBM, are much faster.) Recompilation speed is just one factor in the efficiency of a programming environment. When you compare the speed of the Java and Visual Basic programming environments, you may be disappointed.

High performance

While generally interpreted bytecodes have more than adequate performance, there are situations in which even greater efficiency is required. Bytecodes can be translated on the fly (during runtime) into machine codes for the specific processor on which the application is running.

If you use an interpreter to execute bytecodes, you should not use the phrase "high performance." However, on many platforms another type of compilation is possible, provided by just-in-time compilers (JIT). They translate bytecode into native code, store the result in memory, and then call it when needed. Since the interpretation is performed only once, this approach increases the speed many times over.

Although synchronous compilers are still slower than machine-dependent compilers, they are in any case much faster than interpreters, providing 10- and even 20-fold speedups for some programs. This technology is constantly improving and may eventually reach speeds that traditional compilers will never surpass. For example, a synchronous compiler can determine which piece of code is executed more often and optimize it for execution speed.

MULTI-THREADED

Provides better interactivity and program execution.

If you've ever tried to implement multithreaded computing in any other programming language, you'll be pleasantly surprised at how easy it is to do it in Java. Threads in Java can take advantage of multiprocessor systems if the operating system allows it. Unfortunately, thread implementations on most platforms vary greatly, and the Java language designers make no attempt to achieve uniformity. Only the code for calling threads remains the same for all machines; The Java language defers the implementation of multithreading to the underlying operating system or threading library. (Threads are covered in Volume 2.) Despite this, it is the ease of multi-threaded computing that makes Java so attractive for developing server software.

Dynamic

In many ways, the Java language is more dynamic than C or C++. It has been designed to easily adapt to an ever-changing environment. New methods and objects can be freely added to libraries without causing any harm. The Java language makes it easy to obtain information about the progress of a program.

This is very important in cases where you need to add code to a program that is already running. A prime example of this is code that is downloaded from the Internet to be executed by the browser. In Java 1.0, it was not easy to obtain information about the progress of a running program, but the current version of the Java language reveals to the programmer both the structure and behavior of the objects of the running program.
This is very valuable for systems that must parse objects during program execution. These systems include graphical user interface tools, intelligent debuggers, plug-in components, and object databases.

Java and the Internet

The idea is simple - users download Java bytecodes from the Internet and execute them on their machines. Java programs that run under Web browsers are called applets. To use the applet, you need a Web browser that supports the Java language and can interpret bytecodes. The source code for the Java language is licensed to Sun, which insists that both the language itself and the structure of its core libraries remain unchanged. Unfortunately, in reality everything is not like that. Different versions of Netscape and Internet Explorer browsers support different versions Java language, and some of these versions are significantly outdated. This unfortunate situation creates increasing obstacles in the development of applets that take advantage of latest version Java language. To solve this problem, Sun developed the Java Plug-in, which provides the most advanced environment for running Java programs in the Netscape and Internet Explorer browsers.

Loading an applet is like embedding an image into a Web page. The applet becomes part of the page, and the text flows around the space it occupies. However, the difference is that the image is now alive. It responds to user commands, changes its appearance and ensures the transfer of data between the computer on which the applet is viewed and the computer that controls this applet.

Loading an applet is like inserting a picture into a Web page. The applet becomes part of the page, and the text flows around the space it occupies. The point is that the image is “live”. It responds to user commands, changes its appearance, and transfers data between the computer running the applet and the computer that controls the applet.

In Fig. 1.1 shown good example a dynamic Web page that performs complex calculations and uses an applet to display molecules. To better understand the structure of a molecule, you can rotate it or zoom in using the mouse. Such manipulations cannot be implemented on static Web pages, however applets make this possible. (This applet can be found at http://jmol.sourceforge.net.)

Rice. 1.1. Applet Jmol

Using applets, you can add new buttons and text fields to a Web page. However, such applets are slow to load over a phone line.

Almost the same thing can be done using Dynamic HTML, forms of HTML (Hypertext Markup Language), or a scripting language such as JavaScript. Of course, the first applets were intended for animation: spinning globes, dancing cartoon characters, fancy text, etc. However, animated GIFs can do most of the same, and Dynamic HTML, combined with scripting, does much more than applets.

As a result of browser incompatibilities and inconsistent loading processes over slow network connections, applets designed for Web pages were not a huge advance. In local networks (intranets) the situation is completely different. They usually do not have problems associated with throughput channel, so loading time for applets is insignificant. On the local network, you can select the desired browser or use the Java Plug-In program. Employees can't move network-delivered software to the wrong location or install it incorrectly, and the system administrator doesn't have to go around all the client machines and update the software on them. A large number of programs designed for inventory accounting, vacation planning, travel reimbursement, and the like have been developed by many corporations in the form of applets using browsers.

While we were writing the book, the pendulum swung again from client programs towards server-side programming. In particular, application servers can use the monitoring capabilities of the Java virtual machine to automatically load balance, merge database connections, synchronize objects, secure shutdown and reboot, and perform other processes required for scalable server applications. which are almost impossible to implement correctly. Thus, programmers creating applications were able to buy these complex mechanisms instead of developing them themselves. This increased the productivity of programmers - they focused on the logic of their programs, without being distracted by details related to the operation of servers.

What do ordinary users of personal computers and the Internet know about Java? What do developers who are not involved in this technology professionally say about it?

Java is widely known as the latest object-oriented language that is easy to learn and allows you to create programs that can be executed on any platform without any modifications (cross-platform). For some reason, the topic of coffee is always connected with Java (images of logos, names of products, etc.). Programmers can add to this description that the language is similar to a simplified C or C++ with the addition of a garbage collector - an automatic garbage collector (a mechanism for freeing memory that is no longer used by the program). Java is also known to be Internet-oriented. and its most common application is small programs, applets, that run in the browser and are part of HTML pages.

Critics, in turn, argue that the language is not at all so easy to use, many wonderful properties are only stated, but in fact do not really work, and most importantly, Java programs execute extremely slowly. Therefore, it is just some kind of fashionable technology that will only attract attention for a while and then disappear, like many others.

However, some facts do not allow us to agree with such an assessment. Firstly, a lot of time has passed since the official announcement of Java for “just a fashionable technology”. Secondly, the Java One Developers Conference, which was first organized in 1996, within a year attracted more than 10,000 participants and became the largest software conference in the world (each subsequent year the number of participants grew by approximately 5,000). Special program Sun's worldwide Java Developer Connection, also launched in 1996, had over 100,000 developers a year later and over 1.5 million in 2000. Today, the number of Java programmers is estimated at 3 million.

Five major versions of the language were released, starting with 1.0 in 1995 and ending with 1.4 in February 2002. The next version 1.5 was released in 2004. All versions and documentation for them have always been available for free on the official Java website http://java.sun.com/. One of the first Java products, JDK 1.1 (Java Development Tool), was downloaded more than 220,000 times within the first three weeks of its announcement. Version 1.4 was downloaded over 2 million times in the first 5 months. Almost all leading software manufacturers have licensed Java technology and regularly announce the release of products built on it. This is the “blue giant” IBM, and the creator of the Macintosh platform, Apple, and the leader in the field of relational databases, Oracle, and even the main competitor of Sun, Microsoft Corporation, which licensed Java back in March 1996.

The next section describes a brief history of the origins and development of the ideas that led to the emergence of Java, which will help you understand what this technology actually is, what its properties and distinctive features, what it is intended for and where such a variety of opinions about it came from.

History of Java

If you search the Internet for the history of the creation of Java, it turns out that the language was originally called OaK (“oak”), and work on its creation began back in 1990 with a rather scandalous story within the Sun Corporation. These facts are true, but in reality everything was even more interesting.

Complexities within Sun Microsystems

Indeed, events begin to unfold in December 1990, when the rapid development of WWW ( World Wide Web - "World Wide Web") no one could even predict. Back then, the computer industry was consumed by the rise of personal computers. Unfortunately, Sun Microsystems, which occupies a significant share of the market for servers and high-performance stations, according to many employees and independent experts, could not offer anything interesting for ordinary users of personal computers - for them, computers from Sun seemed "too complex, very ugly and too "dumb" devices."

So Scott McNealy, board member, president and CEO of Sun Corporation, was not surprised when 25-year-old well-established programmer Patrick Naughton, after only 3 years on the job, announced his desire to go to NeXT. They were friends, and Patrick explained his decision simply and briefly: “They are doing everything right.” Scott thought for a second and said the historical phrase. He asked Patrick before he left to describe what he thought Sun was doing wrong. It was necessary not only to talk about the problem, but to offer a solution, without looking back at existing rules and traditions, as if he had unlimited resources and opportunities at his disposal.

Patrick Naughton complied with the request. He mercilessly criticized the new NeWS software architecture the firm was working on at the time, and also praised the newly announced NeXTstep operating system. Naughton suggested bringing in professional graphic designers to make Sun's user interfaces more attractive; choose one development tool and concentrate efforts on one window technology, rather than on several at once (Naughton was forced to support hundreds of different combinations of technologies, platforms and interfaces used in the company); finally, dismiss almost all employees from Window Systems Group (if the previous conditions are met, they will simply not be needed).

Of course, Naughton was sure that his letter would simply be ignored, but he still postponed his move to NeXT in anticipation of some kind of response. However, she exceeded all expectations.

McNeely sent Naughton's letter to the entire management team of the corporation, and they forwarded it to their leading specialists. Literally everyone responded, and general opinion, Naughton described what everyone was thinking but were afraid to say. The support of Bill Joy and James Gosling was decisive. Bill Joy is one of the founders and vice president of Sun, as well as a participant in the project to create operating system UNIX at the University of Berkeley. James Gosling joined Sun in 1984 (he had previously worked at the IBM Research Laboratory) and was the lead developer and author of the first implementation of the EMACS text editor in C. These people had enormous authority in the corporation.

Not to stop there, Naughton decided to propose some completely new project. He teamed up with a group of technicians and they sat until 4:30 a.m. discussing the basic concepts of such a project. There were only three of them: the main thing is the consumer, and everything is built exclusively in accordance with his interests; a small team must design a small hardware and software platform; this platform needs to be implemented in a device intended for personal use, convenient and easy to use - i.e. create a computer for ordinary people. These ideas were enough for John Gage, Sun's head of research, to make a presentation to the corporation's top management. Naughton outlined the conditions that he considered necessary for the successful development of this enterprise: the team should be located outside the Sun office so as not to experience any resistance to revolutionary ideas; the project will be secret to everyone except Sun's senior management; hardware and software platforms may not be compatible with Sun products; The group needs a million dollars for the first year.

Project Green

On December 5, 1990, the day Naughton was scheduled to join NeXT, Sun made him a counteroffer. The management agreed to all its terms. The goal is to “create something extraordinary.” On February 1, 1991, Patrick Naughton, James Gosling and Mike Sheridan began to implement the project, which was called Green.

They chose an ambitious goal - to find out what the next wave of development of the computer industry will be (the appearance of semiconductors and personal computers is considered the first) and what products need to be developed to successfully participate in it. From the very beginning, the project was not considered as a purely research project; the task was to create a real product, a device.

At the Sun's annual meeting in the spring of 1991, Gosling noted that computer chips had become incredibly common, being used in VCRs, toasters, even hotel doorknobs! However, up to three remote controls can still be seen in every home remote control- for TV, VCR and music center. Thus was born the idea to develop a small device with a liquid crystal touch screen, which will interact with the user through animation, showing what can be controlled and how. To create such a device, Naughton began working on a specialized graphic system, Gosling took on the software, and Sheridan took care of business issues.

In April 1991, the team left the Sun office, disconnecting even from the corporation's internal network, and moved into new premises. A variety of consumer electronic devices such as Nintendo game consoles, set-top boxes, remote controls are purchased, and developers play various games all day long to better understand how to make the user interface easy to understand and use. As a perfect example, Gosling noted that modern microprocessor toasters have exactly the same interface as his mother's toaster, which has been in service for 42 years. Very quickly, researchers discovered that almost all devices were built on a variety of central processors. This means that adding new functionality extremely difficult, since it is necessary to take into account the limitations and, as a rule, rather meager capabilities of the chips used. When Gosling attended a concert, where he was able to observe with his own eyes the complex interweaving of wires, a huge number of speakers and semi-automatic spotlights that seemed to move in concert to the beat of the music, he realized that the future lies in the unification of networks, computers and other electronic devices into a single consistent infrastructure.

Gosling first tried to modify C++ to create a language for writing programs that were minimally platform-specific. However, it soon became clear that this was practically impossible. The main advantage of C++ is the speed of programs, but not their reliability. And the reliability of operation for ordinary users should be as absolutely guaranteed as the compatibility of ordinary electrical plugs and sockets. So in June 1991, Gosling, who wrote his first programming language at age 14, began developing a replacement for C++. While creating a new catalog and wondering what to call it, he looked out the window and his gaze stopped at the tree growing below him. This is how the language got its first name - OaK (oak). A few years later, after marketing research, the name was changed to Java.

It only took a few months to get development to the stage where it was possible to combine the new language with the graphics system Naughton was working on. Already in August, the team was able to launch the first programs demonstrating the capabilities of the future device.


The device itself, according to the creators, was supposed to be the size of a regular remote control, run on batteries, have an attractive and funny graphical interface and, in the end, become a favorite (and useful!) home toy. To build this unique device, resourceful developers used “hammer technology.” They simply found some device that had suitable parts or microcircuits, smashed it with a hammer and thus obtained the necessary parts. This is how the main LCD screen, touch screen and miniature built-in speakers were obtained. CPU and motherboard were specifically designed based on the high-performance Sun workstation. An original name was also invented - *7, or Star7 (using this combination of buttons, one could answer a call from any other phone from any device in the office, and since rarely any of them could be found at work, these words were very often shouted loudly for the entire office). To make the interface more attractive, the developers created a funny character named Duke, who was always ready to help the user complete his task. Later he became a Java companion, a lucky talisman - he can be found in many documents, articles, and code examples.

The task was completely new, there was nothing to rely on, there was no experience, no preliminary developments. The team worked without stopping for a single day. In August 1991, the first demonstration took place for Bill Joy and Scott McNealy. In November the group reconnected to Sun's network via a modem line. The further the project developed, the more new specialists joined the development team. Around that time, a name was invented for the ideology that they were creating - 1st Person (can be roughly translated as “first person”).

Finally, on September 4, 1992, Star7 was completed and demonstrated to McNealy. It was a small device with a 5" color (16-bit) touch screen, without a single button. To turn it on, you just had to touch the screen. The entire interface was built like a cartoon - no menus! Duke moved through the rooms of a drawn house, and to control All they had to do was move their finger across the screen - no special controls.You could take a virtual TV program from a drawn sofa, select a program and "drag" it onto the VCR image to program it to record.

The result exceeded all expectations! It is worth recalling that devices such as pocket computers (PDAs), starting with the Newton, appeared much later, not to mention the color screen. This was the time of the 286i and 386i Intel processors(486i had already appeared, but were very expensive) and MS DOS, even a mouse was not yet a mandatory attribute of a personal computer.

Sun executives were simply delighted - they had an excellent weapon against such powerful competitors as HP, IBM and Microsoft. The new technology was capable of not only showing cartoons. The object-oriented language OaK promised to be a fairly powerful tool for writing programs that could run in a networked environment. Its objects, freely distributed over the Internet, would work on any device, from a personal computer to ordinary household VCRs and toasters. At the presentations, Naughton presented applications of OaK, depicting home computers, cars, phones, televisions, banks and connecting them single network. An entire application, for example, for working with email, could be built as a group of such objects, and they did not necessarily have to be located on the same device. Moreover, as a language focused on a distributed architecture, OaK had security mechanisms, encryption, authentication procedures, and all these capabilities were built-in, and therefore invisible and user-friendly.

FirstPerson Company

Large manufacturing companies such as Mitsubishi Electric, France Telecom, Dolby Labs became interested in the new technology, and negotiations began. Sheridan prepared a business plan with the original title “Beyond the Green Door,” in which he proposed that Sun establish a subsidiary to promote the OaK platform to the market. On November 1, 1992, FirstPerson was created, headed by Wayne Rosing, who moved from Sun Labs. A luxurious office is rented, the number of employees increases from 14 to 60 people.

However, it later turned out that the cost of such a solution (processor, memory, screen) was at least $50. Manufacturers household appliances are not accustomed to paying significant sums for additional functionality that makes their products easier to use.

At this time, the computer industry's attention is captured by the idea of ​​interactive television, and there is a feeling that it will be the next revolutionary breakthrough. So when, in March 1993, Time Warner announced a competition for set-top box makers to deploy a pilot interactive television network, FirstPerson turned its attention entirely to the task. And again failure - the winner is James Clark, founder of Silicon Graphics Inc., despite the fact that his proposal is technologically inferior to OaK. However, a year later the project of Time Warner and SGI fails, and James Clark creates the Netscape company, which will still play an important role in the success of Java.

Another potential client was the manufacturer of game consoles 3DO. It took only 10 days to import OaK onto this platform, but after three months of negotiations, the director of 3DO demanded full rights to the new product, and the deal fell through.

Finally, in early 1994, it became clear that the idea of ​​interactive television was not viable. Expectations were not destined to become reality. An analysis of FirstPerson's status showed that the company does not have a single client or partner and its future prospects are rather vague. Sun management is demanding an immediate new business plan that will allow the company to become profitable again.

World Wide Web

In pursuit of the ghost of interactive television, many participants in the computer market missed a truly epoch-making event. In April 1993, Marc Andreessen and Eric Bina, working at the National Center for Supercomputing Applications (NCSA) at the University of Illinois, released the first version of the graphical browser ("browser") Mosaic 1.0 for www. Although the Internet had existed at that time for about 20 years, the existing communication protocols (FTP, telnet, etc.) were very inconvenient to use and the Global Network was used only in academic and government environments. Mosaic was based on a new markup language for hypertext documents (HyperText Markup Language, HTML), which since 1991 has been developed at the European Institute of Particle Physics (CERN) specifically for presenting information on the Internet. This format made it possible to view text and images, and most importantly, it supported links, with which you could use one click to go to either another part of the same page or a page that could be located in a completely different part of the network and anywhere on the planet. It was precisely these cross-references, using which the user could visit many Internet nodes unnoticed, that made it possible to count everything HTML documents connected parts of a single whole - the World Wide Web (WWW).

And most importantly, all these new achievements were completely free and available to everyone. For the first time, ordinary users of personal computers without any special training could use the global network not only to solve work issues, but also to search for information on a variety of topics. The number of documents in the WWW space began to grow exponentially, and very soon the Internet became truly World Wide. True, over time it was discovered that this method of organizing and storing information is very reminiscent of a landfill, in which it is extremely difficult to find data on any specific issue, but this topic belongs to a completely different stage of development computer world. So, in some incomprehensible way, the Sun does not notice the birth of a new era. Sun's CTO didn't see Mosaic for the first time until three months later! And this despite the fact that about 50% of servers and workstations in Internet networks were produced by Sun.

FirstPerson's new business plan set a goal that was a kind of intermediate step from interactive television to the capabilities of the Internet. The idea was to create a platform for cable companies, the users of which would be ordinary owners of personal computers, united by the networks of such companies. Using OaK technology, developers could create applications that are similar in functionality to CD-ROM programs, but with interactivity that allows people to share any information over the network. It was expected that such networks would eventually develop into interactive television, and then OaK would become a full-fledged solution for this industry. Not a word has been said about the Internet and Mosaic yet.

For many reasons, this plan did not suit Sun management (it did not quite meet the main expectation - new development should have led to increased demand for Sun products). Due to the lack of prospects, half of FirstPerson employees were transferred to the newly created Sun Interactive team, which continued to work on multimedia services without OaK. The entire enterprise was in danger of dying ignominiously, but at that moment Bill Joy again lent his support to the project, which would soon give the world the Java platform.

When the creators of FirstPerson finally turned their attention to the Internet, they realized that the functionality of the network applications for which OaK was created was very similar to the WWW. Bill Joy recalled how he helped develop UNIX at Berkeley twenty years ago, and how the operating system then became widespread because it could be downloaded online for free. This principle of free distribution of commercial products was created by the WWW itself, in the same way Netscape soon became the leader in the browser market, so many technologies were able to capture market share in the shortest possible time. These new ideas, with the support of Joy, finally convinced Sun management that the Internet would help resurrect the OaK platform (by the way, this new project was initially called "Liveoak"). As a result, Joy sits down to write another business plan and sends Gosling and Naughton to begin work on adapting OaK for the Internet. Gosling revises the platform's code, and Naughton takes on the task of writing a killer application that would immediately demonstrate the full power of OaK for the Internet.

In fact, these technologies fit together perfectly. Programming languages ​​have always played an important role in the development computer technology. Mainframes weren't particularly useful until Cobol came along. Thanks to IBM's Fortran language, computers became widely used for scientific computing and research. Altair BASIC - the very first product from Microsoft - allowed all amateur programmers to create programs for their personal computers. The C++ language became the basis for the development of graphical user interfaces such as Mac OS and Windows. The creators of OaK did everything to ensure that this technology played the same role in programming for the Internet.

Despite the fact that by mid-1994 the WWW had reached unprecedented size (by the standards of that time, of course), web pages were still more like regular paper publications than interactive applications. For the most part, all web work consisted of sending a request to a web server and receiving a response, which contained a regular static HTML file that was rendered by the browser on the client side. Even then, the functionality of web servers was expanded with the help of CGI (Common Gateway Interface). This technology made it possible to run a regular program on the server at a client request and send its result back as a response. Since communication speeds were slow at the time (although it seems that users will never be satisfied with the capabilities of the hardware), the client could wait several minutes just to see a message that he had made a mistake in one letter of the request. Dynamic plotting with this implementation would mean generating GIFs in real time. But often client machines are full-fledged personal computers that could take on a significant part of the user interaction work, relieving the servers.

In general, the client-server architecture, which is simply necessary for most complex corporate (enterprise) applications, has a number of significant technical difficulties. The main idea is to place shared data on a server to create a single information space for the work of many users, and programs that display and allow convenient editing of this data are executed on client machines. Very often, a corporation uses several hardware platforms (this can be either a “historical legacy” or a consequence of the fact that different departments need different computers to solve their problems). Consequently, the application must be developed in several versions at once, which significantly increases the cost of support. In addition, updating the client side means that all the company's computers need to be reconfigured as soon as possible. But updates are often carried out by several groups of developers.

An attempt to give Internet browsers the possibility of a full-fledged client application encounters even greater difficulties. Firstly, the usual difficulties are increasing extremely - almost all existing platforms are represented on the Internet, and the number and geographical distribution of users makes quick updates simply impossible. Secondly, the issue of security is especially acute. Not only does it spread amazingly quickly through the network important information, but also viruses. Text information and images do not pose any threat to the client machine; executable code is another matter. Finally, applications with beautiful and convenient graphical interface, as a rule, were rather large in size; it was not without reason that the main means of their distribution were CD-ROMs. It is clear that for the Internet it was necessary to seriously work on the compactness of the code.

If you look back at the history of the development of OaK, it becomes clear that this platform miraculously meets all the listed requirements for Internet programming, although it was created at a time when no one even thought about the WWW. Apparently, this indicates how correctly the Green project participants predicted the development of the industry.

Revival of OaK

OaK was not enough for a victorious exit finishing touch- a browser that would support this technology. It was this that was supposed to become Naughton’s “killer” application, which completed almost five years of preparatory work before the official announcement of the new platform.

The browser was called WebRunner. Naughton needed only one day off to write the bulk of the program. This was in July, and in September 1994, WebRunner was already demonstrated to Sun management. Small programs written in OaK for distribution over the Internet were called applets.


The next demonstration took place at a conference where Internet application developers and representatives of the entertainment industry met. When Gosling began his presentation of WebRunner, the audience showed little interest, thinking that it was just a clone of Mosaic. Then Gosling moved his mouse over a complex three-dimensional model of a chemical molecule.

Following the cursor, the model turned in all directions! Now this function, may not have the same impact, but at the time it was like the transition from picture to cinema. The following example demonstrated animated sorting. First, a set of segments of different lengths was depicted. Then the blue and red lines began to run across this set, sorting the segments by size. The example is also simple, but clearly demonstrates that a full-fledged software platform has appeared on the client side. Both of these applets are now standard examples and are included in any version of the Java Development Kit. The success of the demonstration, which ended with thunderous applause, showed that OaK and WebRunner are capable of revolutionizing the Internet, as all conference participants took a different look at the opportunities that the World Wide Web provides.

By the way, at the beginning of 1995, when it became clear that the official announcement was just around the corner, marketers got down to business. As a result of their research, OaK was renamed Java, and WebRunner became HotJava. Many then were perplexed as to what was the reason for such a decision. Legend has it that Java is a type of coffee (there really is such a coffee) that programmers loved very much. Apparently, the name HotJava (“hot Java”) was born in a similar way. The theme of coffee will forever remain in names and logos (the technology for creating components is called Java Beans - coffee beans, a special format for archiving files with Java programs JAR - a jar of coffee, etc.), and critics began to call the language itself “for coffee makers” . However, now everyone has become accustomed and does not think about the name, perhaps this was intended (and those who continue to express dissatisfaction are given alternative options, which were considered then - Neon, Lyric, Pepper or Silk).

According to the plan, the Java specification, platform implementation, and HotJava were to be freely distributed over the Internet. On the one hand, this made it possible to quickly spread the technology throughout the world and make it a de facto standard for Internet programming. On the other hand, with the participation of the entire community of developers who would express their comments, it would be possible to eliminate all possible errors and shortcomings much faster. However, by the end of 1994, only a few copies had been distributed outside of Sun. In February 1995, perhaps the first press release was issued, announcing that alpha versions of OaK and WebRunner would soon be available.

When this happened, the team began to count the number of times their product was downloaded for review. Soon we had to count in the hundreds. Then they decided that if they could reach 10,000, it would be a stunning success. We didn't have to wait as long as one might have expected. Interest grew like an avalanche, after viewing a large number of letters came and the Internet channel’s capacity began to be insufficient. Letters were always answered in great detail, which at first could be done without interrupting work. Then they began to assign one developer one by one so that he would only write answers for a week. Finally, a special employee was needed, since 2-3 thousand letters were already arriving per day. Sun management soon realized that Java's massive success had no budget or plan for advertising and other promotions. The first step in this direction was the publication on March 23, 1995 in the Sun Jose Mercury News of an article describing new technology, where the address of the official website http://java.sun.com/ was given, which to this day is the main source of information on Java.

Java is released

Finally, all the preparatory work began to come to its logical conclusion. The official announcement of Java, already widely recognized and showing great promise, was supposed to happen at the SunWorld conference. It was expected that this would be a short informational announcement, since the main target of this event was UNIX systems. However, things didn't happen as planned.

At four o'clock on the morning of the conference, after long and difficult negotiations, Sun signs a crucial agreement. The second party is Netscape, founded in April 1994 by James Clark (he had already played a role in the fate of OaK two years earlier, when he intercepted the offer from Time Warner) and Marc Andreessen (creator of NCSA Mosaic). The company became the browser market leader after the first version of Netscape Navigator was released in December 1994, which was open for free non-commercial use, which allowed it to capture 75% of the market at that time.

On May 23, 1995, Java and HotJava technologies were officially announced by Sun and at the same time, company representatives announced that the new version of the most popular browser, Netscape Navigator 2.0, would support the new technology. Essentially, this meant that Java would now become as integral a part of the WWW as HTML. For the second time, the presentation ended with an ovation - the victorious march of Java began.

History of Java development

Now that Java had not only a few creators, but also a whole army of developers behind it, Sun was able to make large-scale plans for the development of the technology.

Browsers

Of course, the main line of development remained related to browsers. Although the Internet was just beginning to be filled with new technologies, compatibility problems were already arising. Worked under different platforms different browsers that even the fonts were different. As a result, the author could create a beautiful, neat page that would fall apart for the client.

Using Java, a web page can be filled not only with regular text, but also with dynamic elements - simple video inserts such as a rotating globe or Duke waving his hand (although now such problems are well solved by animated GIF, and in more complex cases - Macromedia Flash); interactive elements such as a rotating model of a chemical molecule; creeping lines containing, for example, stock indices or weather forecasts.

But in fact, Java is more than a decoration for HTML. Since it is a full-fledged programming language, it can be used to create complex user interfaces. In the very first version of the Java Development Kit (Java development tool), there was an example applet representing the simplest spreadsheets. Soon a text editor appeared that allowed you to change the style and color of the text. Of course, there were game applets that taught, simulated physical and other systems. For example, a client who placed an order in a store or sent a parcel by mail was able to track delivery via the Internet.

Unlike ordinary programs, applets have inherited an important property of HTML pages. After reading the content of the news page today, the client does not save it on his computer, but reads the updated content the next day. In the same way, after downloading the applet and working with it, you can delete it and get a newer version next time. Thus, programs appear and disappear from the client's machine without any effort, no special knowledge or actions are required, and the latest versions are automatically supported.

On the other hand, the user is no longer tied to his main workplace; in any Internet cafe you can open the desired web page and start working with familiar programs. And all this without any fear of catching the virus. The developers were very interested in the fact that their programs, one day after release, could be seen by users all over the world, regardless of what computer, operating system and browser they use. Although the client-side browser must support Java, as already mentioned, users were offered HotJava, available on any platform. The most popular browser at the time, Netscape Navigator, also supported Java, starting with version 2.0. However, today, as you know, the most common browser is Microsoft Internet Explorer.

Microsoft, having achieved stunning success in the field of software for personal computers, became (and generally remains) the main competitor in this area for Sun, IBM, Netscape and others. If in the early nineties Microsoft's main efforts were aimed at the Windows operating system and office applications (MS Office), then in the middle of the decade it became obvious that it was time to get serious about the Internet. In early 1995, Bill Gates published "plans to declare war" on Netscape, with the goal of gaining the same monopoly position on the WWW as he had on personal computer operating systems. And when Netscape soon signed a licensing agreement with Sun, Microsoft found itself in a difficult situation.

Internet Explorer 2.0 did not inspire enthusiasm and no one believed that it could be any significant competitor to Netscape Navigator. This means that the new version of IE 3.0 should be able to do everything that the just released NN 2.0 can do. Therefore, on December 7, 1995, Microsoft announced its intention to license Java, and in March 1996, a licensing agreement was signed. The world's largest software company was forced to support what may be its most dangerous competitor.

Now we have the opportunity to look back and assess the consequences of the events that took place. It is now obvious that Microsoft has fully succeeded in implementing its plan. While Netscape Navigator 3.x still retained its leading position, Netscape 4.x had already begun to give way to Internet Explorer 4.x. Version NN 5.x was never released, and NN 6.x became another disappointment for former Navigator fans. Now version 7.0 has appeared, but it does not occupy a significant market share, while Internet Explorer 5.0, 5.5 and 6.0 are used by more than 95% of users.

It's funny that many people bitterly accused Microsoft of fighting Netscape with "non-market" means. However, let's compare the actions of competitors. Among the many steps Microsoft took was supporting the independent organization W3C, which led the development of the new standard HTML 3. In the beginning, Netscape was considered a powerhouse of the industry, as it constantly developed and modernized HTML, which was not originally intended for graphical text formatting. But Microsoft, having invested a large amount of money and human resources, was able to approve standards that differed from those already implemented in Netscape Navigator, and the differences were sometimes purely formal. As a result, it turned out that pages created in accordance with the W3C specifications were displayed distorted in Navigator. It is also important that NN had to be downloaded (albeit for free) and installed manually, and IE quickly became built-in Windows component, ready for use (and which, by the way, could not be gotten rid of in principle).

How did Netscape achieve its leadership position? At one time, the company tried (successfully, in the end) to oust NCSA Mosaic from the market using similar methods. Back then, HTML was not particularly rich in interesting features, and therefore the innovations supported by Navigator immediately attracted the attention of developers and users. However, such pages did not display correctly in Mosaic, causing its users to consider switching to Netscape products.

As a result, many people breathed a sigh of relief at the oblivion of Netscape and its Navigator. Although, of course, the loss of competition in the market and the accession of such a dangerous monopolist as Microsoft is never good for end users, many are tired of the “war of standards”, when the already poor HTML capabilities I had to make some sophisticated tweaks to make the pages look the same in both browsers.

Unfortunately, there is not much to say about HotJava. Sun supported this product for some time and added the ability to visually generate web pages without knowledge of HTML. However, it was not possible to create a competitive browser and the development of HotJava was soon stopped. Now you can still download and watch the latest version 3.0.

And the last thing worth dwelling on is the Java Script language, which is also very widespread and which many still associate with Java, apparently due to the similarity of names. However, they do have some common features.

On December 4, 1995, Netscape and Sun jointly announced a new "scripting language" called Java Script. As follows from the press release, this is an open cross-platform object scripting language for corporate networks and the Internet. The Java Script code is described directly in HTML text(although you can load it from separate files with extension .js). This language is designed for creating applications that bind objects and resources on a client machine or server. Thus, Java Script, on the one hand, extends and complements HTML, and on the other hand, complements Java. Java is used to write applet objects that can be controlled through a scripting language.

Common properties of Java Script and Java:

* ease of learning. In this respect, Java Script is compared to Visual Basic - no programming experience is required to use these languages;

* cross-platform. The Java Script code is executed by the browser. The implication is that browsers on different platforms should provide the same functionality for pages that use a scripting language. However, this is done to about the same extent as supporting HTML itself - there are still a lot of differences;

* openness; the language specification is open for use and discussion by the developer community;

* all of the listed properties suggest that Java Script is well suited for Internet programming;

* The syntaxes of Java Script and Java are very similar. However, they are also quite reminiscent of the C language;

* Java Script is not object-oriented (although some aspects of the object-oriented approach are supported), but allows the use of various objects provided by the browser;

* similar history of appearance and development. Both languages ​​were announced by Sun and Netscape within a few months of each other. Netscape Navigator 2.0, released soon after, supported both new technologies. Perhaps the name Java Script itself was given in order to take advantage of the popularity of Java, or in order to further expand the concept of “Java platform”. It is likely that Netscape did most of the language development.

Despite a large number of similar characteristics, Java and Java Script are completely different languages, and primarily in purpose. If Java was initially positioned as a language for creating Internet applications (applets), it is now obvious that Java is a full-fledged programming language. As for Java Script, it fully lives up to its name as a scripting language, remaining an extension of HTML. However, the extension is quite powerful, since fans of this technology manage to create quite serious applications, such as 3D first-person games (in a greatly simplified mode, of course), although this is more of a case of curiosity.

In conclusion, we note that the Java Script code running on the client is available to everyone in clear text, which makes copyright protection difficult. On the other hand, due to the lack of full support, declarations of new types of programs with complex functionality are often too confusing for others to use.

Networked computers

When it became clear that the new technology was in unprecedented demand, developers wanted to strengthen and build on the success and prevalence of Java. To prevent Java from sharing the fate of NeWS (this window system was mentioned at the beginning of the lecture, it was not developed, losing to X Window), Sun tried to establish cooperation with independent companies to produce various libraries, developer tools, and tools. On January 9, 1996, a new division, JavaSoft, was formed, which began developing new Java technologies and promoting them to the market. The main goal is the emergence of an increasing number of different applications written on this platform. For example, on July 1, 1997, it was announced that NASA scientists (National Aeronautics and Space Administration, a US government organization engaged in space exploration) were using Java applets to control a robot exploring the surface of Mars (“Java helps make history!”).

It's time to take a closer look at why the term "platform" is used in relation to Java, and how Java differs from a regular programming language.

As a rule, a platform is a combination of hardware architecture (hardware), which is determined by the type of processor used (Intel x86, Sun SPARC, PowerPC, etc.), with an operating system (MS Windows, Sun Solaris, Linux, Mac OS, etc.) . When writing programs, the developer always uses the target platform's tools to access the network, support threads of execution, work with a graphical user interface (GUI), and other features. Of course, different platforms, due to technical, historical and other reasons, support different interfaces (API, Application Programming Interface), which means that the program can only be executed under the platform for which it was written.

However, often customers require the same functionality, but they use different platforms. The task of porting applications has been facing developers for a long time. It is rarely possible to port a complex program without significant rework, and very often different platforms support many features differently (for example, Mac OS traditionally uses a one-button mouse, while Windows was originally designed for a two-button mouse).

This means that programming languages ​​must initially be oriented towards a specific platform. The syntax and basic concepts are easy to extend to any system (though not always efficient), but the libraries, compiler, and, of course, binary executable code are specific to each platform. This has been the case since the dawn of computing, and few truly successful programs were supported on multiple systems at once, resulting in a somewhat isolated software world for different operating systems.

It would be strange if, with the development of the computer industry, developers did not try to create a universal platform under which all programs could work. This step was especially facilitated by the rapid development of the Global Internet, which united users regardless of the type of processors and operating systems used. That is why the creators of Java decided to develop not just another programming language, but a universal platform for executing applications, especially since OaK was originally created for various household devices, from which one cannot expect compatibility.

How can one “smooth out” the differences and diversity of operating systems? The method is not new, but effective - using a virtual machine. Java applications run in a special, universal environment called the Java Virtual Machine. The JVM is a program that is written specifically for each real platform in order, on the one hand, to hide all its features, and on the other, to provide a unified execution environment for Java applications. Sun and its partners have created the JVM for almost all modern operating systems. When we talk about a Java-enabled browser, we mean that it has a built-in virtual machine.

The JVM is discussed in more detail below, but it must be said that the Sun developers have made efforts to make this machine very real, and not just virtual. On May 29, 1996, the Java OS operating system was announced (the final version was released in March of the following year). According to the press release, it was "possibly the smallest and fastest operating system supporting Java." Indeed, developers strived to provide the ability to run Java applications on a wide range of devices - networked computers, PDAs, printers, game consoles, mobile phones, etc. It was expected that Java OS would be implemented on all hardware platforms. This was necessary for the original goal of the creators of Java - the ease of adding new functionality and compatibility to any electrical devices used by the modern consumer.

This was the first step in moving the Java platform one level down to the operating system level. It was supposed to do next step- create a hardware architecture, a central processor that would directly execute Java instructions without any virtual machine. A device with such an implementation would become a full-fledged Java device.

In addition to household appliances, Sun positioned this decision and for the computer industry, networked computers were expected to replace heterogeneous personal workstation platforms. This approach fit well with Sun's core philosophy, expressed in the slogan "The Network is the Computer." The capabilities of one computer will never compare with the capabilities of a network that unites all the resources of the company, and even more so the entire world. This is probably already obvious today, but at a time when WWW had not yet entangled the planet, the idea was revolutionary.

If you build a multifunctional network, then completely different requirements are imposed on its workstations - they should not be particularly powerful, computing tasks can be transferred to servers. This is even more profitable, since it allows you to centralize software support and updates, and also does not force employees to be tied to their desks. It is enough to log in to the network from any terminal, log in - and you can continue working from the place where you left it. This can be done in your office, presentation room, cafe, airplane seat, at home - anywhere!

In addition to the obvious convenience, this initiative was supported with great enthusiasm by the industry due to the fact that it was the strongest weapon in the fight against the largest software manufacturer - Microsoft. Then (and even now) the most common platform was the Windows operating system based on Intel processors (now called Wintel by many). These companies managed to create a vicious circle that guaranteed success - everyone used their platform, since the most programs were written for it, which, in turn, forced developers to create new products specifically for the Wintel platform. Since Microsoft has always been very aggressive in developing its advantage in the field of personal computers (remember how Netscape Navigator hopelessly lost the competition to MS Internet Explorer), this could not but cause great concern for others in the computer industry. It is clear that the concept network computers would negate the benefits of Wintel if widely adopted. Developers would simply stop wondering what's inside their workstation, just as home users have no idea what chips are in their cell phone or VCR.

We've already talked about how and why Microsoft licensed Java, although it would seem that this step only contributed to the dangerous spread of the new technology, because Internet Explorer was gaining more and more popularity. However, a legal scandal soon broke out. On September 30, 1997, a new IE 4.0 was released, and on October 7, Sun announced that this product did not pass tests for compliance with the virtual machine specification. November 18 Sun goes to court to stop the use of the "Java compatible" logo for MS IE 4.0. It turned out that Microsoft developers slightly “improved” the Java language by adding several new keywords and libraries. Not that these are super-powerful extensions, but they are attractive enough for a significant part of developers to start using it. Fortunately, Sun quickly realized the dangers of such a move. Java could lose its title as a universal platform, for which the famous motto “Write once, run everywhere” is true. In this case, it would lose the basis of its success, becoming just "another programming language."

Sun managed to defend its technology. On March 24, 1998, the court agreed with the company's demands (of course, this was only a preliminary decision, the case ended only on January 23, 2001 - Sun received compensation of $ 20 million and achieved compliance license agreement), and on May 12 Sun again came out with a demand to oblige Microsoft to include full version Java in Windows 98 and other software products. This litigation continues to this day with varying success between the parties. For example, Microsoft excluded Internet from the virtual machine Explorer library java.rmi, which allows you to create distributed applications, trying to attract the attention of developers to DCOM technology, which is tightly tied to the Win32 platform. In response, many companies began to distribute a special add-on (patch) that eliminates this drawback. As a result, Microsoft stopped its support for Java at version 1.1, which this moment is outdated and lacks many useful features. This, in turn, has practically stopped the widespread use of applets, except for cases of either very simple functionality (such as a ticker or a dialog with several input fields and buttons), or applications for internal corporate networks. For the latter case, Sun has released a special Java Plug-in product that is built into MS IE and NN, allowing them to run applets based on the latest versions of Java, and full compliance with the specifications is guaranteed (the product was originally called Java Activator and was first announced on December 10, 1997 ). Currently, Microsoft alternates between including and excluding Java from its operating system. Windows systems XP, apparently trying to find the most profitable option for itself.

In 1995, software giant Sun Microsystems released a new platform called Java. It included a programming language and the so-called Java Runtime Environment or runtime environment for applications written using Java. In turn, the JRE included basic system types of the Java language, a virtual machine, more often called a Java machine, and a whole library of helper classes.



Obviously, the main purpose of the innovation of that time was the cross-platform nature of applications, which, before the advent of Java, were strongly tied to the hardware for which they were intended. Java made it possible to run applications regardless of the platform installed on the computer.

Learn more about how Java works

Unlike applications created, for example, in C, the JRE collects files differently source code application created using the Java language. As a result of compilation, a C application goes through the stage of creating so-called object code or machine code (assembly stage), from which an executable file is assembled by the linker, depending on the platform installed on the PC. An application written using Java, as a result of the compilation process, creates so-called bytecode, independent of the operating environment in which it is compiled. However, in order for this bytecode to be compiled into an executable file on a given platform, the JRE runtime environment must be installed on that platform. This is the tool that users often ask: “Why do you need Java on a computer?”


A little about the popularity of Java programs

Modern Java has become an almost universally accepted development standard. Network applications, games, enterprise software, well-known applets for web browsers, embedded and mobile software are developed in this language. According to statistics, in the world, Java is installed on 97 percent of corporate desktop PCs. Tools written in this language are used in three billion mobile phones. Java is also popular among TV devices. So the popularity of applications created using the Java programming language is undeniable. The reason for this popularity was the ability to develop in one operating environment and run the created application in a completely different one. This is the so-called cross-platform, based on independent bytecode, which was discussed just above.


Is there an alternative to Java?

An example of an alternative for Java would be the .Net platform from another software giant called Microsoft. It also has a cross-platform component due to the presence of MSIL code, which is analogous to Java bytecode. However, unlike Java, the Microsoft platform is installed only for operating systems. Windows environment, and therefore remains platform-dependent, although there is an attempt to port this platform to other operating systems in the form of the Mono project. An important advantage of this platform is the ability to develop for it in many .Net-compatible languages.

Last update: 04/15/2018

Today, the Java language is one of the most common and popular programming languages. The first version of the language appeared back in 1996 in the depths of the Sun Microsystems company, which was later absorbed by Oracle. Java was intended to be a universal programming language that can be used for various types of tasks. And to date, the Java language has come a long way, many different versions have been published. The current version is Java 12, which was released in March 2019. And Java has evolved from just a universal language into an entire platform and ecosystem that combines various technologies used in a number of tasks: from creating desktop applications to writing large web portals and services. In addition, the Java language is actively used to create software for a number of devices: regular PCs, tablets, smartphones and mobile phones, and even household appliances. Suffice it to recall the popularity of the Android mobile OS, most programs for which are written in Java.

Java Features

A key feature of the Java language is that its code is first translated into special bytecode that is platform independent. And then this bytecode is executed by the JVM (Java Virtual Machine). In this regard, Java differs from standard interpreted languages ​​like PHP or Perl, the code of which is immediately executed by the interpreter. At the same time, Java is not a purely compiled language like C or C++.

This architecture ensures cross-platform and hardware portability of Java programs, so that such programs can be executed on various platforms without recompilation - Windows, Linux, Mac OS, etc. Each platform may have a different implementation of the JVM, but each can run the same code.

Java is a language with a C-like syntax and is close in this regard to C/C++ and C#. Therefore, if you are familiar with one of these languages, then mastering Java will be easier.

One more key feature Java is that it supports automatic garbage collection. This means that you do not have to manually free memory from previously used objects, as in C++, since the garbage collector will do this automatically for you.

Java is an object-oriented language. It supports polymorphism, inheritance, static typing. The object-oriented approach allows you to solve the problems of building large, but at the same time flexible, scalable and extensible applications.

Installing Java

For Java programs to run, the JRE (Java Runtime Environment) must be installed on the target machine. The JRE provides a minimal virtual machine implementation as well as a class library. Therefore, if we want to run programs, then we need to install the JRE. Each specific platform has its own version of the JRE.

However, since we are going to not only run programs, but also develop them, we will need a special development kit, the JDK (Java Development Kit). The JDK already contains the JRE, and also includes a number of additional programs and utilities, in particular the Java compiler.

You can download and install the appropriate version of the JDK from the official Oracle website: http://www.oracle.com/technetwork/java/javase/downloads/index.html

So, from the above mentioned address, download the JDK installer for the latest version of Java.

Then we will be redirected to a page where we need to select the version for the target OS - Windows, MacOS or Linux:

For each OS there are two download options: as an installer, or as an archive that does not need to be installed. For example, my OS is Windows, so I download the jdk_12_windows-x64_bin.exe file, which represents the installer.

After downloading, run the installation program:

Click on the Next button. On the next screen you need to specify which folder the installation will be in:

Leave the default folder selection and click Next to complete the installation.

After the JDK installation is complete, we will see this window:

So, after installing the JDK, let's create our first Java program.

A Brief Course in the History of the Java Language

This section briefly describes the history of the Java language. This section is based on various published materials (mostly interviews with the creators of the Java language in the July 1995 issue of SunWorld).

Java's history goes back to 1991, when a group of engineers at Sun, led by Patrick Naughton and board member (and all-around computer wizard) James Gosling, set out to develop a small language that could be used to program everyday devices. devices, for example, controllers for switching cable television channels (cable TV switchboxes).

Since such devices do not consume much power and do not have large memory chips, I had to be small and generate very compact programs. Additionally, since different manufacturers may choose different Central Processor Units (CPUs), it was important not to get bogged down by any one computer architecture. The project was codenamed "Green".

In an effort to invent small, compact, and machine-independent code, the developers revived the model used to implement the first versions of the Pascal language at the dawn of the personal computer era. Niklaus Wirth, the creator of the Pascal language, once developed a machine-independent language that generates intermediate code for a certain hypothetical machine. This language became a commercial product under the name UCSD Pascal. (Such hypothetical machines are often called virtual machines—for example, the Java virtual machine, or JVM.)
This intermediate code can be executed on any machine that has an appropriate interpreter. The engineers working on Project Green also used a virtual machine, which solved their main problem.

However, most Sun employees had experience with the UNIX operating system, so the language they developed was based on C++, not Pascal. In particular, they made the language object-oriented rather than procedure-oriented.

As Gosling said in his interview: " Language is always a means, not an end"At first, Gosling decided to call it "Oak." (Perhaps because he liked to look at the oak tree growing right outside the windows of his office at Sun.) Then Sun employees learned that the word Oak was already used in as the name of a previously created programming language, and changed the name Java.

In 1992, the first products were released as part of the Green project, called
"*7". It was a means for extremely intelligent remote control. (It had the power of a SPARK workstation while fitting into a 6x4x4-inch box.) Unfortunately, none of the manufacturing companies electronic engineering was not interested in this invention.

The group then began developing a cable television device that could provide new types of services, such as video on demand. And again they did not receive a single contract. (It’s funny that one of the companies that refused to sign a contract with them was led by Jim Clark, the founder of Netscape, which later did a lot for the success of the Java language.)

Throughout 1993 and half of 1994, an unsuccessful search for buyers of products developed within the framework of the Green project (under the new name “First Person, Inc.”) continued. (Patrick Naughton, one of the group's founders who later worked primarily in marketing, flew more than 300,000 miles in total trying to sell the technology.) First Person, Inc. was discontinued in 1994.

Meanwhile, the World Wide Web was growing within the Internet. The key to this network is the browser, which turns hypertext into an image on the screen.
In 1994, most people were using the Mosaic browser, a non-profit Web browser developed at the University of Illinois Supercomputing Center in 1993. (This browser was written in part by Mark Andreessen for $6.85 an hour. Mark was finishing college at the time and the browser was his diploma work. He then became one of the founders and chief programmer of Netscape, and fame and fortune came to him.)

In an interview with Sun World magazine, Gosling said that in mid-1994, the language's developers realized: "We need to create a really cool browser. This browser should be one of the few applications of fashionable client-server technology, in which exactly what we did would be vital: architectural independence, real-time execution, reliability, security - issues that were not extremely important for workstations. And we created such a browser."

In fact, the browser was developed by Patrick Naughton and Jonathan Payne. It later evolved into the modern HotJava browser. This browser was written in Java to demonstrate its full power. However, developers did not forget about the powerful tools now called applets, giving their browser the ability to execute code inside Web pages. The "technology demo" was presented at Sun World '95 on May 23, 1995, and sparked a Java craze that continues to this day.

Sun released the first version of the Java language in early 1996. A few months after it, Java version 1.02 appeared. People quickly realized that Java 1.02 was not suitable for developing serious applications. Of course, this version can be used to develop Web pages with dancing men, but in Java 1.02 you can't even print anything.

To be honest, Java 1.02 was still raw. Its successor, Java 1.1, filled in most of the gaping holes, greatly improving reflection capabilities and adding new model events for graphical user interface programming. Despite this, it was still quite limited.

The release of Java 1.2 was the main news at the JavaOne conference in 1998. The new version replaces weak tools for creating graphical user interfaces and graphical applications with complex and extensive tools. This was a step forward towards the implementation of the slogan "Write Once, Run Anywhere" ™, put forward during the development of previous versions.

In December 1998, three days (!) after its release, the name of the new version was changed to the cumbersome phrase Java 2 Standard Edition Software Development Kit Version 1.2 (Standard edition of a package of tools for software development in the Java 2 language, version 1.2).

In addition to the standard edition of the package ("Standard Edition"), two more options were offered: a "micro edition" ("Micro Edition") for portable devices, for example, for mobile phones, etc. "Industrial Edition" ("Enterprise Edition") for creating server-based applications. Our book focuses on the standard edition.

Versions 1.3 and 1.4 of the standard edition of the toolkit are much more advanced than the original release of the Java 2 language. They have new features and, of course, contain many fewer bugs. In table Figure 1 1 shows the rapid growth of the API library as new versions of the standard edition SDK become available.

Table 1.1. The growth of the API library from the Java Standard Edition package

Number of classes and interfaces

Number of methods and fields

Common Misconceptions About the Java Language

This section lists and comments on some of the common misconceptions about Java.

The Java language is an extension of the HTML language.

Java is a programming language, and HTML is a way of describing the structure of Web pages. There is nothing in common between them, with the exception of HTML language extensions that allow applets written in Java to be placed on Web pages.

I'm working in XML, so I don't need Java.

Java is a programming language, and XML is simply a way to describe data. Data described using XML can be processed by programs written in any programming language, but only the Java API library provides excellent support for processing such data. In addition, Java implements many of the features of XML. They are described in more detail in the second volume.

The Java language is easy to learn.

There is no programming language as powerful as Java that can be learned easily. It's easy to write toy programs, but doing serious work is always difficult. Also, note that this book only devotes four chapters to discussing the Java language itself. The remaining chapters explain how to work with its libraries, which contain thousands of classes and interfaces, as well as many thousands of functions. Fortunately, you don't need to know every one of them, but doing a real project requires a surprising amount of knowledge from the user.

Java is easy to program.

The Java SDK is not easy to use for anyone except programmers accustomed to command line. There are integrated programming environments that include text editors, compilers, and drag-and-drop form creation tools, but they seem too complex and intimidating for a beginner. In addition, they often generate programs consisting of hundreds of lines. It seems to us that starting to learn the Java language using long programs, automatically generated and filled with comments like “DO NOT TOUCH YOUR HANDS!” is not a very good idea. We believe that the best way to learn Java is through familiar text editor. This is exactly what we will do.

The Java language will eventually become a universal programming language for all platforms.

Theoretically this is possible. This is what all software manufacturers dream of, except Microsoft. However, there are many applications that work great on personal computers, which will not work as well on other devices or browsers. In addition, these applications are written to take maximum advantage of the processors and machine-dependent libraries. In any case, they have already been ported to all important platforms. These applications include text and graphic editor, as well as Web browsers. Typically these applications are written in C or C++, and the user will gain nothing by rewriting them in Java. Additionally, rewriting them in Java will make these programs slower and less efficient, at least in the near future.

The Java language is just another programming language.

Java is a wonderful programming language. Many programmers prefer it over the C or C++ languages. However, there are hundreds of great programming languages ​​around the world that have never achieved widespread adoption, while languages ​​with obvious shortcomings, such as C++ and Visual Basic, have achieved stunning success.

Why? The success of any programming language is determined primarily by the practicality of its support system rather than the elegance of its syntax. Are there useful, convenient and standard libraries that allow you to do exactly what a programmer needs? Has a convenient environment for creating and debugging programs been developed? Are the language and its tools integrated into the computer infrastructure? The Java language has made strides in server applications because its class libraries make it easy to do things that were previously difficult, such as networking and multithreading. The fact that Java has reduced the number of pointer bugs is also in its favor. Thanks to this, the productivity of programmers has increased. However, this is not the reason for his success.

Java programs are interpreted, meaning serious applications will run too slowly on a particular platform.

Many programs spend most of their time interacting with the user interface or waiting for data from the network. All programs, no matter what language they are written in, must respond to mouse clicks within seconds. certain time. Of course, you should not perform CPU-intensive tasks using the Java interpreter. However, on platforms that allow synchronous compilation, you just need to run the bytecodes for execution, and most issues will simply disappear.

After all, Java is great for developing network programs. Experience shows that it easily maintains high network transfer rates even during intensive calculations such as encryption. Since Java is faster than internet speeds, it doesn't matter that C++ programs can run even faster. Java is easier to program and programs written in it are machine-independent.

All Java programs run under Web browsers.

All applets written in Java actually run under the control of Web browsers. Actually, this is the definition of an applet - a program executed by a Web browser. However, it is entirely possible and appropriate to create stand-alone Java programs that run independently of the Web browser.

These programs (usually called applications) are completely machine independent. Just take the program and run it on another machine! Because Java is more user-friendly and less error-prone than C++, it is a good choice. When combined with database access tools such as the Java Database Connectivity package, the Java language becomes irresistible. It is especially convenient to learn it as a first programming language.
Most of the programs in this book are completely self-contained. Of course, applets are a lot of fun. However, Java applications are more important and useful in practice.

Java applets pose a great threat to security systems.

Several security bug reports have been published in the Java language. Most of them concerned the implementation of the Java language using a specific browser. Researchers took this as a challenge and began looking for security loopholes in the Java language to overcome the strength and complexity of the applet security model. The technical errors discovered were soon corrected, and as far as we know, no real system has ever been compromised. To appreciate the importance of this fact, remember the millions of viruses on the executable files of the Windows operating system and Word processor macros, which indeed caused a lot of trouble, and the surprisingly toothless criticism of the weaknesses of the attacked platform. In addition, the ActiveX mechanism in the Internet Explorer browser could cause a lot of criticism, but the methods of hacking it are so obvious that only a few experts bothered to publish their research.

Some system administrators have even started turning off Java language protection in their browsers so that users can continue to download executable files, ActiveX controls, and documents created using the word processor Word. It's funny that nowadays the probability of overcoming the security system of Java applets is comparable to the probability of dying in a plane crash, while the risk of infecting a computer by opening a document created by word processor Word, comparable to the risk of dying under the wheels of a car while crossing the road during rush hour.

The JavaScript language is a simplified version of the Java language.

JavaScript is a scripting language that can be used in Web pages. It was developed by Netscape and was first called LiveScript. The syntax of the JavaScript language is similar to the syntax of the Java language, but that is where the similarities end (except for the name, of course). A subset of the JavaScript language has been standardized under the name ECMA-262, but its extensions required for real work, were not standardized.