Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
53 Cards in this Set
- Front
- Back
In the java program use variables for what? |
To stare values. |
|
Int cansPerPack = 6; is a reference to what? |
Declares a variable named cans PerPack: |
|
Variable |
A symbol in a program that identifies a storage location that can hold different values |
|
When declaring a variable, you usually want? |
to initialize it |
|
Initialization |
Setting a variable to well-defined value when it is created. |
|
Type |
A named set values and the operations that can be carried out with them. |
|
Integer |
A number that cannot have a fractional part. |
|
int cans = 6; is what in english |
Declares an integer variable and initializes it with 6 |
|
int total = cans + bottles; is what in english |
The inital value need not be fixed value. (of course, cans and bottles must have been previously declared. |
|
bottles = 1; is an error, why> |
The type is missing. This statementis not a declaration but an assignment of a new value to an existing variable |
|
Int volume = "2" ; is an error, why? |
You cannot initialize a number with a string |
|
int cansPerPack; is what in english |
Declares an integer variable without initializing it. This can be a cause for errors. |
|
int dollars, cents; is what type of englsih |
Declares two integer variables in a single statement. |
|
You use the int type to> |
denote a whole number without a fractional part. |
|
Floating-point number |
A number that can have a fractional part |
|
double is what in Java? |
we use this for floating - point numbers. |
|
double canVolume = 0.335; is what? |
its a floating - point variable |
|
Number literal |
A constant value in a program this is explicitly written as a number, such as -2 or 6.02214115E23 |
|
Rules with variables |
Name must start with a letter or underscore (_) character, and the remaining characters must be letters, numbers, or underscores. |
|
Camel case |
The uppercase letters in the middle of the name look like the humps of a camel. |
|
Case sensitive |
Distinguishing upper - and lowercase characters. |
|
Reserved word |
A word that has a special meaning in a programming language and therefore cannot be used as a name by the programmer. |
|
Variable names should start with? |
a lowercase letter. |
|
Class names should start with? |
an uppercase letter |
|
Can variables have spaces? |
No |
|
Assignment |
Placing a new value into a variable |
|
When a variable is defined with the reserved word final, what does that mean? |
its value can never change. |
|
Constants are commonly written? |
Using capital letter to distinguish them visually from regular vriables |
|
Comment |
An explanation to help the human reader understand a section of a program; ignored by the compiler |
|
// is used for? |
delimiter fro short comments |
|
*/ and /* is used for |
they are in closed for large comments |
|
/** is used for? |
Start a comment that explains the purposes of a program |
|
Declare a variable suitable for holding a the number of bottles inc ase. |
int bottlesPerCase = 8; it can have any variable name or a different initialization value but your variable should have type int. |
|
What is wrong with the following variable declaration? int ounces per liter = 28.35 |
You cannot have spaces in variable names the variable type should be double instead of int because it holds a fraction value there is a semicolon missing at the end of the statement |
|
Use the variables declared in self check 3 to display the total purchase price |
System.out.print("Total price: "); System.out.println(unitPrice * quantity); |
|
Some drinks are sold in four - packs instead of six - packs. How would you change the Volume1.java program to compute the total volume? |
change the declaration of canPerPack to int cansPerPack = 4; |
|
What is wrong with this comment? double canVolume = 0.355; /* Liters in a 12-ounce can // |
You need to use a */ delimiter to close a comment that begins with a /*: double canVolume = 0.355; /* Liters in a 12-ounce can */ |
|
Suppose the type of the cansPerPack variable in Volume1.java was changed from int to double. What would be the effect on the program? |
The program would compile, and it would display the same result. However, a -person reading the program might find it confusing that fractional cans are being considered. |
|
Why can't the variable totalVolume in the Volume1.java program be declared as final? |
Its value is modified by the assignment statement. |
|
How would you explain assignment using the parking space analogy? |
Assignment would occur when one car is replaced by another in the parking space. |
|
Expression |
A syntactical construct that is made up constants, variables, method calls, and the operators combining them. |
|
++ operator adds? |
1 to a variable |
|
-- operator |
subtracts 1 from the variable |
|
7/4 in Java will do what? |
it will be evaluated to 1 because 7 divided by 4 is 1 with a remainder of 3. This is a programming error. |
|
division in Java should only use numbers? |
That are fraction base numbers such as 7.0/4.0 7/4.0 7.0/4 |
|
% symbol is used for? |
remainder only such as 7 % 4 |
|
Modulus |
The % operator that computes the remainder of an integer division |
|
Modulus |
The % operator that computes the remainder of an integer division |
|
Call method |
Is used to take the square root of a number and powers |
|
Math.sqrt(x) is used for what? |
Squared root of a number |
|
Math.pow(x, n) is used for what? |
The power root |
|
b*(1+r/100)^n how is it written in linear arrangement |
b * Math.pow(1 + r / 100, n) |
|
Cast |
Explicitly converting a value from one type to a different type. For example, the cast from a floating-point number x to an integer is expressed in Java by the cast notation (int) x |