From the Author:
Ivor Horton on Java
1) What has been the biggest development within the Java Community in the last 12 months?
It's hard to single out one development as being the biggest - there have been so many.
For me I see the confirmation and reinforcement of Java as a major application
development tool. This derives from several recent advances in Java technology:
- the functionality provided by Java 2
- the layered structuring of the Java development environments from the Enterprise Edition down through the Standard Edition to the Micro Edition.
- the continuing general improvement in Java execution performance
2) What are the advantages working with Java, as opposed to working with other technologies?
I would pick three major advantages that I believe Java offers over other programming technologies:
3) What is the fundamental difference between JDK 1.2 and JDK 1.3?
- The write-once run anywhere capability that is implicit in Java. The same code will run under Windows 98/NT, Solaris, Unix in a variety of flavors including Linux, plus mainframe operating systems. No other programming technology offers this.
- A programming language with virtually none of the 'gotchas' of apparently (and superficially) similar object-oriented languages.
- A set of coherent class libraries that span a truly remarkable spectrum of application function - supporting text, graphics, image processing, sound, networking, plus many others. I'm not sure there is an equivalent in any other context, and definitely not for free.
While there is a whole range of incremental improvements to the capabilities that already exist in JDK 1.2, the Sound API is a major step change in functionality. You now have in JDK 1.3 a comprehensive facility for recording and replaying sounds in a wide variety of audio formats. It also provides you with extensive support for MIDI including a software synthesizer. Of course, the Sound API underpins the Java Media Framework, too.
Read an Excerpt
Chapter 1: Introducing JavaThis chapter will give you an appreciation of what the Java language is all about. Understanding the details that we'll introduce in this chapter is not important at this stage; you will see all of them again in greater depth in later chapters of the book. The intent of this chapter is to introduce you to the general ideas that underpin what we'll be covering through the rest of the book, as well as the contexts in which ,Java programs can be used and the kind of program that is applicable in each context.
In this chapter you will learn:
- The basic characteristics of the Java language.
- How Java programs work on your computer.
- Why Java programs are portable between different computers.
- The basic ideas behind object-oriented programming.
- How a simple Java program looks and how you can run it using the Java Development Kit.
- What HTML is and how it is used to include ajava program in a Web page.
What is Java All About?
Java is an innovative programming language that is becoming the language of choice for programs that need to run on a variety of different computer systems. First of all Java enables you to write small programs called applets. These are programs that you can embed in Internet Web pages to provide some intelligence. They might simply display an animated logo, or support data entry of some kind. Java also allows you to write large-scale application programs that you can run normally on any computer that supports the language. You can even write programs that will work both as ordinary applications and as applets. Java has matured immensely over the past couple of years, particularly with the introduction of Java 2. The breadth of capability provided by the standard core Java has grown incredibly, with the latest release extending into sampled sound and MIDI data processing.
Being able to embed executable code in a Web page introduces a vast range of exciting possibilities. Instead of being a passive presentation of text and graphics, a Web page can be interactive in any way that you want. You can include animations, games, interactive transaction processing - the possibilities are almost unlimited.
Of course, embedding program code in a Web page creates special security requirements. As an Internet user accessing a page with embedded Java code, you need to be confident that it will not do anything that might interfere with the operation of your computer, or damage the data you have on your system. This implies that execution of the embedded code must be controlled in such a way that it will prevent accidental damage to your computer environment, as well as ensure that any Java code that was created with malicious intent is effectively inhibited. Java implicitly incorporates measures to minimize the possibility of such occurrences arising with a Java applet.
Aside from its ability to create programs that can be embedded in a Web page, perhaps the most important characteristic of Java is that it was designed from the outset to be machine independent. Java programs can run unchanged on any computer that supports Java. Of course there is still the slim possibility of the odd glitch as you are ultimately dependent on the implementation of Java on any particular machine, but Java programs are intrinsically more portable than programs written in other languages. An interactive application written in Java will only require a single set of source code, regardless of the number of different computer platforms on which it is run. In any other programming language, the application will frequently require the source code to be tailored to accommodate different computer environments, particularly if there is an extensive graphical user interface involved.
Possibly the next most important characteristic of Java is that it is object oriented. The object-oriented approach to programming is also an implicit feature of all Java programs, so we will be looking at what this implies later in this chapter. Not only is Java object oriented, but it also manages to avoid many of the difficulties and complications that are inherent in some other object-oriented languages, making it very straightforward and easy to learn.
Java is not difficult, but there is a great deal to it. The language itself is fairly compact, but very powerful. To be able to program effectively in Java, however, you also need to understand the libraries that go with the language, and these are very extensive. In this book, the sequence in which you learn how the language works, and how you apply it, has been carefully structured so that you can gain expertise and confidence with programming in Java through a relatively easy and painless process. As far as possible, each chapter avoids the use of things you haven't learnt about already. A consequence, though, is that you won't be writing Java to be embedded in Web pages right away. While it may be an appealing idea, this would be a bit like learning to swim by jumping in the pool at the deep end. Generally speaking, there is good evidence that by starting in the shallow end of the pool and learning how to float before you try to swim, the chance of drowning is minimized, and there is a high expectation that you will end up a competent swimmer...