Java quiz
grarodQuestion 1 (1 point)
Select the line of Java code that will correctly declare a float variable named average and assign the variable a value of 3.4.
Question 1 options:
|
None of the above |
|
int average; average = 3.4; |
|
int average = 3.4D; |
|
int average = 3.4f; |
|
int average = 3.4; |
Save
Select the correct line of Java code to assign 1000 to an int variable named myValue.
Question 2 options:
|
int myValue = 1000; |
|
int myValue = 0x3E8; |
|
int myValue = 0b1111101000; |
|
All of the above |
|
None of the above |
Save
Which of the following is an invalid Java statement:
Question 3 options:
|
System.out.println("Hello, World! "); |
|
int d = 14; |
|
d++; |
|
x + y/100; |
|
None of the above |
Save
Which of the following statements is a comment in Java
Question 4 options:
|
/ This is a test |
|
public class Hello { |
|
// This is a test. // |
|
(String[] args) |
|
None of the above |
Save
Will the following Java code compile and run?
public class QuizItem { public static void main(String[] args) { final int age = 38; System.out.println("Age is " + Age); } }
Question 5 options:
|
Yes |
|
No |
Save
What is the output from the following Java code?
public class Week1Quiz {
public static void main (String[] args) {
System.out.println ("Welcome");
System.out.println ("to");
System.out.print ("UMUC!");
}
}
Question 6 options:
|
Welcome to UMUC! |
|
No output as the code will not compile. |
|
Welcome to UMUC |
|
None of the above |
|
WelcometoUMUC |
Save
What character is assigned to the variable myChar in the following line of Java code?
char value = '\u0023';
Question 7 options:
|
# |
|
y |
|
null |
|
? |
|
X |
Save
Will the following Java code compile and run without errors? public class QuizItem { public static void main(String[] args) { final int age = 38; age = 39; System.out.println("Age is " + age); } }
Question 8 options:
|
Yes |
|
No |
Save
You are designing a program for users to enter whole numbers that range from -200 to 2147483648. What Java data type will best satisfy this range of numbers?
Question 9 options:
|
int |
|
long |
|
byte |
|
char |
|
short |
Save
Given the following sequence of Java code: int var = 4; var++; var = var + 2; var--; var = -var; What is the final value of var?
Question 10 options:
|
4 |
|
-6 |
|
8 |
|
-9 |
|
None of the above |
Save
You are designing a program for users to enter whole numbers that range from -100 to 127. What Java data type will best and most efficiently satisfy this range of numbers?
Question 11 options:
|
int |
|
char |
|
byte |
|
long |
|
short |
Save
Given the following sequence of Java code: int var1 = 9; int var2 = 12; boolean failure = false; int result = failure ? var1 : var2; What is the value of result after executing the code?
Question 12 options:
|
12 |
|
9:12 |
|
9 |
|
3 |
|
0.75 |
Save
Select the Java code that will correctly declare a boolean variable named success and assign it a value of false.
Question 13 options:
|
Boolean success = true; |
|
int success = false; |
|
None of the above |
|
boolean success = 1; |
|
boolean success = 0; |
Save
Given the following sequence of Java code: int var1 = 9; int var2 = 12; int var3 = 12; Which of the following statements evaluate to true
Question 14 options:
|
var1 != var2 |
|
var1 < var2 |
|
var1 <= var2 |
|
var2 == var3 |
|
All of the above |
Save
What is the output from the following Java code?
public class Week1Quiz {
public static void main (String[] args) {
System.out.print ("Welcome");
System.out.print ("to ");
System.out.println ("UMUC");
System.out.print ("!");
}
}
Question 15 options:
|
WelcometoUMUC |
|
Welcome to UMUC |
|
Welcome to UMUC ! |
|
No output as the code will not compile. |
|
None of the above |
Save
What Java keyword can used to create a named constant?
Question 16 options:
|
static |
|
default |
|
final |
|
enum |
|
public |
Save
If we declared the following variables in Java
int age = 27; int cafe = 0xCAFE; int number1 =0b0001; What is the output for the following Java statement?
System.out.println(age + cafe + number1);
Question 17 options:
|
2720001 |
|
51994 |
|
54,false,A5194327 |
|
None of the above |
Save
A non-local boolean variable is declared with the following Java code:
boolean myVar;
What is the value of myVar?
Question 18 options:
|
true |
|
false |
|
null |
|
Unknown |
|
None of the above |
Save
Given the following sequence of Java code: int var1 = 4; int var2 = 6; int var3 = 10; int results = (var1 + var2) * var3 /(var1 + var3) - var2%var1; What is the values of results after executing the code?
Question 19 options:
|
6 |
|
5 |
|
-2 |
|
9 |
|
None of the above |
Save
Given the following sequence of Java code: int var1 = 9; int var2 = 12; int var3 = 12; Which of the following statements evaluate to true
Question 20 options:
|
(var1 == var2) || (var1 < var2) |
|
(var1 == var2) && (var1 < var2) |
|
!(var2 == var3) |
|
(var2 <= var3) && (var2 < var1) |
|
None of the above |
Save
What is the filename extension used for all Java source files.
Question 21 options:
|
.js |
|
.java |
|
.javac |
|
.cs |
|
None of the above |
Save
From the list of Java variable names below, select the illegal variable name.
Question 22 options:
|
K149a$ |
|
2ForMe |
|
XXXXXXXXXXXXXXYYYYYYYYYYYYYYYzzzzzzzzzzzzzzzz |
|
Johns1290sX4k |
|
NoneForYou |
Save
What must be installed on a computer to be able to run bytecodes?
Question 23 options:
|
Java Virtual Machine (VM) |
|
Microsoft Visual Basic |
|
Ubuntu Server |
|
Oracle Database (11g or higher) |
|
None of the above |
Save
What is the filename extension used for all Java compiled files.
Question 24 options:
|
.cs |
|
.javac |
|
.bytes |
|
.class |
|
None of the above |
Save
What development tool do you use to launch Java bytecodes?
Question 25 options:
|
java |
|
javadoc |
|
javac |
|
jconsole |
|
All of the above |