chapter 6 Flashcards
what is the main thing computers do with data?
For all their complexity, the main business of computers is to move data from one place to another. Take a number — the balance in a person’s bank account. Move this number from the computer’s memory to the computer’s processing unit. Add a few dollars to the balance and then move it back to the computer’s memory. The movement of data
what is a variable and what happens when you change the variable in your code?
A variable is a placeholder. You can stick a number like 5.95 into a variable. After you’ve placed a number in the variable, you can change your mind and put a different number, like 30.95, into the variable. (That’s what varies in a variable.) Of course, when you put a new number in a variable, the old number is no longer there. If you didn’t save the old number somewhere else, the old number is gone.
what is stored in a variable & what kinds of variables can be stored in a variable?
The thing stored in a variable is called a value. A variable’s value can change during the run of a program. The value stored in a variable isn’t necessarily a number. (You can, for example, create a variable that always stores a letter.)
what is a variable type?
the kind of value stored in a variable is a variable type.
what is a variable name and how is it different from a variable?
There’s a subtle, almost unnoticeable difference between a variable and a variable’s name. Even in formal writing, I often use the word variable when I mean variable name. Strictly speaking, amount is the variable name, and all the memory storage associated with amount (including the value and type of amount) is the variable itself.
what else is a variable name besides the name of the variable itself?
a variable name is also an identifer– a name that you can make up in your own code.
what is an assignment statement ?
The statements with equal signs are called assignment statements. In an assignment statement, you assign a value to something. In many cases, this something is a variable.
In an assignment statement, the thing being assigned a value is always on what side of the equal sign?
In an assignment statement, the thing being assigned a value is always on the left side of the equal sign.
What is hard coding values in Java, and why is getting input from the keyboard better for large programs?
Hard coding values means directly embedding fixed values in the code, such as setting a variable to a specific number or string. Getting input from the keyboard is better for large programs because it allows flexibility, enabling users to provide different inputs without needing to modify the code. This reduces the risk of errors and saves time when changes are needed across the program.
what is the difference between System.out.print and System.out.println?
A call to System.out.print writes some things and leaves the cursor sitting at the end of the line of output. A call to System.out.println writes things and then finishes the job by moving the cursor to the start of a brand-new line of output.
what kind of special method is required for reading numbers as input from your keyboard?
In Java, each type of input requires its own, special method. If you’re getting a line of text, then nextLine works just fine. But if you’re reading stuff from the keyboard and you want that stuff to be interpreted as a number, you need a method like nextDouble.
what is the difference between user and a programmer?
When you write a program, you’re called a programmer, but when you run a program, you’re called a user. So when you test your own code, you’re being both the programmer and the user.
what would you have to put before an input method in order for the user to get an informative message on what to do first?
first you put a call to print and it puts an informative message on the user’s screen. A message of this kind is called a prompt.
what happens if you dont use a prompt in your code with input methods?
If you don’t have a call to print or println, the user sees no prompt. A blinking cursor sits quietly and waits for the user to type something. The user has to guess what kind of input to type. Occasionally that’s okay, but usually it isn’t.
what can be mistaken for an assignment statement?
The line double amount=5.95 isn’t called an “assignment statement.” Instead, this line is called a declaration with an initialization. You’re initializing the amount variable.