Chapter 8

What Java Does (and When)

IN THIS CHAPTER

check Making decisions with Java statements

check Repeating actions with Java statements

Human thought centers around nouns and verbs. Nouns are the “stuff,” and verbs are the stuff's actions. Nouns are the pieces, and verbs are the glue. Nouns are, and verbs do. When you use nouns, you say “book,” “room,” or “stuff.” When you use verbs, you say “do this,” “do that,” “tote that barge,” or “lift that bale.”

Java also has nouns and verbs. Java's nouns include int and String, along with Android-specific terms such as AppCompatActivity, EditText, and TextView. Java's verbs involve assigning values, choosing among alternatives, repeating actions, and taking other courses of action.

This chapter covers some of Java's verbs. (In the next chapter, I bring in the nouns.)

Making Decisions

When you’re writing Java programs, you’re continually hitting forks in roads. Did the user type the correct password? If the answer is yes, let the user work; if it’s no, kick the bum out. The Java programming language needs a way to make a program branch in one of two directions. Fortunately, the language has a way: It’s the if statement. The use of the if statement is illustrated in Listing 8-1.

LISTING 8-1: Using an if Statement

package com.allmycode.a08_01; ...

Get Java Programming for Android Developers For Dummies, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.