×

Uh-oh, it looks like your Internet Explorer is out of date.

For a better shopping experience, please upgrade now.

Beginning Java 2
     

Beginning Java 2

by Ivor Horton
 

What is this book about?

The Java language has been growing from strength to strength since its inception in 1995. It has since proved to be both powerful and extraordinarily easy to learn and use. This is what makes it ideal for the beginner. With dramatic changes to the handling of files, and the introduction of native support for XML, Java has been

Overview

What is this book about?

The Java language has been growing from strength to strength since its inception in 1995. It has since proved to be both powerful and extraordinarily easy to learn and use. This is what makes it ideal for the beginner. With dramatic changes to the handling of files, and the introduction of native support for XML, Java has been updated to work faster and to be current with the incredible rise of XML as a medium for communicating data.

This edition of the Beginning Java books outlines everything the beginning programmer needs to know to program with the Java programming language and the 1.4 Java Developer Kit (JDK). With the release of JDK 1.4, programmers can look forward to the most stable edition yet, and even better performance than was available previously.

Over the course of the book, you will build an example application called Sketcher — a simple drawing tool — that teaches you how to build an interactive user interface with Java, how to save and open files, how to use color, and how to respond to user input.

What does this book cover?

  • Teaches the Java language from scratch
  • Object-oriented Programming in Java
  • Handling errors and exceptions in applications
  • Manipulating data and files
  • Concurrent programming and threads
  • A comprehensive introduction to Swing, the graphical user interface API for Java
  • Printing in Java
  • An introduction to XML

Who is this book for?

Ivor's inimitable style has proved to be a hit with nearly half a million people with its easy to learn approach and the many useful examples. Regularly voted the most popular Javaprogramming book, this book teaches Java from scratch and assumes no previous knowledge. It is also suitable for those who have got some programming experience, especially C or C++, which will make learning easier.

Product Details

ISBN-13:
9781861002235
Publisher:
Wrox Press, Inc.
Publication date:
01/07/1999
Series:
Programmer to Programmer Ser.
Pages:
1110
Product dimensions:
7.26(w) x 9.12(h) x 1.93(d)

Read an Excerpt


Chapter 1: Introducing Java

This 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:

What is Java All About?

Java is an innovative programming language that first of all enables you to write programs called applets that you can embed in Internet Web pages. Java also allows you to write applications programs that you can run normally on your, or indeed any, computer that supports the language. You can even write programs that will work as an ordinary application and as an applet. Because Java has matured so much recently, it is becoming the language of choice for applications that need to run on a variety of different computer systems.

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 unlimited.

Beginning Java 2

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 creating code with malicious intent is effectively inhibited. Java implicitly incorporates measures to minimize the possibility of such occurrences.

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 will run unchanged on an); 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 require the source code to be tailored to each individual computer to accommodate the particular idiosyncrasies of that machine and operating system.

Possibly the next most important characteristic of Java is that it is object oriented. The objectoriented 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 manages to avoid many of the difficulties and complications that are inherent in some other object-oriented languages, so you will find it very straightforward and easy to learn.

Learning Java

Java is not difficult, but there is a great deal to it. The language itself is quite 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. Each chapter, as far as possible, 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 you drowning is minimized, and there is a high expectation that you will end up a competent swimmer.

Java Programs

As we have already noted, there are two kinds of programs you can write in Java. Programs that are to be embedded in a Web page are called Java applets, and ordinary standalone programs are called Java applications. You can further subdivide Java applications into console applications, which only support character output to your computer screen (in a DOS window on a PC under Windows, for example) and windowed Java applications that can create and manage multiple windows, and use the typical graphical user interaction (GUI) mechanisms of window-based programs.

While you are learning the Java language basics, we will be using console applications as examples to illustrate how things work. This is because we can then focus on the specifics of the language, without worrying about any of the complexity involved in creating and managing windows. Once you are comfortable with using all the features of the Java language, we'll move on to windowed applications and applet examples.

Learning Java - the Road Ahead

Before starting out, it is always helpful to have an idea of where you are heading and what route you should take, so let's take a look at a brief road map of where you will be going with Java. There are five broad stages you will progress through in learning Java using this book:

1. The first stage is this chapter. It sets out some fundamental ideas about the structure of Java programs and how they work. This includes such things as what objectoriented programming is all about, and how an executable program is created from a Java source file. Getting these concepts straight at the outset will make learning to write Java programs that much easier for you.

2. Next you will learn how statements are put together, what facilities you have for storing basic data in a program, how you perform calculations and how you make decisions based on the results of them. These are the nuts and bolts you need for the next stages.

3. In the third stage you will learn about classes - how you define them and how you can use them. This is where you learn the object-oriented characteristics of the language. By the time you are through this stage you will have learnt all the basics of how the Java language works so you will be ready to progress further into how you can use it.

4. In the fourth stage, you will learn how you can segment your application into pieces that can execute concurrently. This is particularly important for when you want to include several applets in a Web page, and you don't want one applet to have to wait for another to finish executing, before it can start. You may want a fancy animation to continue running while you play a game, for example, with both programs sitting in the same Web page.

5. In the fifth stage you will learn in detail how you implement an application or an applet with a graphical user interface, and how you handle interactions with the user in this context. This amounts to applying the capabilities provided by the Java class libraries. As well as learning about GUI implementation, you will also learn about handling images in various ways, as well as using the database access facilities in Java. When you finish this stage you will be equipped to write your own fully-fledged applications and applets in Java. At the end of the book, you should be a knowledgeable Java programmer. The rest is down to experience....

Meet the Author

Ivor Horton has extensive experience of programming and large-scale systems implementation in a wide range of industrial environments. He has in-depth knowledge and experience of production scheduling and online control systems, computer-aided design and manufacturing systems, as well diverse engineering and scientific applications. He's also taught programming in a variety of languages to engineering and scientific personnel primarily in aerospace and automotive companies. After countless years in the computer industry both doing and managing, Ivor now writes on programming topics for relaxation. When not relaxing, he takes an interest in cosmology, cacti, chaos, and cameras, and does a little editing and criticising of other peoples' efforts on the side.

Customer Reviews

Average Review:

Post to your social network

     

Most Helpful Customer Reviews

See all customer reviews