What this book will tell you
This book explains how to write Java
programs that run either as independent applications or as applets (part of a
This book is for novices
If you have never done any programming
before if you are a complete novice this book is for you. This book
assumes no prior knowledge of programming. It starts from scratch. It is
written in a simple, direct style for maximum clarity. It is aimed primarily at
first year undergraduates at universities and colleges, but it is also suitable
for novices studying alone.
Java is probably one of the best programming
languages to learn and use because of the following features.
Java is small and beautiful
The designers of Java have deliberately
left out all the superfluous features of programming languages; they cut the
design to the bone. The result is a language that has all the necessary
features, combined in an elegant and logical way. The design is lean and mean.
It is easy to learn, but powerful.
Java is object-oriented
Object-oriented languages are the latest
and most successful approach to programming. Object-oriented programming is the
most popular approach to programming. Java is completely object-oriented from
the ground up. It is not a language that has had object-orientedness grafted
onto it as an afterthought.
Java supports the Internet
A major motivation for Java is to enable
people to develop programs that use the Internet and the World-Wide Web. Java applets
can easily be invoked from Web browsers such as Internet Explorer to provide
valuable and spectacular facilities. In addition, Java programs can be easily
transmitted around the Internet and run on any computer.
Java is general-purpose
Java is a truly general-purpose language.
Anything that C++, Visual Basic etc. can do, so can Java.
Java is platform-independent
Java programs will run on almost all
computers and with nearly all operating systems
unchanged! Try that with any other programming language. (You almost certainly !) This is summed up in the
slogan "write once
Java is robust
The Java compiler carries out many
stringent checks as it prepares a program for execution. Once a program has
been corrected and compiles without errors, it often performs correctly.
However, if a Java program goes wrong (and programs do have that tendency), it create mayhem, damage and
Java has libraries
Because Java is a small language, most of
its functionality is provided by pieces of program held in libraries. A whole
host of library software is available to do graphics, access the Internet, provide
graphical user interfaces (GUIs) and many other things.
You will need
To learn to program you need a computer and
some software. A typical system is a PC (personal computer) with the Java Software
Development Kit (SDK). This is also available for Unix, Linux
and Apple systems. This kit allows you to prepare and run Java programs. There
are also more convenient development environments. We
Exercises are good for you
If you were to read this book time and
again until you could recite it backwards, you still
be able to write programs. The practical work of writing programs and program
fragments is vital to becoming fluent and confident at programming.
There are exercises for the
reader at the end of each chapter. Please do some of them to enhance your
ability to program.
There are also short self-test
questions with answers throughout the text, so that you can check you have
understood things properly.
This book explains the fundamentals of
input and output;
graphics and windows programming;
selection using if;
repetition using while.
It also covers integer numbers,
floating-point numbers and character strings. Arrays are also described. All
topics that are fundamental,
whatever kind of programming you go on to do.
This book also thoroughly
addresses the object-oriented aspects of programming:
using library classes.
We also look at some of the more sophisticated
aspects of object-oriented programming, like:
This book describes the essentials of Java.
It does not explain the bits and pieces, the bells and whistles. Thus the
reader is freed from unnecessary detail and can concentrate on mastering Java
and programming in general.
Applications or Applets?
There are two distinct types of Java
a distinct free-standing program (this is called
a program invoked from a Web browser (this is
called an applet).
In this book we concentrate on applications,
because we believe that this is the main way in which Java is being used. (We
explain how to run applets in an appendix.)
Graphics or text?
Throughout the text we have emphasized
programs that use graphical images rather than text input and output. We think
they are more fun, more interesting and clearly demonstrate all the important
principles of programming. We
ignored programs that input and output text
they are included, but they come second best.
Graphical user interfaces (GUIs)
The programs we present use many of the
features of a graphical user interface (GUI), such as windows, buttons,
scrollbars and using the mouse in lots of different ways.
The Swing set of
user interface components is more complete and powerful than the AWT set. This
book uses the Swing approach because it is being used more widely.
The sequence of material
Programming involves many challenging
ideas, and one of the problems of writing a book about programming is deciding
how and when to introduce new ideas. We introduce simple ideas early and more
sophisticated ideas later on. We use objects from an early stage. Then later we
see how to write new objects. Our approach is to start with ideas like
variables and assignment, then introduce selection and looping, and then go on
to objects and classes (the object-oriented features). We also wanted to make
sure that the fun element of programming is paramount, so we use graphics right
from the start.
Bit by bit
In this book we introduce new ideas
carefully one-at-a-time, rather than all at once. So there is a single chapter
on writing methods, for example.
Computers are used in many different
applications and this book uses examples from all these areas:
l information processing;
The reader can choose to
concentrate on those application areas of interest and spend less time on the
Different kinds of programming
There are many different kinds of
programming examples are procedural, logic,
functional, spreadsheet, visual and object-oriented programming. This book is
about the dominant type of programming
as practiced in languages like Visual Basic, C++, C#, Eiffel and Smalltalk.
time to time Sun release a new version of the Java Software Development Kit
(SDK). A new version usually means additional items in the libraries - and a
new version number. All versions from 1.2 have the generic name of Java 2. any version from version onwards
Programming is creative and interesting,
particularly in Java. Please have fun!
l Visit our Web site
All the programs presented in this book are
available on our Web site, which can be reached via: www.booksites.net/bell.
Any comments on this book?
If you want to email the authors, we are at
D.H.Bell@shu.ac.uk and M.Parr@shu.ac.uk. We look forward to hearing from you.