
Beginning Programming with Java For Dummies
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Consider Beginning Programming with Java For Dummies your indispensable guide to learning how to program in one of the most popular programming languages--Java! Java is an invaluable language to master, as it's widely used for application development, including Android, desktop, and server-side applications.
Beginning Programming with Java For Dummies is written specifically for newbies to programming. The book starts with an overview of computer programming and builds from there; it explains the software you need, walks you through writing your own programs, and introduces you to a few of the more-complex aspects of programming in Java. It also includes step-by-step examples you can try on your own (and email the author if you need help). As you work through the book, you'll get smart about these Java features:
* Object-oriented programming (OOP), a Java mainstay
* IntelliJ IDEA, an integrated development environment (IDE), that gives you one place to do all your programming, including debugging code
* Loops, branches, and collections
* Variables and operators
* Expressions, statements, and blocks
Beginning Programming with Java For Dummies translates all this foreign programming and computer syntax into plain English, along with plenty of helpful examples and tips. Learning a new language--and coding is definitely its own language--should be a fun endeavor. With this book as your handy interpreter, you'll be on your way to fluency, speaking the language of coders everywhere!
More details
Other editions
Additional editions

Person
Barry Burd, PhD holds an MS in Computer Science from Rutgers University and a PhD in Mathematics from the University of Illinois. Barry is the author of numerous For Dummies books, including Java For Dummies and Beginning Programming with Java For Dummies.
Content
Introduction 1
Part 1: Getting Started with Java Programming 5
Chapter 1: The Big Picture 7
Chapter 2: Setting Up Your Computer 21
Chapter 3: Running Programs 47
Part 2: Writing Your Own Java Programs 71
Chapter 4: Exploring the Parts of a Program 73
Chapter 5: Composing a Program 95
Chapter 6: Using the Building Blocks: Variables, Values, and Types 127
Chapter 7: Numbers and Types 149
Chapter 8: Numbers? Who Needs Numbers? 173
Part 3: Controlling the Flow 197
Chapter 9: Forks in the Road 199
Chapter 10: Which Way Did He Go? 219
Chapter 11: Around and Around It Goes 251
Chapter 12: Circling Back to Java Loops 275
Part 4: The Inside ScOOP 293
Chapter 13: Programming with Objects and Classes 295
Chapter 14: Using Methods and Fields from a Java Class 315
Chapter 15: Creating New Java Methods 347
Part 5: Smart Java Techniques 375
Chapter 16: Piles of Files: Dealing with Information Overload 377
Chapter 17: How to Flick a Virtual Switch 401
Chapter 18: Creating Loops within Loops 423
Chapter 19: Out of Many, One 443
Chapter 20: Oooey-GUI Was a Worm 477
Part 6: The Part of Tens 503
Chapter 21: Ten Useful Classes in the Java API 505
Chapter 22: Ten Bits of Advice for New Software Developers 511
Index 517
Chapter 1
The Big Picture
IN THIS CHAPTER
Recognizing what computer programming is all about
Understanding the software that enables you to write programs
Revving up to use an integrated development environment
Computer programming? What's that? Is it technical? Does it hurt? Is it politically correct? Does Google control it? Why would anyone want to do it? And what about me? Can I learn to do it?
What's It All About?
You've probably used a computer to do word processing: Type a letter, print it, and then send the printout to someone you love. If you have easy access to a computer, you've probably surfed the web: Visit a page, click a link, and see another page. It's easy, right?
Well, it's easy only because someone told the computer exactly what to do. If you take a computer fresh from the factory and give no instructions to it, it can't do word processing, it can't surf the web, and it can't do anything. All a computer can do is follow the instructions that people give to it.
Now imagine that you're using Microsoft Word to write the great American novel and you come to the end of a line. (You're not at the end of a sentence; just the end of a line.) As you type the next word, the computer's cursor jumps automatically to the next line of type. What's going on here?
Well, someone wrote a computer program - a set of instructions telling the computer what to do. Another name for a program (or part of a program) is code. Listing 1-1 shows you what some of Microsoft Word's code may look like.
LISTING 1-1 A Few Lines in a Computer Program
if (columnNumber> 60) {
wrapToNextLine();
} else {
continueSameLine();
}
If you translate Listing 1-1 into plain English, you get something like this:
If the column number is greater than 60,
then go to the next line.
Otherwise (if the column number isn't greater than 60),
then stay on the same line.
Somebody has to write code of the kind shown in Listing 1-1. This code, along with millions of other lines of code, makes up the program called Microsoft Word.
And what about web surfing? You click a link that's supposed to take you directly to Facebook. Behind the scenes, someone has written code of the following kind:
Go to <a href="http://www.facebook.com">Facebook</a>.
One way or another, someone has to write a program. That someone is called a programmer.
Telling a computer what to do
Everything you do with a computer involves gobs and gobs of code. For example, every computer game is really a big (make that "very big"!) bunch of computer code. At some point, someone had to write the game program:
if (person.touches(goldenRing)) {
person.getPoints(10);
}
Without a doubt, the people who write programs have valuable skills. These people have two important qualities:
- They know how to break big problems into smaller, step-by-step procedures.
- They can express these steps in a precise language.
A language for writing steps is called a programming language, and Java is just one of several thousand useful programming languages. The stuff in Listing 1-1 is written in the Java programming language.
James Gosling and others at Sun Microsystems created Java in the early to mid-1990s. In 2010, Java became part of Oracle Corporation as part of Oracle's acquiring Sun Microsystems.
Pick your poison
This book isn't about the differences among programming languages, but you should see code in some other languages so that you understand the bigger picture. For example, there's another language, Visual Basic, whose code looks a bit different from code written in Java. An excerpt from a Visual Basic program may look like this:
If columnNumber > 60 Then
Call wrapToNextLine
Else
Call continueSameLine
End If
The Visual Basic code looks more like ordinary English than the Java code in Listing 1-1. But, if you think that Visual Basic is like English, then just look at some code written in COBOL:
IF COLUMN-NUMBER IS GREATER THAN 60 THEN
PERFORM WRAP-TO-NEXT-LINE
ELSE
PERFORM CONTINUE-SAME-LINE
END-IF.
At the other end of the spectrum, you find languages like Forth. Here's a snippet of code written in Forth:
: WRAP? 60 > IF WRAP_TO_NEXT_LINE? ELSE CONTINUE_SAME_LINE? THEN ;
Computer languages can be very different from one another, but in some ways, they're all the same. When you get used to writing IF COLUMN-NUMBER IS GREATER THAN 60, you can also become comfortable writing if (columnNumber> 60). It's just a mental substitution of one set of symbols for another. Eventually, writing things like if (columnNumber> 60) becomes second nature.
From Your Mind to the Computer's Processor
When you create a new computer program, you complete a multistep process. The process involves three important tools:
- Compiler: A compiler translates your code into computer-friendly (human-unfriendly) instructions.
- Virtual machine: A virtual machine steps through the computer-friendly instructions.
- Application programming interface: An application programming interface contains useful prewritten code.
The next three sections describe each of the three tools.
Translating your code
You may have heard that computers deal with zeros and ones. That's certainly true, but what does it mean? Well, for starters, computer circuits don't deal directly with letters of the alphabet. When you see the word Start on your computer screen, the computer stores the word internally as 01010011 01110100 01100001 01110010 01110100. That feeling you get of seeing a friendly-looking, five-letter word is your interpretation of the computer screen's pixels and nothing more. Computers break everything down into very low-level, unfriendly sequences of zeros and ones and then put things back together so that humans can deal with the results.
So, what happens when you write a computer program? Well, the program has to get translated into zeros and ones. The official name for the translation process is compilation. Without compilation, the computer can't run your program.
I compiled the code in Listing 1-1. Then I did some harmless hacking to help me see the resulting zeros and ones. What I saw was the mishmash in Figure 1-1.
FIGURE 1-1: My computer understands these zeros and ones, but I don't.
The compiled mumbo jumbo in Figure 1-1 goes by many different names:
- Most Java programmers call it bytecode.
- I often call it a
.classfile. That's because, in Java, the bytecode gets stored in files namedSomethingOrOther.class. - To emphasize the difference, Java programmers call Listing 1-1 the source code and refer to the zeros and ones in Figure 1-1 as object code.
To visualize the relationship between source code and object code, see Figure 1-2. You can write source code and then get the computer to create object code from your source code. To create object code, the computer uses a special software tool called a compiler.
FIGURE 1-2: The computer compiles source code to create object code.
WHAT IS BYTECODE, ANYWAY?
Look at Listing 1-1 and at the listing's translation into bytecode in Figure 1-1. You may be tempted to think that a bytecode file is just a cryptogram - substituting zeros and ones for the letters in words like if and else. But it doesn't work that way at all. In fact, the most important part of a bytecode file is the encoding of a program's logic.
The zeros and ones in Figure 1-1 describe the flow of data from one part of your computer to another. I illustrate this flow in the following figure. But remember: This figure is just an illustration. Your computer doesn't look at this particular figure, or at anything like it. Instead, your computer reads a bunch of zeros and ones to decide what to do next.
Don't bother to absorb the details in my attempt at graphical representation in the figure. It's not worth your time. The thing you should glean from my mix of text, boxes, and arrows is that bytecode (the stuff in a .class file) contains a complete description of the operations that the computer is to perform. When you write a computer program, your source code describes an overall strategy - a big picture. The compiled bytecode turns...
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.