Introduction

What’s your story?

check.png Are you a working stiff, interested in knowing more about the way your company’s computers work?

check.png Are you a student who needs some extra reading in order to survive a beginning computer course?

check.png Are you a typical computer user — you’ve done lots of word processing, and you want to do something more interesting with your computer?

check.png Are you a job seeker with an interest in entering the fast-paced, glamorous, high-profile world of computer programming (or, at least, the decent-paying world of computer programming)?

Well, if you want to write computer programs, this book is for you. This book avoids the snobby “of-course-you-already-know” assumptions and describes computer programming from scratch.

About This Book

The book uses Java — a powerful, general-purpose computer programming language. But Java’s subtleties and eccentricities aren’t the book’s main focus. Instead, this book emphasizes a process — the process of creating instructions for a computer to follow. Many highfalutin’ books describe the mechanics of this process — the rules, the conventions, and the formalisms. But those other books aren’t written for real people. Those books don’t take you from where you are to where you want to be.

In this book, I assume very little about your experience with computers. As you read each section, you get to see inside my head. You see the problems that I face, the things that I think, and the solutions that I find. Some problems are the kind that I remember facing when I was a novice; other problems are the kind that I face as an expert. I help you understand, I help you visualize, and I help you create solutions on your own. I even get to tell a few funny stories.

How to Use This Book

I wish I could say, “Open to a random page of this book and start writing Java code. Just fill in the blanks and don’t look back.” In a sense, this is true. You can’t break anything by writing Java code, so you’re always free to experiment.

But I have to be honest. If you don’t understand the bigger picture, writing a program is difficult. That’s true with any computer programming language — not just Java. If you’re typing code without knowing what it’s about, and the code doesn’t do exactly what you want it to do, then you’re just plain stuck.

So in this book, I divide programming into manageable chunks. Each chunk is (more or less) a chapter. You can jump in anywhere you want — Chapter 5, Chapter 10, or wherever. You can even start by poking around in the middle of a chapter. I’ve tried to make the examples interesting without making one chapter depend on another. When I use an important idea from another chapter, I include a note to help you find your way around.

In general, my advice is as follows:

check.png If you already know something, don’t bother reading about it.

check.png If you’re curious, don’t be afraid to skip ahead. You can always sneak a peek at an earlier chapter if you really need to do so.

Conventions Used in This Book

Almost every technical book starts with a little typeface legend, and Beginning Programming with Java For Dummies, 3rd Edition is no exception. What follows is a brief explanation of the typefaces used in this book:

check.png New terms are set in italics.

check.png When I want you to type something short or perform a step, I use bold.

check.png You’ll also see this computerese font. I use the computerese font for Java code, filenames, web page addresses (URLs), onscreen messages, and other such things. Also, if something you need to type is really long, it appears in computerese font on its own line (or lines).

check.png You need to change certain things when you type them on your own computer keyboard. For example, I may ask you to type

class Anyname

which means you should type class and then some name that you make up on your own. Words that you need to replace with your own words are set in italicized computerese.

What You Don’t Have to Read

Pick the first chapter or section that has material you don’t already know and start reading there. Of course, you may hate making decisions as much as I do. If so, here are some guidelines you can follow:

check.png If you already know what computer programming is all about, then skip the first half of Chapter 1. Believe me, I won’t mind.

check.png If you’re required to use a development environment other than Eclipse, then you can skip Chapter 2. This applies if you plan to use NetBeans, IntelliJ IDEA, or a number of other development environments.

Most of this book’s examples require Java 5.0 or later, and some of the examples require Java 7 or later. So make sure that your system uses Java 5.0 or later. If you’re not sure about your computer’s Java version or if you have leeway in choosing a development environment, your safest move is to read Chapter 3.

check.png If you’ve already done a little computer programming, be prepared to skim Chapters 6 through 8. Dive fully into Chapter 9 and see whether it feels comfortable. (If so, then read on. If not, re-skim Chapters 6, 7, and 8.)

check.png If you feel comfortable writing programs in a language other than Java, then this book isn’t for you. Keep this book as a memento and buy my Java For Dummies, 5th Edition, also published by John Wiley & Sons, Inc.

If you want to skip the sidebars and the Technical Stuff icons, then please do. In fact, if you want to skip anything at all, feel free.

Foolish Assumptions

In this book, I make a few assumptions about you, the reader. If one of these assumptions is incorrect, then you’re probably okay. If all these assumptions are incorrect . . . well, buy the book anyway.

check.png I assume that you have access to a computer. Here’s good news. You can run the code in this book on almost any computer. The only computers you can’t use to run this code are ancient things that are more than 8 years old (give or take a few years). You can run the latest version of Java on Windows, Macintosh, and Linux computers.

check.png I assume that you can navigate through your computer’s common menus and dialog boxes. You don’t have to be a Windows, Linux, or Macintosh power user, but you should be able to start a program, find a file, put a file into a certain directory . . . that sort of thing. Most of the time, when you practice the stuff in this book, you’re typing code on your keyboard, not pointing and clicking your mouse.

