|
Published:
September 28, 2021

Beginning Programming with Java For Dummies

Overview

Become a Java wizard with this popular programming guide

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!

Read More

About The Author

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.

Sample Chapters

beginning programming with java for dummies

CHEAT SHEET

When doing anything with Java, you need to know your Java words — those programming words, phrases, and nonsense terms that have specific meaning in the Java language and that get it to do its thing. This cheat sheet walks you through Java's peculiar vocabulary by focusing on keywords, literals, restricted keywords and identifiers.

HAVE THIS BOOK?

Articles from
the book

Before you jump into Java GUIs, there are a few things you should know. Java comes with three sets of classes for creating GUI applications: The Abstract Window Toolkit (AWT): The original set of classes, dating back to JDK 1.0. Classes in this set belong to packages whose names begin with java.awt. Components in this set have names like Button, TextField, Frame, and so on.
Templates look very nice. But knowing how the templates work is even better. Here are a few tidbits describing the inner workings of Java’s disk access code: APrintStream is something you can use for writing output. A PrintStream is like a Scanner. The big difference is that a Scanner is for reading input and a PrintStream is for writing output.
When doing anything with Java, you need to know your Java words — those programming words, phrases, and nonsense terms that have specific meaning in the Java language and that get it to do its thing. This cheat sheet walks you through Java's peculiar vocabulary by focusing on keywords, literals, restricted keywords and identifiers.
Experienced Java programmers have seen code that messes with your hard drive. But, what should you do with it? Let’s take a look.“I _____ (print your name)_____ agree to pay $______each month on the ___th day of the month.”Fill in the blanks. That’s all you have to do. Reading input from a disk can work the same way.
Imagine that you’re expecting a delivery from a local confectioner. In the late afternoon, the mail carrier delivers a box containing your favorite chocolate candy. Naturally, you want to open the box as soon as it arrives.The same is true about this book’s software. Here’s how you open your newly downloaded IntelliJ IDEA box: Launch the IntelliJ IDEA application.
The late 1980s saw several advances in software development, and by the early 1990s, many large programming projects were being written from prefab components. Java came along in 1995, so it was natural for the language's founders to create a library of reusable code. The library included about 250 programs, including code for dealing with disk files, code for creating windows, and code for passing information over the Internet.
Say that you’re sending a friend to buy groceries. You make requests for groceries in the form of method calls. You issue calls such asgoToTheSupermarketAndBuySome(bread);goToTheSupermarketAndBuySome(bananas);The things in parentheses are parameters. Each time you call your goToTheSupermarketAndBuySome method, you put a different value in the method’s parameter list.
The Java code you see below illustrates some pithy issues surrounding the input of data. For one thing, the program gets input from both the keyboard and a disk file. (The program gets a room number from the keyboard. Then the program gets the number of guests in that room from the occupancy file.) To make this happen, this program sports two Scanner declarations: one to declare keyboard and a second to declare diskScanner.
Most Java programs don’t work correctly the first time you run them, and some programs don’t work without extensive trial and error on your part. This code is a case in point.To write this code, you need a way to generate three-letter words randomly. This code would give you the desired result: anAccount.lastName = " + (char) (myRandom.
Before you can jump into Java GUIs, you need to install JavaFX and Scene Builder. GUI programs have two interesting characteristics: GUI programs typically contain lots of code. Much of this code differs little from one GUI program to another. GUI programs involve visual elements. The best way to describe visual elements is to “draw” them.
The Java program below takes the user’s input and echoes it back on the screen. This is a wonderful program, but (like many college administrators) it doesn’t seem to be particularly useful.Take a look at a more useful application of Java’s String type.import java.util.Scanner;import static java.lang.System.out; class ProcessMoreData { public static void main(String args[>) {Scanner keyboard = new Scanner(System.
After you’ve created an array in Java, you can put values into the array’s components. For example, imagine you are the owner of a motel. The guests in Room 6 are fed up with all those mint candies that you put on peoples’ beds. They check out, and Room 6 becomes vacant. You should put the value 0 into the 6 component.
Here’s a Java riddle: You have two baseball teams — the Hankees and the Socks. You want to display the teams’ scores on two separate lines, with the winner’s score listed first. (On the computer screen, the winner’s score is displayed above the loser’s score.) What happens when the scores are tied?Do you give up?
To write the Java program you see below, you need a loop — a loop that repeatedly asks the user whether the importantData.txt file should be deleted. The loop continues to ask until the user gives a meaningful response./** DISCLAIMER: Neither the author nor John Wiley & Sons,* Inc., nor anyone else even remotely connected with the* creation of this book, assumes any responsibility* for any damage of any kind due to the use of this code,* or the use of any work derived from this code,* including any work created partially or in full by* the reader.
You will probably find times when programming with Java that you need to display a window on your computer screen. This code has very little logic of its own. Instead, this code pulls together a bunch of classes from the Java API. import javax.swing.JFrame; import javax.swing.ImageIcon; import javax.swing.JLabel; class ShowPicture { public static void main(String args[]) { var frame = new JFrame(); var icon = new ImageIcon("androidBook.
The Java API (Application Programming Interface) has thousands of identifiers. Each identifier is the name of something (a class, an object, a method, or something like that). These identifiers include System, out, println, String, toString, JFrame, File, Scanner, next, nextInt, Exception, close, ArrayList, stream, JTextField, Math, Random, MenuItem, Month, parseInt, Query, Rectangle, Color, Oval, paint, Robot, SQLData, Stack, Queue, TimeZone, URL, and so many others.
In your own Java program, you can make up names to your heart's delight. For example, in the codedouble multiplyByTwo(double myValue) { return myValue * 2; }the names multiplyByTwo and myValue are your very own identifiers.When you create a new name, you can use letters, digits, underscores (_), and dollar signs ($).
The Java programming language has 50 keywords. Each keyword has a specific meaning in the language. You can't use a keyword for anything other than its pre-assigned meaning.The following table lists Java's keywords. Keyword What It Does abstract Indicates that the details of a class, a method, or an interface are given elsewhere in the code.
In addition to its keywords, three of the words you use in a Java program are called literals. Each literal has a specific meaning in the language. You can't use a literal for anything other than its pre-assigned meaning.The following table lists Java's literal words. Literal What It Does false One of the two values that a boolean expression can possibly have.
In Listing 1, below, you get a blast of Java code. Like all novice programmers, you're expected to gawk humbly at the code. But don't be intimidated. When you get the hang of it, programming is pretty easy. Yes, it's fun, too.Listing 1: A Simple Java Program /* * A program to list the good things in life * Author: Barry Burd, BeginPro@allmycode.
When I was a young object, I wasn’t as smart as the objects you have nowadays. Consider, for example, the object in the code below This object not only displays itself, but it can also fill itself with values.importjava.util.Random;importjava.text.NumberFormat;import static java.lang.System.out; classBetterAccount {String lastName;int id;double balance;<strong> </strong><strong>void fillWithData() {</strong><strong>Random myRandom = new Random();</strong> <strong>lastName = "" +</strong><strong> </strong> <strong>(char) (myRandom.
You can make an enhanced for loop to step through a bunch of values, including an array’s values. Let’s take a look at an enhanced for loop that steps through an array’s values.To see such a loop, start with this code. The loop looks something like this:for (int roomNum = 0; roomNum < 10; roomNum++) {out.println(guestsIn[roomNum]);}To turn this into an enhanced for loop, you make up a new variable name.
For Java programmers the switch statement can be a useful piece of code. But, there are a few things you should know before you use it. A switch statement can take the following form:switch (Expression) {case <em>FirstValue</em>:<em>Statements</em> case <em>SecondValue</em>:<em>MoreStatements</em> // ... more cases.
Ridding the editor of jagged underlines is cause for celebration. Eclipse likes the look of your Java code, so from that point on, it's smooth sailing. Right?Well, it ain't necessarily so. In addition to some conspicuous compile-time errors, your code can have other, less obvious errors.Imagine someone telling you to “go to the intersection, and then rurn tight.
When you call myRandom.nextInt(10) + 1 in Java, you get a number from 1 to 10. As a test, here’s a program that calls myRandom.nextInt(10) + 1Random myRandom=new Random();System.out.print(myRandom.nextInt(10) + 1);System.out.print(" ");System.out.print(myRandom.nextInt(10) + 1);System.out.print(" ");System.out.
A String is a bunch of characters in Java. It’s like having several char values in a row. To read a String value from the keyboard, you can call either next or nextLine: The methodnextreads up to the next blank space. For example, with the input Barry A. Burd, the statementsString firstName = keyboard.next();String middleInit = keyboard.
With the release of Java 9, the language has ten new words called restricted keywords. A restricted keyword has a specific meaning in the language, but only if you use that word in a specific way. For example, if you writerequires other.stuff;you tell Java that your program won't run unless it has access to some other code (the code contained in other.
When you start learning object-oriented programming, you may think that this class idea is a big hoax. Some geeks in Silicon Valley had nothing better to do, so they went to a bar and made up some confusing gibberish about classes. They don’t know what it means, but they have fun watching people struggle to understand it.
Do you ever get tired of writing the word System? This is a conundrum for Java programmers. After all, the following code has ten System.out.print lines. Shouldn’t your computer remember what out.print means?importjava.util.Scanner;<strong>import static java.lang.System.in;</strong><strong>import static java.lang.
Sometimes, error messages can strike fear into the heart of even the bravest programmer. Fortunately some helpful, calming advice is here — advice to help you solve the problem when you see one of these messages. NoClassDefFoundError You get this error when you're trying to run your code. So first ask yourself, did you attempt to compile the code?
There are a few things beginning Java programmers should know about variables and recycling. When you assign a new value to smallLetter, the old value of smallLetter gets obliterated. smallLetter is used twice, and bigLetter is used twice. That’s why they call these things variables.First, the value of smallLetter is R.
One Java instructor has an interesting policy. He said, “Sometimes when I’m lecturing, I compose a program from scratch on the computer. I do it right in front of my students. If the program compiles and runs correctly on the first try, I expect the students to give me a big round of applause.”At first, you may think this guy has an enormous ego, but you have to put things in perspective.
You can choose to go for a variation on a theme. Let’s take a look at assigning values in Java. Here, it takes two lines to give the amount variable its first value:double amount;amount = 5.95;You can do the same thing with just one line:double amount = 5.95;When you do this, you don’t say that you’re “assigning” a value to the amount variable.
If you were stuck on a desert Java island with only one kind of loop, what kind would you want to have? The answer is, you can get along with any kind of loop. The choice between a while loop and a for loop is about the code’s style and efficiency. It’s not about necessity.Anything that you can do with a for loop, you can do with a while loop as well.
When you are coding in Java, you will want to take the actual size of your code into consideration. Let’s look at an example. But first. here are today’s new vocabulary words: foregift (fore-gift) n.A premium that a lessee pays to the lessor upon the taking of a lease. hereinbefore (here-in-be-fore) adv.In a previous part of this document.
Have you ever asked yourself what would happen if you ran the same file writing program more than once in Java. Create the tiny program below and run the program twice. Then examine the program’s output file. The output file contains only two letters. Testing the import java.io.File;import java.io.FileNotFoundException;import java.
https://cdn.prod.website-files.com/6630d85d73068bc09c7c436c/69195ee32d5c606051d9f433_4.%20All%20For%20You.mp3

Frequently Asked Questions

No items found.