Programming Fundamental quiz 1-4 – Flashcards

Unlock all answers in this set

Unlock answers
question
A byte is a collection of:
answer
Eight bits
question
A computer program is
answer
a set of instructions that enable the computer to solve a problem or perform a task
question
A program is a sequence of instructions stored in:
answer
The computer's memory
question
A runtime error is usually the result of:
answer
A logical error.
question
Another term for programs is:
answer
software
question
Application software refers to:
answer
The programs that make the computer useful to the user.
question
An operating system can be categorized according to
answer
both of these: The number of users they can accommodate. The number of tasks they can perform at one time.
question
Because Java byte code is the same on all computers, compiled Java programs
answer
are highly portable.
question
Byte code instructions are
answer
read and interpreted by the JVM
question
Computer programming is
answer
both of these An art. A science.
question
Each different type of CPU has its own
answer
machine language
question
Java was developed by
answer
Sun Microsystems
question
Key words are
answer
words that have a special meaning in the programming language
question
RAM is usually
answer
a volatile type of memory, used only for temporary storage
question
Software refers to
answer
programs
question
Suppose you are at an operating system command line, and you are going to use the following command to compile a program: javac MyClass.java Before entering the command, you must
answer
Make sure you are in the same directory or folder where MyClass.java is located
question
Syntax is
answer
Rules that must be followed when writing a program.
question
The computer can do such a wide variety of tasks because
answer
it can be programmed
question
The major components of a typical computer system consist of
answer
All of these: The CPU. Input/output devices. Main memory. Secondary storage devices.
question
The purpose of validating the results of the program is
answer
to determine whether the program solves the original problem
question
A Java program must have at least one of these
answer
Class definition
question
A Java program will not compile unless it contains the correct line numbers...
answer
False
question
A variable's scope is the part of the program that has access to the variable.
answer
True
question
All Java statements end with semicolons
answer
False
question
Although the dollar sign is a legal identifier character, you should not use it because it is normally used for special purposes.
answer
True
question
Assuming that pay has been declared a double, the following statement is valid..pay = 2,583.44;
answer
False
question
Character literals are enclosed in ________; string literals are enclosed in ________.
answer
single quotes; double quotes
question
Every Java application program must have
answer
A method named main.
question
Given the declaration double r;, which of the following statements is invalid?
answer
r = 2.9X106
question
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result
answer
True
question
If the following Java statements are executed, what will be displayed? System.out.println("The top three winners aren"); System.out.print("Jody, the Giantn"); System.out.print("Buffy, the Barbarian"); System.out.println("Adelle, the Alligator");
answer
The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator
question
If x has been declared an int, which of the following statements is invalid?
answer
x = 1,000
question
In Java the variable named total is the same as the variable named Total.
answer
False
question
In Java, ________ must be declared before they can be used.
answer
Variables
question
In Java, it is standard practice to capitalize the first letter of
answer
Class names
question
In the following Java statement what value is stored in the variable name? String name = "John Doe";
answer
The memory address where "John Doe" is located
question
Java is a case-insensitive language.
answer
False
question
Named constants are initialized with a value, that value cannot be changed during the execution of the program.
answer
True
question
The term ________ typically refers to the device that displays console output.
answer
Standard output device
question
The boolean data type may contain values in the following range of values
answer
true or false
question
A Boolean expression is one that is either
answer
either true or false
question
A block of code is enclosed in a set of:
answer
braces { }
question
If chr is a character variable, which of the following if statements is written correctly?
answer
if (chr == 'a')
question
In an if/else statement, if the boolean expression is false,
answer
the statement or block following the else is executed
question
In a switch statement, each of the case values must be unique.
answer
True
question
The ________ statement is used to make simple decisions in Java.
answer
if
question
The expression tested by an if statement must evaluate to:
answer
true or false
question
The if/else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.
answer
True
question
The switch statement is a:
answer
Multiple alternative decision structure
question
This type of operator determines whether a specific relationship exists between two values
answer
Relational
question
What is the value of x after the following code has been executed? int x = 75; int y = 90; if (x ! = y) x += y;
answer
165
question
What will be the value of ans after the following code has been executed? int x = 10; int y = 65; if (x > = y) ans = x + y;
answer
120
question
What will be the value of bonus after the following code is executed? int bonus, sales = 10000 ; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;
answer
1000
question
What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x = x - y;
answer
15
question
What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }
answer
ans = 60, x = 0, y = 50
question
What would be the value of discountRate after the following statements are executed?
answer
0.0
question
What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default : x *= 3; }
answer
20
question
Which of the following expressions will determine whether x is less than or equal to y?
answer
x <= y
question
Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?
answer
((x > 500 && x < 650) || (y != 1000))
question
Which one of the following is the not equal operator?
answer
!=
question
A loop that repeats a specific number of times is known as a(n):
answer
count-controlled loop
question
A for loop normally performs which of these steps?
answer
all of the above
question
Before entering a loop to compute a running total, the program should first do this.
answer
Set the accumulator where the total will be kept to an initial value, usually zero
question
Each repetition of a loop is known as what?
answer
An iteration
question
How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 1000);
answer
1
question
How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x <= 1000);
answer
5
question
How many times will the following for loop be executed? for(int count=10; count<21; count++) System.out.println("Java is great!!!");
answer
11
question
If a loop does not contain within itself a way to terminate, it is called a(n):
answer
Infinite loop.
question
In a for statement, the control variable can only be incremented
answer
False
question
The do-while loop must be terminated with a semicolon
answer
True
question
The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true.
answer
True
question
This is a control structure that causes a statement or group of statements to repeat
answer
loop
question
This type of loop is ideal in situations where the exact number of iterations is known.
answer
for loop
question
This type of loop is ideal in situations where you always want the loop to iterate at least once.
answer
do-while loop
question
This type of loop will always be executed at least once.
answer
Post-test loop
question
What will be printed after the following code is executed? for (int number = 5; number <= 15; number +=3 System.out.print (number + ", ");
answer
5, 8, 11, 14,
question
What will be the value of x after the following code is executed? int x = 10, y = 20; while ( y < 100) { x += y; }
answer
This is an infinite loop.
question
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
answer
False
question
When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration
answer
True
question
Which of the following are pre-test loops?
answer
while, for
question
A parameter variable's scope is
answer
The method in which the parameter is declared.
question
A special variable that holds a value being passed into a method is called what?
answer
Parameter
question
Breaking a program down into small manageable methods:
answer
All of these.
question
If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?
answer
Control is returned to method C
question
If you attempt to use a local variable before it has been given a value:
answer
a compiler error will occur.
question
In a general sense, a method is
answer
A collection of statements that performs a specific task
question
Local variables
answer
All of these.
question
Methods are commonly used to break a problem into small manageable pieces
answer
True
question
The header of a value-returning method must specify this.
answer
The data type of the return value
question
The lifetime of a method's local variable is:
answer
Only while the method is executing.
question
The process of breaking a problem down into smaller pieces is sometimes called
answer
Divide and conquer.
question
This part of a method is a collection of statements that are performed when the method is executed.
answer
Method body
question
Two general categories of methods are void methods and value returning methods.
answer
True
question
Values that are sent into a method are called ________.
answer
arguments
question
What will be returned from the following method? public static int methodA() { double a = 8.5 + 9.5; return a ; }
answer
This is an error.
question
When an argument is passed to a method,
answer
Its value is copied into the method's parameter variable.
question
When an object, such as a String, is passed as an argument, it is:
answer
Actually a reference to the object that is passed.
question
When you pass an argument to a method, be sure that the argument's data type is compatible with:
answer
The parameter variable's data type.
question
Which of the following would be a valid method call for the following method? public static void showProduct (int num1, double num2) { int product; product = num1 * (int) num2; System.out.println("The product is " + product); }
answer
showProduct(10, 4.5);
question
You should always document a method by writing comments that appear:
answer
Just before the method's definition.
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New