On those rare occasions when you need to drag and drop, cut and paste, or plug and play, I guide you carefully through the steps. But your computer may be configured in any of several billion ways, and my instructions may not quite fit your special situation. So when you reach one of these platform-specific tasks, try following the steps in this book. If the steps don’t quite fit, send me an e-mail message, or consult a book with instructions tailored to your system.

check.png I assume that you can think logically. That’s all there is to computer programming — thinking logically. If you can think logically, you’ve got it made. If you don’t believe that you can think logically, read on. You may be pleasantly surprised.

check.png I assume that you know little or nothing about computer programming. This isn’t one of those “all things to all people” books. I don’t please the novice while I tease the expert. I aim this book specifically toward the novice — the person who has never programmed a computer or has never felt comfortable programming a computer. If you’re one of these people, you’re reading the right book.

How This Book Is Organized

This book is divided into subsections, which are grouped into sections, which come together to make chapters, which are lumped finally into five parts. (When you write a book, you get to know your book’s structure pretty well. After months of writing, you find yourself dreaming in sections and chapters when you go to bed at night.) The parts of the book are listed here.

Part I: Revving Up

The chapters in Part I prepare you for the overall programming experience. In these chapters, you find out what programming is all about and get your computer ready for writing and testing programs.

Part II: Writing Your Own Java Programs

This part covers the basic building blocks — the elements in any Java program and in any program written using a Java-like language. In this part, you discover how to represent data and how to get new values from existing values. The program examples are short, but cute.

Part III: Controlling the Flow

Part III has some of my favorite chapters. In these chapters, you make the computer navigate from one part of your program to another. Think of your program as a big mansion, with the computer moving from room to room. Sometimes the computer chooses between two or more hallways, and sometimes the computer revisits rooms. As a programmer, your job is to plan the computer’s rounds through the mansion. It’s great fun.

Part IV: Using Program Units

Have you ever solved a big problem by breaking it into smaller, more manageable pieces? That’s exactly what you do in Part IV of this book. You discover the best ways to break programming problems into pieces and to create solutions for the newly found pieces. You also find out how to use other peoples’ solutions. It feels like stealing, but it’s not.

This part also contains a chapter about programming with windows, buttons, and other graphical items. If your mouse feels ignored by the examples in this book, read Chapter 20.

Part V: The Part of Tens

The Part of Tens is a little beginning programmer’s candy store. In the Part of Tens, you can find lists — lists of tips, resources, and all kinds of interesting goodies.

I added an appendix on this book’s website to help you feel comfortable with Java’s documentation. I can’t write programs without my Java programming documentation. In fact, no Java programmer can write programs without those all-important docs. These docs are in web page format, so they’re easy to find and easy to navigate. But if you’re not used to all the terminology, the documentation can be overwhelming.

Icons Used in This Book

If you could watch me write this book, you’d see me sitting at my computer, talking to myself. I say each sentence several times in my head. When I have an extra thought, a side comment, something that doesn’t belong in the regular stream, I twist my head a little bit. That way, whoever’s listening to me (usually nobody) knows that I’m off on a momentary tangent.

Of course, in print, you can’t see me twisting my head. I need some other way of setting a side thought in a corner by itself. I do it with icons. When you see a Tip icon or a Remember icon, you know that I’m taking a quick detour.

Here’s a list of icons that I use in this book:

tip.eps A tip is an extra piece of information — something helpful that the other books may forget to tell you.

warning_bomb.eps Everyone makes mistakes. Heaven knows that I’ve made a few in my time. Anyway, when I think of a mistake that people are especially prone to make, I write about the mistake in a Warning icon.

remember.eps Sometimes I want to hire a skywriting airplane crew. “Barry,” says the white smoky cloud, “if you want to compare two numbers, use the double equal sign. Please don’t forget to do this.” Because I can’t afford skywriting, I have to settle for something more modest. I create a Remember icon.

technicalstuff.eps Occasionally, I run across a technical tidbit. The tidbit may help you understand what the people behind the scenes (the people who developed Java) were thinking. You don’t have to read it, but you may find it useful. You may also find the tidbit helpful if you plan to read other (more geeky) books about Java.

ontheweb.eps This icon calls attention to useful material that you can find online. (You don’t have to wait long to see one of these icons. I use one at the end of this introduction!)

Where to Go from Here

If you’ve gotten this far, then you’re ready to start reading about computer programming. Think of me (the author) as your guide, your host, your personal assistant. I do everything I can to keep things interesting and, most importantly, help you understand.

ontheweb.eps If you like what you read, send me a note. My e-mail address, which I created just for comments and questions about this book, is BeginProg@allmycode.com. And don’t forget — to get the latest information, visit one of this book’s support websites. Mine is at http://allmycode.com/BeginProg3, or you can visit www.dummies.com/go/beginningprogrammingwithjavafd.

Occasionally, we have updates to our technology books. If this book does have technical updates, they will be posted at www.dummies.com/go/beginningprogrammingwithjavafdupdates and at http://all mycode.com/BeginProg3.

Please note that some special symbols used in this eBook may not display properly on all eReader devices. If you have trouble determining any symbol, please call Wiley Product Technical Support at 800-762-2974. Outside of the United States, please call 317-572-3993. You can also contact Wiley Product Technical Support at www.wiley.com/techsupport.