CMSC 255 Final Exam Review ACTUAL UPDATED QUESTIONS AND CORRECT
ANSWERS
Which of the following lines of code correctly writes System.out.println("Hello");
"Hello" to the screen.
Fill in the blanks in the main method code below: public static void main (String[] args) {
The class name does not have to be the same as the False
filename in a Java program.
The command to compile a Java program is: javac
_____________ Hello.java.
Explain the steps that need to happen to take code from 1. Code is written in a an IDE or editor.
it being written to it running and producing output. 2. Code is compiled into a class file or byte code.
3. The byte code is run by the virtual machine and results are outputted.
What does the virtual machine do? Choose all answers runs byte code
that apply. runs the class file
runs byte code
generates source code
runs the class file
Logic errors are the hardest errors to find. True
While running a program, it unexpectedly stops. What logic
type of error is that? Choose all answers that apply. runtime
syntax
logic
compilation
runtime
Write the algorithm (pseudo or Java code) for the double employeeBonus;
following computer problem: employeeBonus = (profit * 0.3) / numEmployees;
Deer Enterprise needs a program to calculate their if profit > 7000000000 {
employee bonus. The bonus is based on the profits for employeeBonus += 1000;
the past year. They will take 30% of the profits and divide }
that amount among the employees. In addition, if the
profits are more than 7,000,000,000, the employees will
get an extra $1000.
(I recommend using the Preformatted text option instead
of the Paragraph text option. You can change this with the
dropdown next to the font size drop down)
, What is a variable? Choose all parts below that are named
relevant. memory location
unnamed can change
named
file location
cannot change
memory location
can change
Name two primitive Java data types that represent whole int, byte
numbers.
Name two primitive Java data types that represent double, float
floating point numbers.
For each error shown below match it to the correct Compile-time error:
output: a compile-time error, run-time error, or no error. System.out.Println("Greetings, Planet Earth!");
Compile-time error:
float scale = 7854.345368564323;
Run-time error:
System.out.println();
Compile-time error:
System.out.println("I love VCU!")
No error:
System.out.print(45 % 342);
What is displayed in the following code segment? System.out.println(numerator / denominator);
int numerator = 34; 5
int denominator = 6;
System.out.println(numerator % denominator)
4
A part of a program that contains information about the comment
program but has no effect when the program runs is
called a ____________ _.
Given the following declaration statement, write a count++
statement that increments the value in the variable count.
int count = 0;
Write a constant statement to hold the value of discount, final double DISCOUNT = 0.15;
which is 15%. ________________________
(remember to use proper java naming conventions for
constants)
ANSWERS
Which of the following lines of code correctly writes System.out.println("Hello");
"Hello" to the screen.
Fill in the blanks in the main method code below: public static void main (String[] args) {
The class name does not have to be the same as the False
filename in a Java program.
The command to compile a Java program is: javac
_____________ Hello.java.
Explain the steps that need to happen to take code from 1. Code is written in a an IDE or editor.
it being written to it running and producing output. 2. Code is compiled into a class file or byte code.
3. The byte code is run by the virtual machine and results are outputted.
What does the virtual machine do? Choose all answers runs byte code
that apply. runs the class file
runs byte code
generates source code
runs the class file
Logic errors are the hardest errors to find. True
While running a program, it unexpectedly stops. What logic
type of error is that? Choose all answers that apply. runtime
syntax
logic
compilation
runtime
Write the algorithm (pseudo or Java code) for the double employeeBonus;
following computer problem: employeeBonus = (profit * 0.3) / numEmployees;
Deer Enterprise needs a program to calculate their if profit > 7000000000 {
employee bonus. The bonus is based on the profits for employeeBonus += 1000;
the past year. They will take 30% of the profits and divide }
that amount among the employees. In addition, if the
profits are more than 7,000,000,000, the employees will
get an extra $1000.
(I recommend using the Preformatted text option instead
of the Paragraph text option. You can change this with the
dropdown next to the font size drop down)
, What is a variable? Choose all parts below that are named
relevant. memory location
unnamed can change
named
file location
cannot change
memory location
can change
Name two primitive Java data types that represent whole int, byte
numbers.
Name two primitive Java data types that represent double, float
floating point numbers.
For each error shown below match it to the correct Compile-time error:
output: a compile-time error, run-time error, or no error. System.out.Println("Greetings, Planet Earth!");
Compile-time error:
float scale = 7854.345368564323;
Run-time error:
System.out.println();
Compile-time error:
System.out.println("I love VCU!")
No error:
System.out.print(45 % 342);
What is displayed in the following code segment? System.out.println(numerator / denominator);
int numerator = 34; 5
int denominator = 6;
System.out.println(numerator % denominator)
4
A part of a program that contains information about the comment
program but has no effect when the program runs is
called a ____________ _.
Given the following declaration statement, write a count++
statement that increments the value in the variable count.
int count = 0;
Write a constant statement to hold the value of discount, final double DISCOUNT = 0.15;
which is 15%. ________________________
(remember to use proper java naming conventions for
constants)