HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
The perfect course in Java for absolute beginners: a total book-and-web integrated learning solution that teaches you Java hands-on! Get started with Java: make sure your Java environment works, start editing files and using the Java console; running Java code, applications, and applets. Through simple examples and analogies, learn what objects are and what object-oriented programming involves. Then, master Java data types, control structures, basic Java graphical user interfaces and the layout manager; events, multimedia, even advanced subclassing, inheritance, exceptions and error handling. Like every book in the Prentice Hall Interactive Workbook series, this one is full of hands-on labs, exercises, "test your thinking" projects, and more -- all supported by a free, Web-based training site!
Click here for a sample chapter for this book: 0130166383.pdf
1. Getting Started.
Lab 1.1 Compiling and Running A Java Program. Test Your Thinking.
Lab 2.1 The Structure of a Simple Java Program. Lab 2.2 A Basic Overview of Variables. Lab 2.3 A Basic Overview of Methods. Test Your Thinking.
Lab 3.1 Primitive Data Types. Lab 3.2 The String Class. Lab 3.3 Arrays. Lab 3.4 Vectors. Test Your Thinking.
Lab 4.1 Boolean Testing. Lab 4.2 If-Then-Else. Lab 4.3 The While Loop. Lab 4.4 The For Loop. Lab 4.5 Switch Statement. Test Your Thinking.
Lab 5.1 Boolean Math. Lab 5.2 Boolean Expressions. Test Your Thinking.
Lab 6.1 GUI Basics. Lab 6.2 Application Versus Applet GUIs. Lab 6.3 The Use of Labels. Lab 6.4 The Use of Buttons. Lab 6.5 The Use of Text Components. Test Your Thinking.
Lab 7.1 The BorderLayout. Lab 7.2 The GridLayout. Lab 7.3 Combining Layout Managers. Lab 7.4 The GridBagLayout. Test Your Thinking.
Lab 8.1 Basic Event Handling. Lab 8.2 Different Approaches to Event Handling. Test Your Thinking.
Lab 9.1 Images. Lab 9.2 Colors. Lab 9.3 Sounds. Lab 9.4 Fonts. Test Your Thinking.
Lab 10.1 Designing and Implementing Classes. Lab 10.2 Special Class Features. Lab 10.3 Subclasses and Inheritance. Test Your Thinking.
Lab 11.1 Error-Handling with Return Values. Lab 11.2 Error-Handling with Exceptions. Lab 11.3 Throwing and Catching Exceptions. Lab 11.4 Creating Your Own Exceptions. Test Your Thinking.
Welcome to the Java 2 Programmer's Interactive Workbook. This book will help guide you as you learn the Java programming language, which is regarded as the future of computer programming. Never before has a computer language so successfully combined a powerful object-oriented language with all of the graphical tools needed to create a fully functional program that can run on any system and in any Web browser. With the advance of the Internet, Java has become the language of choice for developers who need to create and distribute their applications quickly.
Java was developed by Sun Microsystems in the early 1990s and has been gaining popularity every since. Prior to Java, the two main languages used by the computer industry were C, and C++. C is simple, powerful, and sometimes elegant, but it is also a procedural language. C++ is object-oriented, but also hugely complex and requires a great deal of overhead to maintain a program. Both languages are also machine-dependent, meaning that their programs only run on one type of computer (PC, Mac, Unix). The program must be recompiled, and sometimes rewritten, to work on a different computer. This can lead to long development times for projects.
Likewise, neither C nor C++ have built-in graphical utilities. Both must use special libraries that allow the program to use the windowing features of the computer. These libraries can be vastly different on various computer platforms, requiring more rewriting of the programs.
Java provides programmers the power and flexibility of C, while at the same time, allowing them to build true object-oriented programs without the overhead of C++. Additionally, the graphics utilities are built-in to Java, so no writing is ever needed. With Java 2, the "look and feel" of the program can be changed to match the local windowing system without any rewriting or recompiling. This means the same program can look like a Mac program when running on a Mac, and also look like a Windows program when running on a PC. All of this is possible after just writing and compiling the program just one time.
One additional feature of Java is that all of the objects created in Java
are truly reusable. This means that every program can build on past programs, greatly reducing the time it takes to develop programs. No longer do programmers have to keep reinventing the wheel with every new project.
This book is for the beginning programmer. It teaches computer programming using Java as the first language. Almost every other Java book out there assumes that you've programmed in some other language before (usually C). This book does not make that assumption. If you have never programmed before, then this book is for you. If you have programmed in an "older" language, such as Fortran, Pascal or Cobol, then this book is also for you. If you have programmed extensively in C or C++, then this book is probably not for youit may be too basic for you.
In addition to covering the basics of the Java programming language, this book will also cover topics that apply to any programming language. Such topics include general programming terms, Boolean logic, and basic program design. There are many books that show you how to do something in Java, but the authors feel that it's just as important to know why and when to do it.
This book is also not intended to be the end-all of Java books. Far from it! However, the unique format of the Interactive Workbook series makes this book an excellent tool to get you started down the path of learning Java. You won't be a Java expert when you're done with this book, but you will have a solid foundation on which to become an expert. The authors recommend that you follow-up this book with at least two other books on Java (you know, the ones that assume you already know the language!). One book should be a general Java reference book, and the other should be a Swing book. You'll learn about Swing is this book, but for now, know that Swing is the toolkit used to create graphical user interfaces (GUIs). There are many such books out there today, and most of them are very good, but as reference books. This book is meant to fill that gap between knowing nothing, and being able to use the reference books.
The Interactive Workbook series offers a unique and challenging program to "learn by doing." Only by engaging your brain in exercises can you truly learn anything. The creators of the Interactive Workbook series understand this concept, so these books offer more than just reading.
Every chapter is divided into several labs. Each lab targets a specific topic. You should try and complete a lab in a single sitting, so allow yourself some time. As you begin each lab, you will be given some instruction followed by the exercises. Make sure you do the exercises! The exercises are the key to learning. The authors also provide answers to the exercises, as well as follow-up discussion.
It is crucial that you actually do the exercises and then read the answers. It is also crucial that you read the discussion that follows. Unlike most books, the "chapter" is not over when the labs begin. The labs are not just a regurgitation of the chapter instruction. The exercises in the lab will reinforce the instruction in the chapter, but they will then challenge you to build on that knowledge. The answers to the exercises may contain new information not presented in the chapter instruction. This new information will make much more sense to you if you have done the exercises first.
At the end of each chapter are a series of Self-Review Questions. These questions also help to reinforce that you have learned what you needed to learn from the chapter. The answers to these questions can be found in Appendix A of this book.
The end of each chapter also has a Test Your Thinking section. This section contains more advanced projects than those contained in the labs. If you can handle these exercises, then you have really started to master the subject! The answers for the Test Your Thinking projects are not in the book, but they can be found on the Web page for this book.
As with all of the books in the Interactive Workbook series, this book has a companion Web site, which is located at the following site:
http://www.phptr.com/chu
This companion Web site is closely integrated with the content of this book, and we encourage you to visit it early and often. At the Web site, you will find all of the source code used in this book, answers to the Test Your Thinking exercises, the Self-Review questions and answers, and more! You can also send e-mail to the authors because they just don't get enough!
In order to program in Java, and use this book, you will need a few things.
This may seem obvious, but you will need one. Java, being a platform-independent language, will run on most current computers. Java is supported on the following systems:
For the other flavors of Unix, including Linux, you'll need to check the Web page that follows.
For this book, you will need to obtain the Production Release of the Java 2 SDK Standard Edition. This is also known as the JDK 1.2. At press time, this was actually known as JDK 1.2.2. There may be a more recent release by the time the book goes to print.
The Solaris and Windows version of Java 2 are free from Sun Microsystems at the following URL:
http://java.sun.com/java2
At this URL you will find both the Java 2 software and the documentation. We recommend that you get both. You may not be able to understand the documentation at first, but . . .
Sun may require that you register yourself for the download, but the software is free.
At press time, the actual download URL is the following:
http://java.sun.com/products/jdk/1.2
From this location you can download the Windows or Solaris releases of Java. If you have a Mac, or different flavor of Unix, click on the Platform Ports link to direct you to the version you need.
In Chapter 1, we will cover the download process and make sure that you can compile and run a Java program. Then in Chapter 2, we'll start learning some Java!