chapter 6 Flashcards

1
Q

what is the main thing computers do with data?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is a variable and what happens when you change the variable in your code?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is stored in a variable & what kinds of variables can be stored in a variable?

A

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.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is a variable type?

A

the kind of value stored in a variable is a variable type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a variable name and how is it different from a variable?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what else is a variable name besides the name of the variable itself?

A

a variable name is also an identifer– a name that you can make up in your own code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is an assignment statement ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In an assignment statement, the thing being assigned a value is always on what side of the equal sign?

A

In an assignment statement, the thing being assigned a value is always on the left side of the equal sign.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is hard coding values in Java, and why is getting input from the keyboard better for large programs?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is the difference between System.out.print and System.out.println?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what kind of special method is required for reading numbers as input from your keyboard?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is the difference between user and a programmer?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what happens if you dont use a prompt in your code with input methods?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what can be mistaken for an assignment statement?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

why wouldnt you use a quick fix when writing a prompt incorrectly?

A

If your prompt displays a misleading message, you misled the user. Java has no built-in feature that checks the appropriateness of a prompt. That’s not surprising. Most computer languages have no prompt-checking feature.

17
Q

what is the difference between an assignment statement or a declaration with an initialization?

A

an assignment statement is the same function but it’s appearance is that it is created with 2 lines instead of just one like a declaration with an initialization. the difference is that you can also do arithmatic with an initialization. also you can drag an initialization outside of a method after the class. but you cannot do the same with an assignment.

18
Q

show an example format of 3 initializations doing arithmatic to get the sum of all 3.

A

a = x;
b = y;
c = z;
d = a + b + c;

19
Q

what is not a varialble declaration?

A

it is not conidered to be a statement.

20
Q

what word must you add whenever you pull a declaration out of a static method ?

A

whenever you pull a declaration out of a static method, you have to add the word static at the beginning of the declaration.

21
Q

what can be said about adding several variables outside the method?

A

it is very possible to add multiple variables an initializations outside of a method and get the same effect

22
Q

when you have multiple declarations or multiple initializations what can you do to shorten the writing in your code?

A

you can combine multiple declarations and multiple initializations if they are the same type of variable.