Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java - Ch. 1 - 6 Review

Total questions: 95

Worksheet time: 2hrs 19mins

Name
Class
Date
1.
If a program “Tester” is run from the command line as shown below, what is the value of args[0]?
java Tester sing a song
a)
"sing a song"
"sing a song"
b)
"song"
 "song"
c)
"a "
d)
"sing"
2.
Logic errors are easily identified when a program is compiled.
a)
True
b)
False
3.
Although not a requirement, it is Java standard that class identifiers begin with an uppercase letter and use other uppercase letters to improve readability. 
a)
True
b)
False
4.
Dots (or periods) in a Java statement are used to separate the names of the components that make up the statement.
a)
True
b)
False
5.
A compiler ignores whitespace between words and lines. 
a)
True
b)
False
6.
You must use the Java interpreter to translate the bytecode into executable statements before running a Java application.
a)
True
b)
False
7.
Using the void keywords in the main( ) method header indicates that a value will be returned by the main( ) method is called. 
a)
True
b)
False
8.
A Java identifier can contain only letters, digits, & , or number signs (pound signs).
a)
True
b)
False
9.
If an object's methods are well written, the user is unaware of the low-level details of how the methods are executed, and the user must simply understand the interface or interaction between the method and the object. 
a)
True
b)
False
10.
System software is used for tasks such as word processing, calculations and playing games. 
a)
True
b)
False
11.
Variables are named computer memory locations that hold values that might vary. 
a)
True
b)
False
12.
When we declare a variable, we tell Java to create space in memory for that variable. Which of the following will create space in memory for a variable?
a)
var = 1;
b)
var++;
c)
Pizza var = new Pizza();
d)
int var;
13.
Which of the following is used to output something to the screen?
a)
println();
b)
System.print("...");
c)
System.out.print("...");
d)
System.out(screen);
14.
Which of the following will NOT output to the screen and then place the output cursor on the next line?
a)
System.out.println("Hi");
b)
System.out.print("\nHi");
c)
System.out.print("Hi\n");
15.
Which code sample will output "Hello World" with each word on a separate line?
a)
System.out.print("Hello\nWorld");
b)
System.out.print("Hello" + "World");
c)
System.out.println("Hello World");
d)
System.out.print("Hello");
System.out.println("World");
16.
Which symbol is used to create a line comment?
a)
/*...*/
b)
//...//
c)
*/.../*
d)
//
17.
The rules of a programming language constitute its...
a)
Objects
b)
Logic
c)
Format
d)
Syntax
18.
The programming code you write is called ___ and the Java compiler converts it to___ for the Java Virtual Machine to execute.
a)
object code, source code
b)
source code, bytecode
c)
bytecode, object code
d)
object code, ASCII
19.
Computer memory locations are called
a)
addresses
b)
compilers
c)
variables
d)
objects
20.
Which of the following is a valid identifier, or name of a procedure or variable?
a)
weeklySales
b)
last character
c)
class
d)
2000yearproblem
21.
Which of the following assigns a value to the variable var?
a)
var = value;
b)
int var;
c)
System.out.println("var = value");
d)
value = var;
22.
Which is not one of the 8 primitive data types?
a)
String
b)
int
c)
double
d)
char
23.
The value 137.68 can be held by a variable of type..
a)
int
b)
String
c)
double
d)
Two of the answers above.
24.
How to you create a new Scanner object to get user input from the console?
a)
Scanner input = new Scanner();
b)
Scanner input = Scanner.System.in;
c)
Scanner input = new Scanner(System.in);
d)
Scanner input = new Scanner(console);
25.
If you use one of the next() methods to retrieve a numeric data type, what can you do to clear any newline (\n) the user may have entered from the input stream?
a)
Call nextLine()
b)
Call the same next() method again
c)
Call System.out.println("\n")
d)
The next() methods will clear all newlines, so nothing else needs to be done
26.
What happens if you call Scanner.nextInt() and the user has entered “abc”?
a)
You will receive the default value (0) for the data type
b)
The Scanner will automatically wait until the user enters a valid number
c)
The system will automatically prompt the user for a valid number
d)
Your program will throw an exception
27.
What is the result of calling hasNextByte() on your Scanner object if the user has entered
“abc” on the console?
a)
true
b)
false
c)
“abc”
d)
“a”
28.
What might you want to do before calling one of the Scanner input methods?
a)
Print a message to the console so the user knows what to do
b)
Recreate your Scanner object
c)
Clear the screen
d)
Print out a newline character (\n) so the user doesn’t have to press Enter
29.
What Scanner function would you call to get a double (floating point) value from the user
input?
a)
getDouble()
b)
nextDouble()
c)
double()
d)
readDouble()
30.
What Scanner function would you call to get a full line of user input?
a)
next()
b)
nextString()
c)
nextLine()
d)
readLine()
31.
Which if() statement will ensure you have 3 or more command-line parameters?
a)
if (args.length() > 1)
b)
if (args.length() > 2)
c)
if (args.length() > 3)
d)
if ((length(args) > 3)
32.
Why is it important to validate any expected parameters from the command-line?
a)
Your program may encounter an exception if you try to use a parameter that does not exist in the args array
b)
The JVM will add empty strings if there are not enough parameters
c)
Your program may crash if there are too many parameters
d)
Because the “args” variable could be null
33.
Which of the following expressions will give you the number of parameters passed into the main(String[] args) function?
a)
args.length
b)
length(args)
c)
args.size
d)
main.length
34.
If you type the command below on the command line, how many parameters will be passed to the Mystery program?
java Mystery data
a)
1
b)
0
c)
2
d)
3
35.
Which of the following keywords can be used to test a condition and make decisions in your program?
a)
if
b)
compare
c)
check
d)
assert
36.
What package contains the Scanner class?
a)
java.util
b)
java.lang
c)
java.system
d)
system.util
37.
If the user enters data "awesome" when you prompt for a number, what will happen when you call nextInt() to read the data?
a)
Your program will get an InputMismatchException
b)
Your program will get a NullReferenceException
c)
You will get a default 0 value if the data can't be parsed
d)
You will get some numeric value that represents the character 'a'
38.
What Scanner function can you call to see if a "short" data value is currently waiting on the input stream?
a)
hasNextShort()
b)
isShort()
c)
nextShort()
d)
parseShort()
39.
What keyword can be used to execute a block of logic when the tested "if" expression returns false?
a)
else
b)
then
c)
break
d)
while
40.
What should you remember to do after using any combination of the hasNext() and next() functions?
a)
Call nextLine() to clear the newline from the input stream
b)
Discard the Scanner object
c)
Close the input stream
d)
Nothing special needs to be done
41.
What do you need to do after a hasNextDouble() function returns false, meaning the user has entered something other than a double value?
a)
Call next() to read the unexpected data from the stream as a String
b)
Exit the program immediately
c)
Close the Scanner immediately
d)
Keep calling hasNextDouble() until the user enters correct data
42.
You cannot be certain ahead of time how many command-line parameters a Console program will receive.
a)
True
b)
False
43.
What does the myString variable contain after the following code sequence:
String myString = "hello number "; myString = myString + myString.length();
a)
"hello number "
b)
"13"
c)
null
d)
"hello number 13"
44.
What string is produced by this expression:
String.format("%1$s and %1$5s and %1$-5s",1,2,3))
a)
"1 and 2 and 3 "
b)
"1 and 25 and -35"
c)
"1 and 1 and 1 "
d)
"%11 and %115 and -%115"
45.
What string is produced by this expression:
String.format("%4$s %3$s %2$s %1$s",4,3,2,1)
a)
"%1$s %2$s %3$s %4$s"
b)
"1 2 3 4"
c)
"4 3 2 1"
d)
"1.0 2.0 3.0 4.0"
46.
Which line of code will result in myInt = 42 ?
a)
int myInt = Integer.parseInt ("42");
b)
int myInt = "42";
c)
int myInt = Integer("42").toString();
d)
int myInt = Integer.toString("42");
47.
Which line of code will result in myString = "1.7320508" ?
a)
String myString = Double.convert(1.7320508);
b)
String myString = String.format(1.7320508);
c)
String myString = Double.toString(1.7320508);
d)
String myString = Double("1.7320508");
48.
What is the default value of a reference variable after it is declared?
a)
null
b)
0
c)
false
d)
Random junk until you initialize it
49.
How would you declare and initialize a primitive wrapper class for the double data type that contains the value 1.0?
a)
Double myDouble = new Double(1.0);
b)
double myDouble = 4.0
c)
Double(4.0) = myDouble;
d)
double myDouble = 4.0F;
50.
Given the following code, what is the result of calling myString1.equals(myString2)?
String myString1 = "abc"; String myString2 = "ABC";
a)
True
b)
False
51.
Given the code below, is it true that myString1.equals(myString2) and myString2.equals(myString1) will produce the same result?
String myString1 = "abc"; String myString2 = "ABC";
a)
True
b)
False
52.
Given the code below, what is the value stored in result?
String myString = "quiz"; int result = myString.length();
a)
4
b)
3
c)
5
d)
An exception will be thrown.
53.
Given the code below, what is the value stored in result?
String myString = "quiz"; boolean result = myString.contains("Z");
a)
True
b)
False
54.
What is stored in the result variable by the following code?
String result = String.format("I'll take %5s please", "2");
a)
I'll take 2 please
b)
I'll take 2 please
c)
I'll take 5 please
d)
I'll take 5 please
55.
What is stored in the result variable by the following code?
String result = "Captain," + "incoming" + "message";
a)
Captain,incomingmessage
b)
Captain, incoming message
c)
Captain,
d)
incoming message
56.
What is stored in the result variable by the following code?
boolean myBool = true; String result = Boolean.toString(myBool);
a)
true
b)
false
c)
1
d)
0
57.
What is stored in the result variable by the following code?
int result = Integer.parseInt("fourty-two");
a)
A run-time exception will be shown
b)
42
c)
forty-two
d)
42.0
58.
How many copies of the value 42 are created by this code?
int myInt1 = 42; int myInt2 = myInt1; int myInt3 = myInt2;
a)
1
b)
2
c)
3
d)
It is impossible to tell.
59.
How would you print the following string to the console? "Nonsense", she said!
a)
System.out.println("Nonsense", she said!);
b)
System.out.println("\"Nonsense\", she said!");
c)
System.out.println(""Nonsense"", she said!");
d)
System.out.println(\"Nonsense\", she said!);
60.
How would you print the following string to the console? "Nonsense", she said!
a)
System.out.println("Nonsense", she said!);
b)
System.out.println("\"Nonsense\", she said!");
c)
System.out.println(""Nonsense"", she said!");
d)
System.out.println(\"Nonsense\", she said!);
61.
What is the best naming style to use for a variable that contains a count of the number of frogs in a pond?
a)
frog_count
b)
frogCount
c)
FrogCount
d)
All styles are equally valid; just be consistent
62.
What governs a numeric data type’s precision and range?
a)
The number of bytes in memory the data occupies
b)
The way the compiler interprets the data type at runtime
c)
The general category of the numeric data type
d)
The amount of CPU power applied to the program
63.
What properties on the Java numeric wrapper classes hold the largest and smallest possible values for that data type?
a)
MAX_VALUE and MIN_VALUE
b)
BIGGEST_VALUE and SMALLEST_VALUE
c)
MAX_NUM and MIN_NUM
d)
BIG_NUM and SMALL_VALUE
64.
After the following statement, what value is stored in the myInteger variable?
int myInteger;
a)
0
b)
1
c)
null
d)
impossible to tell; randomly assigned based on computer memory contents
65.
Which assignment statement correctly assigns a decimal value to the variable “myFloat” that was already declared as a float data type?
a)
myFloat = 2.1;
b)
myFloat = 2.1D;
c)
myFloat = 2.1F;
d)
myFloat = 2.1(float);
66.
Which data type would you use to hold a true or false value?
a)
short
b)
double
c)
int
d)
boolean
67.
Which of the following variable names is invalid?
a)
1place
b)
int
c)
SHOO FLY
d)
They are all invalid.
68.
What's wrong with always using the largest possible data type to store your data?
a)
Larger data types take more memory
b)
It's harder to apply mathematical operators to larger data types
c)
Larger data types are not available on smaller, older systems
d)
Nothing; you should alway use the largest possible data type
69.
If you needed to hold the integer value 36,493, which numeric data type would you use?
a)
int
b)
double
c)
short
d)
byte
70.
What are the two main categories of numeric data types as stored in computers?
a)
integer and floating point
b)
big and small
c)
positive and negative
d)
real and imaginary
71.
Which data type can hold exactly two different values?
a)
boolean
b)
char
c)
byte
d)
binary
72.
What is the smallest data type that can hold the value 126?
a)
byte
b)
short
c)
float
d)
int
73.
After the following code is run:
double num1 = 9.6; int num2 = (int)num1; What is the value in num2?
a)
9
b)
9.6
c)
6
d)
9.60
74.
What keyword do you use to ensure a variable can never change values while your program is running?
a)
final
b)
const
c)
static
d)
Variables can always be changed with an assignment statement
75.
Which statement correctly assigns the character value 'x' to the char variable myChar?
a)
char myChar = 'x';
b)
myChar as char = 'x';
c)
character myChar = "x";
d)
char myChar = "x";
76.
Which object is used to write output to the console?
a)
System.out
b)
System.in
c)
Console
d)
OutputStream
77.
What is the difference between the print() and println() functions?
a)
println() will automatically wrap to the next line; print() will not
b)
print() will automatically wrap to the next line; println() will not
c)
println() will accept any string; print() will ony take variables
d)
println() is only for output; print() can also be used to gather user input
78.
What text string is printed to the screen with this statement?
System.out.println("#\"##\\#");
a)
#"##\#
b)
#\"##\\#
c)
####
d)
None; there is a syntax error
79.
How will the Eclipse IDE identify compile-time errors in your program?
a)
With an audible warning
b)
With a red “X” in your text editor and a description in the “Problems” panel
c)
With a green squiggly underline in the text editor
d)
Eclipse cannot identify problems until you attempt to run the program.
80.
If you hover your mouse cursor over a function from the Java Class Library, what happens in an Eclipse system?
a)
The IDE will attempt to automatically execute that function
b)
The IDE will auto-complete your typing for that statement
c)
The IDE will check that statement for errors
d)
The IDE will display a pop-up tool-tip with reference documentation
81.
What concept does Eclipse use to group together related projects?
a)
Workspace
b)
Package
c)
Solution
d)
Source Control
82.
What handy Java documentation can you find online at Oracle’s website?
a)
Detailed help for the Java Class Library
b)
Specification for the Java language and the Java Virtual Machine
c)
Tutorials on how to write Java code
d)
All of these topics are available!
83.
When creating a new Java class in Eclipse, what checkbox should you remember to check for the class that will be run when the program is launched?
a)
public static void main(String[] args)
b)
abstract
c)
Generate comments
d)
All of these should be checked
84.
When creating a new Java project in Eclipse, which of the following are you allowed to specify?
a)
Project Name
b)
Project Location
c)
Inclusion of the main() function
d)
You can specify all of these things
85.
Which of the following subdirectory or filename and descriptions are not accurate for a default Eclipse project?
a)
“bin” – contains your output .class files
b)
“code” – contains your source .java files
c)
“.project” – contains the name of your project
d)
“.classpath” – contains build settings for your project
86.
How do you run your program from the Eclipse IDE?
a)
Click the green arrow button
b)
Select "Run" and then "Run" again from the menu
c)
Both of these are true
d)
Neither of these are true
87.
How much does Eclipse cost?
a)
Eclipse is free
b)
$25 per developer
c)
$99 per year
d)
Depends on where you buy it
88.
Who currently manages Eclipse?
a)
The Eclipse Foundation
b)
IBM
c)
Sun Microsystems
d)
Microsoft
89.
How many projects can belong to an Eclipse workspace?
a)
0, 1, or more
b)
Only 1
c)
Up to 3
d)
A workspace and a project are exactly the same thing
90.
What area in the Eclipse interface holds a tree showing the projects and components in your workspace?
a)
Package Explorer
b)
Toolbar
c)
Menu
d)
Main working area
91.
Which of the following are important to include in a ZIP file to represent your entire project?
a)
All of these
b)
.classpath file
c)
.settings file
d)
"src" directory
92.
You can get pop-up help on Java and the Java Class library while typing in the main source editor.
a)
True
b)
False
93.
What does the top-left corner of the web page contain on the online Java reference documentation website?
a)
A list of Java packages
b)
Java class names
c)
Java functions
d)
A toll-free help phone#
94.
Where does Eclipse store your *.class output files by default?
a)
"bin" directory
b)
"class" directory
c)
In the root of the project directory
d)
"java" directory
95.
If the name of the class in your source code is “Tester”, what must the corresponding *.java filename be?
a)
Class_Tester.java
b)
Tester_Class.java
c)
Tester.java
d)
Anything you like; filenames do not have to match the class names