
Java For Dummies
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Learn to code with Java and open the gate to a rewarding career
Now in its 9th edition, Java For Dummies gives you the essential tools you need to understand the programming language that 17 million software developers rely on. This beginner-friendly guide simplifies every step of the learning process. You'll learn the basics of Java and jump into writing your own programs. Along the way, you'll gain the skills you need to reuse existing code, create new objects, troubleshoot when things go wrong, and build working programs from the ground up. Java For Dummies will help you become a Java developer, even if you're brand new to the world of coding.
- Learn the basic syntax and building blocks of Java
- Begin to write your own programs in the latest Java version
- Test out your code and problem-solve any errors you find
- Discover techniques for writing code faster
This is the must-have Dummies resource for beginning programmers and students who need a step-by-step guide to getting started with Java. You'll also love this book if you're a seasoned programmer adding another language to your repertoire.
More details
Other editions
Additional editions

Person
Dr. Barry Burd is a professor of Mathematics and Computer Science at Drew University in Madison, NJ. He's a co-leader of the Garden State Java User Group and New York JavaSIG. In 2020, he was honored to be named a Java Champion. He's the author of Beginning Programming with Java For Dummies and Flutter For Dummies.
Content
Introduction 1
Part 1: Getting Started with Java 5
Chapter 1: All about Java 7
Chapter 2: All about Software. 21
Chapter 3: Using the Basic Building Blocks 35
Part 2: Writing Your Own Java Programs 57
Chapter 4: Making the Most of Variables and Their Values 59
Chapter 5: Controlling the Flow by Making Decisions 97
Chapter 6: Controlling Program Flow with Loops 135
Part 3: Working with the Big Picture: Object-Oriented Programming 155
Chapter 7: The Inside scOOP 157
Chapter 8: Constructing New Objects 205
Chapter 9: Piles of Files: Dealing with Information Overload 229
Chapter 10: Saving Time and Money: Reusing Existing Code 249
Part 4: Smart Java Techniques 279
Chapter 11: Putting Variables and Methods Where They Belong 281
Chapter 12: Using Collections and Streams 313
Chapter 13: Using Arrays to Juggle Values 349
Chapter 14: Looking Good When Things Take Unexpected Turns 377
Chapter 15: Fancy Reference Types. 407
Chapter 16: Oooey GUI Was a Worm 427
Part 5: The Part of Tens 443
Chapter 17: Ten Packs of Java Websites 445
Chapter 18: Ten Bits of Advice for New Software Developers 449
Index 455
Chapter 1
All about Java
IN THIS CHAPTER
What Java is
Where Java came from
Why Java is so cool
Three ways to write computer code
Say what you want about computers. As far as I'm concerned, computers are good for just two simple reasons:
-
When computers do work, they feel no resistance, no stress, no boredom, and no fatigue. Your computer can work 24/7 making calculations for
www.climateprediction.net- a distributed computing project to model the world's climate change. Or, have your computer crunch numbers forRosetta@home- a site that models proteins to help cure major illnesses. Will you feel sorry for my computer because it's working so hard? Will the computer complain? No.You can make demands, give the computer its orders, and crack the whip. Will you (or should you) feel the least bit guilty? Not at all.
-
Computers move ideas, not paper. Not long ago, whenever you wanted to send a message to someone, you hired a messenger. The messenger mounted a horse and delivered your message personally. The message was recorded on paper or parchment or a clay tablet or whatever other physical medium was available at the time.
This whole process seems wasteful now, but that's only because you and I are sitting comfortably in the electronic age. Messages are ideas, and physical objects like ink, paper, and horses have little or nothing to do with real ideas; they're just temporary carriers of ideas (even though people used them for several centuries to carry ideas). Nevertheless, the ideas themselves are paperless, horseless, and messengerless.
The neat thing about computers is that they carry ideas efficiently. They carry nothing but the ideas, a couple of photons, and some electrical power. They do this with no muss, no fuss, and no extra physical baggage.
When you start dealing efficiently with ideas, something very nice happens: Suddenly, all overhead is gone. Instead of pushing paper and trees, you're pushing numbers and concepts. Without the overhead, you can do things much faster and do things that are far more complex than ever.
What You Can Do with Java
It would be nice if all this complexity were free, but, unfortunately, it isn't. Someone has to think hard and decide exactly what to ask the computer to do. After that thinking takes place, someone has to write a set of instructions for the computer to follow.
Given the current state of affairs, you can't write these instructions in English or any other language that people speak. Science fiction is filled with stories about people who make simple requests of robots and get back disastrous, unexpected results. English and other such languages are unsuitable for communication with computers, for several reasons:
- An English sentence can be misinterpreted. "No parking. Violators will be towed away at the owner's expense." So, the parking space's owner will pay to tow my car? That's not so bad!
- It's difficult to weave a complicated command in English. "Join flange A to protuberance B, making sure to connect only the outermost lip of flange A to the larger end of the protuberance B while joining the middle and inner lips of flange A to grommet C."
- English sentences have lots of extra baggage. "Sentences have unneeded words."
- English can be difficult to interpret. "John Wiley & Sons, Inc. shall pay net earnings to the Author ('Barry Burd') or the Author's assigns upon submittal of Java For Dummies, 9th Edition ('the Work') minus prepaid and accrued expenses and deferred charges, either directly or indirectly, within the meaning of section 4942(j)(3) or 4965(k)(5) for calendar year 2024."
To tell a computer what to do, you have to use a special language to write terse, unambiguous instructions. A special language of this kind is called a computer programming language. A set of instructions written in such a language is called a program. When looked at as a big blob, these instructions are called software or code. Here's what code looks like when it's written in Java:
void main() {
var checkAmount = 1257.63;
println("Pay to the order of Dr. Barry Burd $" + checkAmount);
}
You may argue that ChatGPT and other generative AI tools narrow the gap between informal English and carefully written code. That's true to some extent. But computer code isn't going away anytime soon. Generative AI may hallucinate. And, in some critical applications, hallucinations are unacceptable. Besides, GPT tools don't create themselves. At this very moment (whenever you're reading my book, that is), thousands of people around the world are writing code to make GPT tools faster and more versatile. Programming isn't a dying art. It's a growing endeavor.
Why You Should Use Java
It's time to celebrate! You've just picked up a copy of Java For Dummies, 9th Edition, and you're reading Chapter 1. At this rate, you'll be an expert Java programmer* in no time at all, so rejoice in your eventual success by throwing a big party.
To prepare for the party, I'll bake a cake. I'm lazy, so I'll use a ready-to-bake cake mix. Let me see: Add water to the mix and then add butter and eggs - hey, wait! I just looked at the list of ingredients. What's MSG? And what about propylene glycol? That's used in antifreeze, isn't it?
I'll change plans and make the cake from scratch. Sure, it's a little harder, but that way, I get exactly what I want.
Computer programs work the same way: You can use somebody else's program or write your own. If you use somebody else's program, you use whatever you get. When you write your own program, you can tailor the program especially for your needs.
Writing computer code is a big, worldwide industry. Companies do it, freelance professionals do it, hobbyists do it - all kinds of people do it. A typical big company has teams, departments, and divisions that write programs for the company. But you can write programs for yourself or for someone else, for a living or for fun. In a recent estimate, the number of lines of code written each day by programmers in the world exceeds the number of methane molecules on the planet Jupiter.** Take almost anything that can be done with a computer - with the right amount of time, you can write your own program to do it. (Of course, the "right amount of time" may be quite long, but that's not the point. Many interesting and useful programs can be written in hours or even minutes.)
- * In professional circles, a developer's responsibilities are usually broader than those of a programmer. But, in this book, I use the terms programmer and developer almost interchangeably.
- ** I made up this fact all by myself.
Gaining Perspective: Where Java Fits In
Here's a brief history:
-
1954-1957: FORTRAN is developed.
FORTRAN was the first modern computer programming language. For scientific programming, FORTRAN is a real racehorse. Year after year, FORTRAN is a leading language among computer programmers throughout the world.
-
1959: Grace Hopper at Remington Rand develops the COBOL programming language.
The letter B in COBOL stands for Business, and business is just what COBOL is all about. The language's primary feature is the processing of one record after another, one customer after another, or one employee after another.
Within a few years after its initial development, COBOL became the most widely used language for business data processing.
(Fun fact: I once foolishly tried to write a COBOL program to create musical compositions. Talk about picking the wrong tool for the job! It was like brushing my teeth with a nail file.)
-
1960: John McCarthy writes a paper on his new LISP programming language.
LISP sets the stage for a style of programming called functional programming. For a few decades, functional programming waits in the background while other programming techniques take center stage.
-
1967: Scientists at the Norwegian Computing Center develop the Simula 67 language.
With Simula 67, object-oriented programming is born.
-
1972: Dennis Ritchie at AT&T Bell Labs develops the C programming language.
The "look and feel" that you see in this book's examples comes from the C programming language. Code written in C uses curly braces,
ifstatements,forstatements, and other elements.In terms of power, you can use C to solve the same problems that you can solve by using FORTRAN or Java or any other modern programming language. The difference between one programming language and another isn't power - the difference is ease and appropriateness of use. That's where the Java language excels.
-
1986: Bjarne Stroustrup (also at AT&T Bell Labs) develops C++.
Unlike its C...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.