Java Programming
Java Programming
Section 1
10. The function of Garbage Collection in Java is: Mark for Review
(1) Points
Memory occupied by objects with no reference is automatically reclaimed for reuse. (*)
As a Java programmer, we have to call the GC function specifically in order to manage the Java
Memory.
1. Which of the following statements is NOT true of the Java programming language? Mark for
Review
(1) Points
All source code is written in plain text files with the extension .java.
Java source code files are compiled into .class files by the javac command.
The javac command can be used to run a Java application. (*)
Correct Correct
2. Which of the following statements describe the Java programming language? Mark for Review
(1) Points
Correct Correct
3. Given the java snippet below:
int x;
int y=100;
(1) Points
Variable x resides in the stack area, and variable y resides in the heap of the JVM.
Variable x resides in the heap area, and variable y resides in the stack of the JVM (*)
Variable x stays in the heap area, and variable y resides in the method area of the JVM.
Correct Correct
4. Which of the following converts a human-readable file into a platform-independent code file
in Java? Mark for Review
(1) Points
JRE
JDK
java command
5. Java allows the same Java program to be executed on multiple operating systems. Mark for
Review
(1) Points
True (*)
False
Correct Correct
6. Which of the following statements describe Java technology? Mark for Review
(1) Points
It is a programming language.
It is a development environment.
It is a deployment environment.
7. During runtime, the Java platform loads classes dynamically as required. Mark for Review
(1) Points
True (*)
False
Correct Correct
8. One of the primary goals of the Java platform is to provide an interpreted, just-in-time run
time environment. Mark for Review
(1) Points
True (*)
False
(1) Points
Entire heap is 9350k.
The "Hello" String literal will be located in which memory area in the JVM during runtime? Mark
for Review
(1) Points
In the constant pool area of the run-time data area in the JVM. (*)
The str variable will be located in which memory area in the JVM during runtime? Mark for
Review
(1) Points
str will stay in the heap area of the run-time data area in the JVM.
str will stay in the method area of the run-time data area in the JVM.
str will stay in the stack area of the run-time data area in the JVM. (*)
str will stay in the heap area of the constant pool run-time data area in the JVM.
12. In which area of heap memory are newly created objects stored? Mark for Review
(1) Points
Survivor Space 0
Survivor Space 1
Eden (*)
Tenured
13. Which of the following allows the programmer to destroy an object referenced by x? Mark
for Review
(1) Points
x.remove();
x.finalize();
x.delete();
Correct Correct
14. Which of following statements describes Parallel and Serial Garbage collection? Mark for
Review
(1) Points
A Parallel garbage collector uses multiple threads to manage heap space. (*)
A Parallel garbage collector uses multiple threads to manage stack space.
15. Which of the following statements is NOT TRUE for the JVM heap? Mark for Review
(1) Points
Java Developer can explicitly allocate and deallocate the Heap Memory. (*)
Correct Correct
1. Given the java snippet below:
int x;
int y=100;
(1) Points
Variable x resides in the stack area, and variable y resides in the heap of the JVM.
Variable x resides in the heap area, and variable y resides in the stack of the JVM (*)
Variable x stays in the heap area, and variable y resides in the method area of the JVM.
Correct Correct
2. Which of the following statements describe the Java programming language? Mark for Review
(1) Points
Correct Correct
3. During runtime, the Java platform loads classes dynamically as required. Mark for Review
(1) Points
True (*)
False
Correct Correct
4. Which of the following statements is NOT TRUE about the JVM? Mark for Review
(1) Points
The JVM is a virtual Machine that acts as an intermediary layer between the Java Application and
the Native Operating System.
The JVM reads byte code from the class file, and generates machine code.
The JVM reads Java source code, and then translates it into byte code. (*)
(1) Points
Stack area
Method area
In the file
In the database
6. Java allows the same Java program to be executed on multiple operating systems. Mark for
Review
(1) Points
True (*)
False
Correct Correct
7. Which of the following converts a human-readable file into a platform-independent code file
in Java? Mark for Review
(1) Points
JRE
JDK
java command
Correct Correct
8. One of the primary goals of the Java platform is to provide an interpreted, just-in-time run
time environment. Mark for Review
(1) Points
True (*)
False
Correct Correct
9. Which of following statements describes Parallel and Serial Garbage collection? Mark for
Review
(1) Points
A Parallel garbage collector uses multiple threads to manage heap space. (*)
Correct Correct
(1) Points
Correct Correct
11. Which of the following statements is NOT TRUE for the JVM heap? Mark for Review
(1) Points
Java Developer can explicitly allocate and deallocate the Heap Memory. (*)
Correct Correct
The "Hello" String literal will be located in which memory area in the JVM during runtime? Mark
for Review
(1) Points
In the constant pool area of the run-time data area in the JVM. (*)
Incorrect Incorrect. Refer to Section 1 Lesson 2.
What estimated percentage of the Java objects will be promoted from Young space to Tenured
space? Mark for Review
(1) Points
0.2
0.4
0.6 (*)
0.8
0.9
(1) Points
x.remove();
x.finalize();
x.delete();
Correct Correct
The str variable will be located in which memory area in the JVM during runtime? Mark for
Review
(1) Points
str will stay in the heap area of the run-time data area in the JVM.
str will stay in the method area of the run-time data area in the JVM.
str will stay in the stack area of the run-time data area in the JVM. (*)
str will stay in the heap area of the constant pool run-time data area in the JVM.
Correct Correct
Section 2
1. Which of the following commands allows a developer to see the effects of a running java
application on memory and CPU? Mark for Review
(1) Points
javac
jvisualvm (*)
java
javap
Correct Correct
2. HotSpot has an HSDIS plugin to allow disassembly of code. Mark for Review
(1) Points
True (*)
False
Correct Correct
3. Which of the following commands is used to launch a java program? Mark for Review
(1) Points
javac
jvisualvm
java (*)
javap
4. Before we can use the jsat tool we first have to use the jps tool to obtain JVM process id
numbers. Mark for Review
(1) Points
True (*)
False
Correct Correct
5. Given the following information in the jdb tool, jdb paused at line 11:
10 x=100;
11 }
Code:
0: bipush 100
5: return
(1) Points
The line=11 means the jdb executed line 11 bytecode in the method1 method.
The bci=5 means the jdb executed the last bytecode instruction in the method1 method. (*)
The bci=5 means the jdb executed 5 lines of the source code.
6. The javac command can be used to display native code in Java Mark for Review
(1) Points
True
False (*)
7. The jsat tool can be used to monitor garbage collection information. Mark for Review
(1) Points
True (*)
False
3. Which of the following structures are contained in a Java class file? Mark for Review
(1) Points
minor_version
major_version
access_flags
The bytecode for a Java method is located in which structure in the Java class file? Mark for
Review
(1) Points
magic
access_flags
method_info (*)
major_version
Which structure in the Java class file contains the line number information for the original source
file? Mark for Review
(1) Points
method_info (*)
this_class
filed_info
cp_info
Which of the following commands can be used to translate Java source code into bytecode? Mark
for Review
(1) Points
java
javac (*)
jdb
jstat
Correct Correct
8. Which of the following commands can be used to monitor the Java Virtual Machine statistics?
Mark for Review
(1) Points
jstat (*)
javap
javac
jmap
9. Which of the following statements is NOT TRUE for the jdb command? Mark for Review
(1) Points
jdb can display the source code.
10. The class file contains the definition it inherits from the superclass. Mark for Review
(1) Points
True
False (*)
int i=888888;
(1) Points
The 888888 is an integer literal. After compile, the number will stay in the constant pool.
The variable i and the literal 888888 are stored in the method_info. (*)
Correct Correct
12. The attributes_count item indicates how many attributes are contained within a method.
Mark for Review
(1) Points
True (*)
False
10. Like in the Java source code file, one Java class file can contain multiple class definitions. Mark
for Review
(1) Points
True
False (*)
Correct Correct
Which of the following is the descriptor of the test method in the class file? Mark for Review
(1) Points
(java/lang/String;int)V
(Ljava/lang/String;I)V (*)
V(Ljava/lang/String;I)
(Ljava/lang/String;java.lang.Integer)V
void foo(){}
void draw(){}
(1) Points
The Circle class contains both the foo and draw method definitions.
The foo method definition is only contained in the Shape class. (*)
If a Circle object is instantiated, the constructor of Circle will call the constructor of Shape.
15. In a valid Java class file, the magic number is always: Mark for Review
(1) Points
42
CAFEBABE (*)
1.618
BABECAFE
Incorrect Incorrect. Refer to Section 2 Lesson 2.
Section 3
1. opcode invokespecial is used to invoke an instance initialization method. Mark for Review
(1) Points
True (*)
False
Correct Correct
(1) Points
True (*)
False
Correct Correct
3. To inspect bytecode, which option is used with the javap command to disassemble the class
file? Mark for Review
(1) Points
-a
-b
-c (*)
-d
4. Choose which opcode is used to load an int from the local variable to the operand stack. Mark
for Review
(1) Points
aload
iload (*)
iaload
iconst
(1) Points
True (*)
False
Correct Correct
6. Choose which opcode is used to push an int constant 5 onto the operand stack. Mark for
Review
(1) Points
iconst_5 (*)
idc5
iload_5
iaload_5
iinc5
7. .class files are loaded into memory all at once, when a Java application is launched. Mark for
Review
(1) Points
True
False (*)
8. The Java developer can define a number of additional or custom classloaders. Mark for
Review
(1) Points
True (*)
False
Correct Correct
9. Which of the following statements is NOT TRUE for the Class.forName("HelloClass") method?
(Choose three)
Class.forName("HelloClass");
}
(1) Points
The forName() method returns the Class object associated with the HelloClass.
The forName() method does not load the HelloClas class into the Java Runtime. (*)
In this example, the Class.forName("HelloClass") will use the ClassLoader which loads the Foo
class.
10. The process of linking involves which of the following processes? Mark for Review
(1) Points
verification
preparation
resolution
11. In the ClassLoader hierarchy, which of the following is the only class loader that does NOT
have a parent? Mark for Review
(1) Points
12. Which of the following exceptions is thrown by the loadClass() method of ClassLoader class?
Mark for Review
(1) Points
IOException
SystemException
ClassFormatError
ClassNotFoundException (*)
(1) Points
True (*)
False
Correct Correct
14. Which of the following from ClassLoader will load the rt.jar, the Java core clsses which are
present in the java.* package? Mark for Review
(1) Points
15. The System or Application ClassLoader loads Java classes from the System Classpath. This
classpath is set by the CLASSPATH environment variable. Mark for Review
(1) Points
True
False (*)
Section 4
String s= "a,b,c";
(1) Points
a,b
ac
a,b,c (*)
abc
Correct Correct
Which of following arguments can be passed into the method? (Choose Two) Mark for Review
(1) Points
Interface
3. Which three are valid declarations for a float value? (Choose Three) Mark for Review
(1) Points
float f = 3.0L;
float f = 0x345; (*)
float f = 1.0;
4. Which two statements prevent a method from being overriden? (Choose Two) Mark for
Review
(1) Points
6. Which of the following operators are relational operators?(Choose Two) Mark for Review
(1) Points
"+="
"!=" (*)
">=" (*)
"="
7. Which of the following operators are logic operators?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
&& (*)
<=
>
! (*)
i=i++;
j=i++;
(1) Points
2. Which statement is a syntactically correct way to declare an Array? Mark for Review
(1) Points
int i[1];
int[5] id={1,2,3,4,5};
3. Using the code below, what will be the output if a Student object is instantiated?
public Student()
System.out.print("1");
super();
System.out.print("2");
(1) Points
12
2
1
Correct Correct
4. What is the final value of result from the following code snippet?
int i = 1;
(1) Points
An exception is thrown.
Correct Correct
System.out.print("i=");
if(i==3)
break;
System.out.print(i);
(1) Points
i=0123456789
i=012 (*)
i=0123
i=012456789
public Student(){
studentId++;
return studentId;
System.out.println(Student.getStudentId());
(1) Points
7. Which of following relationships does not use inheritance? Mark for Review
(1) Points
(1) Points
Since a constructor can not return any value, it should be declared as void.
You can use access modifiers to control which other classes can call the constructor. (*)
You can declare more than one constructor in a class declaration. (*)
int i=0,j=0;
i=++i;
j=i++;
(1) Points
(1) Points
int x=0;
int y=5;
do{
++x;
y--;
}while(x<3);
22
3 2 (*)
23
33
byte b = 1;
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
int[] myarray={1,2,3,4,5};
int sum=0;
sum+=x;
(1) Points
10
20
15 (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
14. Which of following statments are true when you create a object from class Object at runtime
as seen below. (Choose Three)
(1) Points
This Object instance will not be created because you never defined class Object.
(1) Points
1. Which of following relationships does not use inheritance? Mark for Review
(1) Points
Correct Correct
int x=0;
int y=5;
do{
++x;
y--;
}while(x<3);
(1) Points
3 2 (*)
33
23
22
(1) Points
When no constructor is defined in the class, the compiler will create a default constructor.
if (i == 3) {
break;
(1) Points
5. A class can be extended by more than one class. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
System.out.println(str1.equals(c));
(1) Points
int i=0,j=0;
i=++i;
j=i++;
(1) Points
8. Which combination of the following overload the Student constructor?(Choose Two) Mark for
Review
(1) Points
9. Which two statements are access modifier keywords in Java?(Choose Two) Mark for Review
(1) Points
abstract
final
protected (*)
public (*)
(1) Points
11. When you instantiate a subclass, the superclass constructor will be also invoked. True or
False? Mark for Review
(1) Points
True (*)
False
Correct Correct
(1) Points
You can use access modifiers to control which other classes can call the constructor. (*)
Since a constructor can not return any value, it should be declared as void.
You can declare more than one constructor in a class declaration. (*)
13. Which ofthe following declarations are wrong?(Choose Three) Mark for Review
(1) Points
(1) Points
Correct Correct
15. What is the output from the following code snippet?
int x = 1;
int y;
while(++x < 5)
y++;
(1) Points
Section 5
(1) Points
True
False (*)
(1) Points
True
False (*)
(1) Points
True
False (*)
4. Unit testing can help you isolate problem quickly. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
5. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working
correctly before it is combined with other components in the system. True or false? Mark for
Review
(1) Points
True (*)
False
6. Which statement is true for the class java.util.ArrayList? Mark for Review
(1) Points
7. Which of the following is the correct way to throw cumstom ServerException? Mark for
Review
(1) Points
throw ServerException
throws ServerException
raise ServerException
Correct Correct
8. What symbol(s) is used to separate multiple exceptions in one catch statement? Mark for
Review
(1) Points
A single vertical bar | (*)
&&
class Shape{
System.out.print("Circle ");
try{new Circle().paint();}
catch(Exception e){System.out.println("Exception");
(1) Points
Circle
Shape
ShapeCircle
Exception
10. Assertions are boolean statements to test and debug your programs.
(1) Points
True (*)
False
Correct Correct
11. Which three types of objects can be thrown using a throw statement? (Choose Three) Mark
for Review
(1) Points
Error (*)
Event
Exception (*)
Throwable (*)
Object
Incorrect Incorrect. Refer to Section 5 Lesson 3.
12. The instanceof operator can find subclass objects when they are passed to method which
declare a superclass type parameter.
(1) Points
True (*)
False
Correct Correct
13. The instanceof operator allows you to determine the type of an object.
(1) Points
True (*)
False
Correct Correct
14. Which one of the following would allow you to define the abstract class Animal. Mark for
Review
(1) Points
public Animal{}
(1) Points
True (*)
False
(1) Points
True
False (*)
Correct Correct
2. Which one of the following would allow you to define an interface for Animal? Mark for
Review
(1) Points
public class Animal {}
(1) Points
True
False (*)
Correct Correct
4. The instanceof operator can find subclass objects when they are passed to method which
declare a superclass type parameter.
(1) Points
True (*)
False
Correct Correct
5. Which method will force a subclass to implement it? Mark for Review
(1) Points
Correct Correct
Section 5
(1) Points
I only
II only
I and II only (*)
None of these
2. Reading great code is just as important for a programmer as reading great books is for a
writer. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
3. Unit testing can help you isolate problem quickly. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
1.try {
(1) Points
5. What is one step you must do to create your own exception? Mark for Review
(1) Points
. Which statement added at line one allows the code to compile and run?
//line one
System.out.println("Java");
(1) Points
import java.io.OutputStreamWriter
include java.io.*;
import java.io.PrintWriter;
import java.io.*;
Incorrect Incorrect. Refer to Section 5 Lesson 3.
try(inputStream = "missingfile.txt");
catch(exception e);
(1) Points
True
False (*)
(1) Points
9. Virtual method invocation requires that the superclass method is defined as which of the
following? Mark for Review
(1) Points
(1) Points
True (*)
False
Correct Correct
interface Shape {}
(1) Points
Line 2
Line 3 (*)
Line 4
Line 1
Correct Correct
12. An abstract class can be instantiated.
(1) Points
True
False (*)
13. In general, classes can be made immutable by placing a final key word before the class
keyword.
(1) Points
False
True (*)
Correct Correct
14. The state of an object differentiates it from other objects of the same class.
(1) Points
True (*)
False
Correct Correct
15. Which one of the following would allow you to define an interface for Animal? Mark for
Review
(1) Points
Correct Correct
ection 5
(1) Points
2. Which statements are true when you compile and run this code.(Choose Two)
5. }
7. sayHello("Java");
8. }
(1) Points
The class Test compiles if line 6 contains a throws statement. public static void main(String[] args)
throws Exception{ (*)
The class Test compiles if line 7 is enclosed in a try-catch block. try{ sayHello("Java"); }
catch(Exception e){} (*)
Compilation succeeds
(1) Points
True (*)
False
Correct Correct
(1) Points
True (*)
False
try{
String[] s=null;
s[0]="Java";
System.out.println(s[0]);
}catch(Exception e) {
System.out.println("Exception");
}catch(NullPointerException e){
System.out.println("NullPointerException");
(1) Points
NullPointerException
Exception
6. A upward cast means all instance variables of the subclass are permanently lost to the instance.
(1) Points
True
False (*)
7. The instanceof operator can find subclass objects when they are passed to method which
declare a superclass type parameter.
(1) Points
True (*)
False
Correct Correct
(1) Points
True (*)
False
Correct Correct
9. You can't downcast an object explicitly because you must use virtual method invocation.
(1) Points
True
False (*)
10. Unit testing can help you isolate problem quickly. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
11. Which of the following statements about arrays and ArrayLists in Java are true?
IV. In an ArrayList you need to know the length and the current number of elements stored.
Mark for Review
(1) Points
II and IV only
None of these
12. Which statement is true for the class java.util.ArrayList? Mark for Review
(1) Points
(1) Points
True
False (*)
(Choose Two)
2. int accountID=100;
(1) Points
(1) Points
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 1.
(1) Points
True (*)
False
Correct Correct
3. You can't downcast an object explicitly because you must use virtual method invocation.
(1) Points
True
False (*)
Correct Correct
4. Which method will force a subclass to implement it? Mark for Review
(1) Points
Correct Correct
True
False (*)
(1) Points
None of them execute since you cannot have multiple catch statements.
Incorrect Incorrect. Refer to Section 5 Lesson 3.
7. Which statements are true when you compile and run this code.(Choose Two)
5. }
7. sayHello("Java");
8. }
(1) Points
Compilation succeeds
The class Test compiles if line 6 contains a throws statement. public static void main(String[] args)
throws Exception{ (*)
The class Test compiles if line 7 is enclosed in a try-catch block. try{ sayHello("Java"); }
catch(Exception e){} (*)
Correct Correct
try(inputStream = "missingfile.txt");
catch(exception e);
(1) Points
True
False (*)
Correct Correct
(1) Points
True (*)
False
Correct Correct
(1) Points
True
False (*)
(1) Points
True
False (*)
Correct Correct
12. Which one of the following would allow you to define an interface for Animal? Mark for
Review
(1) Points
(1) Points
In an Array you need to know the length and the current number of elements stored.
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 1
(1) Points
Memory occupied by objects with no reference is automatically reclaimed for reuse. (*)
As a Java programmer, we have to call the GC function specifically in order to manage the Java
Memory.
Correct Correct
2. Which of the following allows the programmer to destroy an object referenced by x? Mark for
Review
(1) Points
x.remove();
x.finalize();
x.delete();
Correct Correct
(1) Points
Correct Correct
4. Java allows the same Java program to be executed on multiple operating systems. Mark for
Review
(1) Points
True (*)
False
Correct Correct
5. Which of the following statements describe the Java programming language? Mark for Review
(1) Points
Correct Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 1
int x;
(1) Points
Variable x resides in the stack area, and variable y resides in the heap of the JVM.
Variable x resides in the heap area, and variable y resides in the stack of the JVM (*)
Variable x stays in the heap area, and variable y resides in the method area of the JVM.
Correct Correct
Section 2
(1) Points
True
False (*)
Correct Correct
8. Which of the following commands can be used to translate Java source code into bytecode?
Mark for Review
(1) Points
java
javac (*)
jdb
jstat
Correct Correct
9. Which of the following statements is NOT TRUE for the jdb command? Mark for Review
(1) Points
Correct Correct
10. Like in the Java source code file, one Java class file can contain multiple class definitions.
Mark for Review
(1) Points
True
False (*)
Correct Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 2
11. Which structure in the Java class file contains the line number information for the original
source file? Mark for Review
(1) Points
method_info (*)
this_class
filed_info
cp_info
Correct Correct
12. The attributes_count item indicates how many attributes are contained within a method.
Mark for Review
(1) Points
True (*)
False
Correct Correct
Section 3
13. Which of the following opcode instructions would add 2 integer variables? Mark for Review
(1) Points
add
addi
iadd (*)
14. Choose which opcode is used to push an int constant 5 onto the operand stack. Mark for
Review
(1) Points
iconst_5 (*)
idc5
iload_5
iaload_5
iinc5
Correct Correct
15. opcode invokespecial is used to invoke an instance initialization method. Mark for Review
(1) Points
True (*)
False
16. Which of the following is NOT a java class loader? Mark for Review
(1) Points
verification class loader (*)
Correct Correct
17. The Java developer can define a number of additional or custom classloaders. Mark for
Review
(1) Points
True (*)
False
Correct Correct
18. Which of the following exceptions is thrown by the loadClass() method of ClassLoader class?
Mark for Review
(1) Points
IOException
SystemException
ClassFormatError
ClassNotFoundException (*)
Correct Correct
Section 4
(1) Points
float f = 3.0L;
float f = 1.0;
Correct Correct
20. What is the final value of result from the following code snippet?
int i = 1;
(1) Points
An exception is thrown.
Correct Correct
Section 4
System.out.println( str1==str2 );
System.out.println( str1==str2.intern() );
(1) Points
int[] myarray={1,2,3,4,5};
int sum=0;
sum+=x;
(1) Points
10
15 (*)
20
Correct Correct
23. Examine the following Classes:
public Student(){
studentId++;
return studentId;
System.out.println(Student.getStudentId());
(1) Points
3
No output. Compilation of TestStudent fails (*)
Correct Correct
24. Which ofthe following declarations are wrong?(Choose Three) Mark for Review
(1) Points
Correct Correct
25. Which of the following types are primitive data types? (Choose Two) Mark for Review
(1) Points
String
boolean (*)
double (*)
Integer
Correct Correct
Previous Page 5 of 10 Next Summary
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 5
(1) Points
True
False (*)
Correct Correct
True
False (*)
Correct Correct
(1) Points
Correct Correct
29. Modeling classes for a business problem requires understanding of the business not Java.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
(1) Points
Correct Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 5
True
False (*)
Correct Correct
1 class Account {
4}
10 account.deposit(10);
11 }
(1) Points
line 7 (*)
line 2
line 3
line 6
Correct Correct
33. You can always upcast a subclass to an interface provided you don't need to access any
members of the concrete class.
(1) Points
True (*)
False
Correct Correct
34. Which two of the following statements are true? (Choose Two) Mark for Review
(1) Points
Correct Correct
(1) Points
True (*)
False
Correct Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 5
36. Virtual method invocation must be defined with the instanceof operator.
(1) Points
True
False (*)
Correct Correct
37. You can't downcast an object explicitly because you must use virtual method invocation.
(1) Points
True
False (*)
Correct Correct
38. Which of the following is the correct way to throw cumstom ServerException? Mark for
Review
(1) Points
throw ServerException
throws ServerException
raise ServerException
Correct Correct
(1) Points
try{
String[] s=null;
s[0]="Java";
System.out.println(s[0]);
}catch(Exception e) {
System.out.println("Exception");
}catch(NullPointerException e){
System.out.println("NullPointerException");
(1) Points
Exception
NullPointerException
Compile fails (*)
Java
Correct Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 5
41. Which statements are true when you compile and run this code.(Choose Two)
5. }
6. public static void main(String[] args){
7. sayHello("Java");
8. }
(1) Points
The class Test compiles if line 7 is enclosed in a try-catch block. try{ sayHello("Java"); }
catch(Exception e){} (*)
Compilation succeeds
The class Test compiles if line 6 contains a throws statement. public static void main(String[] args)
throws Exception{ (*)
Correct Correct
42. The finally clause only executes when an exception is not caught and thrown.
(1) Points
True
False (*)
Correct Correct
43. In what order do multiple catch statements execute? Mark for Review
(1) Points
None of them execute since you cannot have multiple catch statements.
Correct Correct
(1) Points
True
False (*)
Correct Correct
(1) Points
I only
II only
None of these
Correct Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.
Section 5
46. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working
correctly before it is combined with other components in the system. True or false? Mark for
Review
(1) Points
True (*)
False
Correct Correct
47. Why is it helpful for new programmers to read pre-written code?(Choose Two) Mark for
Review
(1) Points
Correct Correct
(1) Points
In an Array you need to know the length and the current number of elements stored.
Correct Correct
49. Which of the following statements about unit testing is/are true
I. When all unit tests succeed, you can have high confidence your code is solid.
II. If a unit test fails, you don メ t proceed until the code is fixed and the test succeeds.
III. Unit testing can help developer find problems early in the development cycle
(1) Points
I only
I and II only
None of these
Correct Correct
50. Which of the following statements about arrays and ArrayLists in Java are true?
(1) Points
II and IV only
None of these
14. Why is it helpful for new programmers to read pre-written code?(Choose Two) Mark for
Review
(1) Points
15. Which of the following statements about inheritance is false? Mark for Review
(1) Points
A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
Inheritance allows you to reuse the fields and methods of the super class without having to write
them yourself.
Inheritance allows you to minimize the amount of duplicate code in an application by sharing
common code among several subclasses.
Through inheritance, a parent class is a more specialized form of the child class. (*)
Incorrect Incorrect. Refer to Section 5 Lesson 4.
Section 6
(1) Points
True (*)
False
Correct Correct
2. Which of the following is a list of elements that have a first in last out ordering. Mark for
Review
(1) Points
Arrays
HashMaps
Enums
Stacks (*)
(1) Points
True
False (*)
It is a keyword in Java that restrict the use of the code to local users only.
Something that enables you to create a generic class without specifying a type between angle
brackets <>.
interface Shape {}
ls.add(c); // Line 3
lc.add(c); // Line 4
(1) Points
Line 2
Line 4
Line 1
Line 3 (*)
6. Which class is an ordered collection that may contain duplicates? Mark for Review
(1) Points
list (*)
enum
set
array
7. The following code is valid when working with the Collection Interface.
(1) Points
True
False (*)
Correct Correct
8. What is the output from the following code snippet?
li.add(1);
li.add(2);
print(li);
(1) Points
1 2 (*)
2
Incorrect Incorrect. Refer to Section 6 Lesson 1.
(1) Points
True (*)
False
Correct Correct
10. What is the correct definition of Enumeration (or enum)? Mark for Review
(1) Points
11. Which of the following would initialize a generic class "Cell" using a String type?
(1) Points
I and II (*)
II only
II and III
I only
III only
Incorrect Incorrect. Refer to Section 6 Lesson 1.
(1) Points
It utilizes the "divide and conquer" method, which makes the algorithm more error prone.
It requires incrementing through the entire array in the worst case, which is inefficient on large
data sets. (*)
It involves looping through the array multiple times before finding the value, which is inefficient
on large data sets.
It is never inefficient.
13. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort
arrays with optimal speed? Mark for Review
(1) Points
Sequential Search
Selection Sort
Binary Search
14. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first
index, finding the next smallest value and swapping it into the next index and so on until the array
is sorted.
(1) Points
True
False (*)
15. A sequential search is an iteration through the array that stops at the index where the
desired element is found.
(1) Points
True (*)
False
Correct Correct
Section 6
interface Shape {}
class Circle implements Shape{}
ls.add(c); // Line 3
lc.add(c); // Line 4
(1) Points
Line 3 (*)
Line 4
Line 1
Line 2
Correct Correct
2. Which of these could be a set? Why? Mark for Review
(1) Points
{1, 1, 2, 22, 305, 26} because a set may contain duplicates and all its elements are of the same
type.
{"Apple", 1, "Carrot", 2} because it records the index of the elements with following integers.
{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are of the same type. (*)
All of the above are sets because they are collections that can be made to fit any of the choices.
3. Which code inserted into the code below guarantees that the program will output [1,2]?
import java.util.*;
set.add(2);
set.add(1);
System.out.println(set);
(1) Points
4. Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches
on arrays. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
(1) Points
True
False (*)
6. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort
arrays with optimal speed? Mark for Review
(1) Points
Sequential Search
Selection Sort
Binary Search
7. A sequential search is an iteration through the array that stops at the index where the desired
element is found.
(1) Points
True (*)
False
Correct Correct
8. Enumerations (enums) are useful for storing data : Mark for Review
(1) Points
True
False (*)
Correct Correct
(1) Points
True
False (*)
Correct Correct
True or False?
class Node implements Comparable{
class Test{
Comparable com=nc;
(1) Points
True (*)
False
Correct Correct
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top
to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way
outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
13. Where you enqueue an element in the list? Mark for Review
(1) Points
(1) Points
True (*)
False
Correct Correct
(1) Points
True (*)
False
Correct Correct
(1) Points
True
False (*)
5. What is special about including a resource in a try statement?(Choose Two) Mark for Review
(1) Points
6. Why should you not use assertions to check parameters? Mark for Review
(1) Points
Assertions can be disabled at run time which may cause unexpected results in your assertions. (*)
Not all methods have parameters, therefore assertions should never be used on parameters.
15. When an object is able to pass on its state and behaviors to its children, this is called: Mark
for Review
(1) Points
Inheritance (*)
Encapsulation
Polymorphism
Isolation
Email This
BlogThis!
Share to Twitter
Share to Facebook
Share to Pinterest
81 comments:
Section 6
ArrayList (*)
ArrayList
ArrayList
ArrayList
2.Enumerations (enums) are useful for storing data :
When you already know all the possibilities for objects of that class. (*)
When you wish to remove data from memory.
When you want to be able to create any number of objects of that class.
True
False (*)
5.Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index,
finding the next smallest value and swapping it into the next index and so on until the array is
sorted.
True
False (*)
7.Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches
on arrays. True or false?
True (*)
False
8. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort
arrays with optimal speed?
Sequential Search
Selection Sort
Binary Search
vegetables[0] = "Cabbage";
vegetables += "Cabbage";
vegetables.get("Cabbage");
vegetables.add("Cabbage"); (*)
java.util.Map
java.util.List
java.util.Collection (*)
java.util.Collections
Something that enables you to create a generic class without specifying a type between angle
brackets <>.
12. To allow our classes to have a natural order we could implement the Comparable interface.
True or false?
True (*)
False
13.Which of the following is a list of elements that have a first in last out ordering.
Stacks (*)
HashMaps
Enums
Arrays
Because you can remove elements from the end of it. (*)
Because you can remove elements from the beginning of it. (*)
A pile of pancakes with which you add some to the top and remove them one by one from the top
to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way
outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
(1) Points
True (*)
False
Correct
(1) Points
True (*)
False
(1) Points
True (*)
False
Correct
4. Virtual method invocation requires that the superclass method is defined as which of the
following? Mark for Review
(1) Points
(1) Points
True (*)
False
Correct
6. Virtual method invocation occurs when you call a method from a superclass.
(1) Points
True
False (*)
Correct
7. Which of the following correctly initializes an object named cell of the class Telephones
whose generic type is Cellular? Mark for Review
(1) Points
8. Which one of the following can be used to declare a generic type. Mark for Review
(1) Points
All of the other responses (*)
Correct
9. Wildcards in generics allows us greater control on the types that can be used. Mark for
Review
(1) Points
True (*)
False
Correct
10. Interfaces define what? Mark for Review
(1) Points
(1) Points
True
False (*)
12. Which one of the following would allow you to define an interface for Animal. Mark for
Review
(1) Points
Correct
13. Which one of the following statements is true? Mark for Review
(1) Points
A class is an intance of an object
Correct
14. The state of an object differentiates it from other objects of the same class. Mark for
Review
(1) Points
True (*)
False
(1) Points
Correct
1. Which of the following would initialise a generic class "Cell" using a String type?
(1) Points
I only
II only
III only
I and II (*)
II and III
(1) Points
True
False (*)
Correct
3. The local petting zoo is writing a program to be able to collect be able to group animals
according to species to better keep track of what animals they have. Which of the following
correctly defines a collection that may create these types of groupings for each species at the zoo?
Mark for Review
(1) Points
public class
public class
animalCollection(AnimalType T) {…}
public class
animalCollection {…}
public class
animalCollection(animalType) {…}
4. Modeling classes for a business problem requires understanding of the business not Java.
True or false? Mark for Review
(1) Points
True
False (*)
Correct
5. Which one of the following would allow you to define an interface for Animal. Mark for
Review
(1) Points
Correct
(1) Points
True
False (*)
Correct
(1) Points
8. A method with public access level can be subclassed by? Mark for Review
(1) Points
(1) Points
True
False (*)
10. The instanceof operator is a boolean comparison operator. True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 2 Lesson 2.
11. Virtual method invocation occurs when you call a superclass method for a subclass with an
overriding method of the same name.
(1) Points
True (*)
False
12. Virtual method invocation requires that the superclass method is defined as which of the
following? Mark for Review
(1) Points
13. Which one of the following would allow you to define the abstract class Animal. Mark for
Review
(1) Points
public Animal
(1) Points
True
False (*)
Correct
(1) Points
True
False (*)
(1) Points
True (*)
False
2. A upward cast means all instance variables of the subclass are permanently lost to the
instance.
(1) Points
True
False (*)
Correct
4. The instanceof operator is a boolean comparison operator. True or false? Mark for Review
(1) Points
True (*)
False
(1) Points
True
False (*)
Correct
6. Calling a subclass method by referring to a superclass works because you have access to all
specialized methods through virtual method invocation.
(1) Points
True
False (*)
Correct
7. A method with public access can be subclassed.
(1) Points
True
False (*)
Correct
(1) Points
True
False (*)
9. You can only implement one interface in a class. Mark for Review
(1) Points
True
False (*)
Correct
(1) Points
(1) Points
True
False (*)
Correct
(1) Points
13. Which one of the following can be used to declare a generic type. Mark for Review
(1) Points
Correct
(1) Points
A generic instance
A concreate method.
A generic class
15. A generic class increases the risk of runtime class conversion exceptions. Mark for Review
(1) Points
True
False (*)
Correct
14. Arrays have built-in operations including add, clear, contains, get and remove.
True or false?
(0/1) Puntos
True
False (*)
Incorrect. Refer to Section 2 Lesson 1.
15. Unit testing is the phase in software testing in which individual software modules
are combined and tested as a whole. True or false?
(0/1) Puntos
True
False (*)
Incorrect. Refer to Section 2 Lesson 1.
Section 1
1. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working
correctly before it is combined with other components in the system. True or false? Mark for
Review
(1) Points
True (*)
False
Correct Correct
2. Unit testing is the phase in software testing in which individual software modules are
combined and tested as a whole. True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
3. Unit testing can help you isolate problem quickly. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
4. Which of the following statements about arrays and ArrayLists in Java are true?
IV. In an ArrayList you need to know the length and the current number of elements stored.
(1) Points
II and IV only
None of these
Correct Correct
5. Which of the following statements about inheritance is false? Mark for Review
(1) Points
A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
Inheritance allows you to reuse the fields and methods of the super class without having to write
them yourself.
Inheritance allows you to minimize the amount of duplicate code in an application by sharing
common code among several subclasses.
Through inheritance, a parent class is a more specialized form of the child class. (*)
Section 1
6. In the relationship between two objects, the class that is being inherited from is called the
maxi-class. True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. What is the final value of result from the following code snippet?
int i = 1;
(1) Points
An exception is thrown.
Correct Correct
int x=5;
if (x>6)
else if (x>=5)
else if (x<10)
else
(1) Points
x<10
x>=5 (*)
Correct Correct
class Foo{
this(i);
(1) Points
Section 2
10. Virtual method invocation requires that the superclass method is defined as which of the
following? Mark for Review
(1) Points
Section 2
11. A downward cast of a superclass to subclass allows you to access a subclass specialized
method call.
(1) Points
True (*)
False
Correct Correct
12. You can always upcast a subclass to an interface provided you don't need to access any
members of the concrete class.
(1) Points
True (*)
False
interface Shape {}
(1) Points
Line 1
Line 3 (*)
Line 2
Line 4
Correct Correct
4}
10 account.deposit(10);
11 }
(1) Points
line 3
line 7 (*)
line 6
line 2
Correct Correct
15. An abstract class can implement its methods.
(1) Points
True (*)
False
Section 2
16. Upward casting an object instance means you can't access subclass specific methods.
(1) Points
True (*)
False
Correct Correct
(1) Points
True
False (*)
(1) Points
Correct Correct
(1) Points
True
False (*)
(1) Points
Section 2
21. Modeling business problems requires understanding the interaction between interfaces,
abstract and concrete classes, subclasses, and enum classes. Mark for Review
(1) Points
True (*)
False
Correct Correct
22. Which one of the following would allow you to define an interface for Animal? Mark for
Review
(1) Points
(1) Points
True
False (*)
24. A generic class is a type of class that associates one or more non-specific Java types with it.
(1) Points
True (*)
False
Correct Correct
25. < ? extends Animal > would only allow classes or subclasses of Animal to be used.
(1) Points
True (*)
False
Correct Correct
Section 2
(1) Points
True
False (*)
(1) Points
True
False (*)
28. ArrayList and Arrays both require you to define their size before use.
(1) Points
True
False (*)
set.add(4);
System.out.print(element);
(1) Points
12134
11234
1234 (*)
1213
Correct Correct
(1) Points
Something that enables you to create a generic class without specifying a type between angle
brackets <>.
Section 2
31. Which code inserted into the code below guarantees that the program will output [1,2]?
import java.util.*;
set.add(2);
set.add(1);
System.out.println(set);
(1) Points
Correct Correct
32. A collection is an interface in the Java API.
(1) Points
True (*)
False
Correct Correct
TreeSet<String>t=new TreeSet<String>();
if (t.add("one"))
if (t.add("two"))
if (t.add ("three"))
t.add("four");
for (String s : t)
System.out.print (s); Mark for Review
(1) Points
onetwothreefour
fouronethreetwo (*)
twofouronethree
Correct Correct
(1) Points
{1, 1, 2, 22, 305, 26} because a set may contain duplicates and all its elements are of the same
type.
{"Apple", 1, "Carrot", 2} because it records the index of the elements with following integers.
{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are of the same type. (*)
All of the above are sets because they are collections that can be made to fit any of the choices.
35. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
log(n) (*)
n*log(n)
n^2
Section 2
(1) Points
True
False (*)
37. Big-O Notation is used in Computer Science to describe the performance of Sorts and
Searches on arrays. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
38. Which searching algorithm involves using a low, middle, and high index value to find the
location of a value in a sorted set of data (if it exists)? Mark for Review
(1) Points
Sequential Search
Merge Sort
Selection Sort
Correct Correct
39. A sequential search is an iteration through the array that stops at the index where the
desired element is found. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
40. Which of the following is the correct lexicographical order for the conents of the following
int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
41. A sequential search is an iteration through the array that stops at the index where the desired
element is found.
(1) Points
True (*)
False
Correct Correct
(1) Points
True
False (*)
Correct Correct
43. Which statements, inserted it at line 2, will ensure that the code snippet will compile
successfully.(Choose Two):
(1) Points
44. Why can a LinkedList be considered a stack and a queue?(Choose Three) Mark for Review
(1) Points
Because you can remove elements from the beginning of it. (*)
Because you can remove elements from the end of it. (*)
Correct Correct
(1) Points
True (*)
False
Section 2
46. Implementing the Comparable interface in your class allows you to define its sort order.
(1) Points
True (*)
False
Correct Correct
47. Nodes are components of LinkedLists, and they identify where the next and previous nodes
are.
True (*)
False
Correct Correct
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top
to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way
outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
(1) Points
It implements a stack.
Allows for insertion or deletion of elements from the first element added or the last one.
Correct Correct
50. To allow our classes to have a natural order we could implement the Comparable interface.
(1) Points
True (*)
False
(0/1) Puntos
True
False (*)
Incorrect. Refer to Section 3 Lesson 1.
11. Generic methods can only belong to generic classes.
True or False?
(0/1) Puntos
True
False (*)
1. What is the correct explanation of when this code will return true?
(1) Points
Any time that str contains two dots.
Any time that str has between zero and nine characters followed by a 6.
Always.
2. Which of the following methods for the String class take a regular expression as a parameter
and returns true if the string matches the expression? Mark for Review
(1) Points
compareTo(String regex)
equals(String regex)
matches(String regex) (*)
equalsIgnoreCase(String regex)
3. What is the function of the asterisk (*) in regular expressions? Mark for Review
(1) Points
Indicates that the preceding character may occur 0 or 1 times in a proper match.
Indicates that the preceding character may occur 0 or more times in a proper match. (*)
Indicates that the preceding character may occur 1 or more times in a proper match.
(1) Points
A class in the java.util.regex package that stores the format of a regular expression.
A class in the java.util.regex package that stores the matches between a pattern and a string. (*)
Correct
5. Matcher has a find method that checks if the specified pattern exists as a sub-string of the
string being matched.
(1) Points
True (*)
False
Correct
(1) Points
A class in the java.util.regex package that stores the format of a regular expression. (*)
7. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark
for Review
(1) Points
8. A linear recursion requires the method to call which direction? Mark for Review
(1) Points
Forward
Backward (*)
9. Which case does a recursive method call last? Mark for Review
(1) Points
Recursive Case
Convergence Case
Basic Case
Correct
10. A non-linear recursive method is less expensive than a linear recursive method. True or
false? Mark for Review
(1) Points
True
False (*)
Correct
11. A non-linear recursive method calls how many copies of itself in the recursive case? Mark for
Review
(1) Points
2 or more (*)
Correct
12. Using the FOR loop method of incrementing through a String is beneficial if you desire to:
(Choose all that apply) Mark for Review
(1) Points
(Choose all correct answers)
Read the String backwards (from last element to first element). (*)
13. Split is a method for Strings that parses a string by a specified character, or, if unspecified,
by spaces, and returns the parsed elements in an array of Strings.
(1) Points
True
False (*)
Correct
14. Which of the following correctly initializes a StringBuilder? Mark for Review
(1) Points
StringBuilder sb = StringBuilder(500);
15. Which of the following are true about the method split? Mark for Review
(1) Points
1. Matcher has a find method that checks if the specified pattern exists as a sub-string of the
string being matched.
(1) Points
True (*)
False
(1) Points
compareTo(String regex)
equals(String regex)
equalsIgnoreCase(String regex)
3. Which of the following does not correctly match the regular expression symbol to its proper
function? Mark for Review
(1) Points
"{x}" means there must be x occurrences of the preceding character in the string to be a match.
"?" means there may be zero or one occurrences of the preceding character in the string to be a
match.
"+" means there may be zero or more occurrences of the preceding character in the string to be a
match. (*)
"{x,}" means there may be x or more occurrences of the preceeding character in the string to be a
match.
"{x,y}" means there may be between x and y occurrences of the preceding character in the string
to be a match.
4. Consider designing a program that organizes your contacts alphabetically by last name, then
by first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the
first name and a group for the last name considering that the string contactsName is always in the
format lastName_firstName? Mark for Review
(1) Points
5. The following code correctly initializes a pattern with the regular expression "[0-9]{2}/[0-9]
{2}/[0-9]{2}".
(1) Points
True (*)
False
Incorrect. Refer to Section 3 Lesson 2.
6. In a regular expression, {x} and {x,} represent the same thing, that the preceding character may
occur x or more times to create a match.
(1) Points
True
False (*)
Correct
7. What is the correct explanation of when this code will return true?
(1) Points
Always.
8. Using the FOR loop method of incrementing through a String is beneficial if you desire to:
(Choose all that apply) Mark for Review
(1) Points
9. Which of the following are true about the method split? Mark for Review
(1) Points
10. Identify the method, of those listed below, that is not available to both StringBuilders and
Strings? Mark for Review
(1) Points
length()
indexOf(String str)
charAt(int index)
11. Which of the following methods are specific to StringBuilders? Mark for Review
(1) Points
append
delete
insert
replace
12. A non-linear recursive method can call how many copies of itself? Mark for Review
(1) Points
2 or more (*)
None
Correct
13. The base case condition can work with a constant or variable. True or false? Mark for
Review
(1) Points
True (*)
False
14. Forward thinking helps when creating linear recursive methods. True or false? Mark for
Review
(1) Points
True
False (*)
Correct
15. A linear recursive method directly calls how many copies of itself in the recursive case?
Mark for Review
(1) Points
0
1 (*)
2 or more
1. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark for
Review
(1) Points
Matcher m = str.matcher(p);
(1) Points
Any time that str has between zero and nine characters followed by a 6.
Always.
3. Your teacher asks you to write a segment of code that returns true if String str contains zero
or one character(s) and false otherwise. Which of the following code segments completes this
task? Mark for Review
(1) Points
(Choose all correct answers)
return str.contains(".");
{ return true;}
return str.matches("[a-z]*");
4. In a regular expression, {x} and {x,} represent the same thing, that the preceding character
may occur x or more times to create a match.
(1) Points
True
False (*)
Correct
5. Consider designing a program that organizes your contacts alphabetically by last name, then
by first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the
first name and a group for the last name considering that the string contactsName is always in the
format lastName_firstName? Mark for Review
(1) Points
6. The following code correctly initializes a pattern with the regular expression
"[0-9]{2}/[0-9]{2}/[0-9]{2}".
(1) Points
True (*)
False
7. Matcher has a find method that checks if the specified pattern exists as a sub-string of the
string being matched.
(1) Points
True (*)
False
8. A non-linear recursive method is less expensive than a linear recursive method. True or
false? Mark for Review
(1) Points
True
False (*)
Correct
9. Which case handles the last recursive call? Mark for Review
(1) Points
10. A non-linear recursive method is less expensive than a linear recursive method. True or
false? Mark for Review
(1) Points
True
False (*)
11. A linear recursive method directly calls how many copies of itself in the recursive case? Mark
for Review
(1) Points
0
1 (*)
2 or more
12. Which of the following are true about the method split? Mark for Review
(1) Points
13. Using the FOR loop method of incrementing through a String is beneficial if you desire to:
(Choose all that apply) Mark for Review
(1) Points
Read the String backwards (from last element to first element). (*)
14. Which of the following correctly initializes a StringBuilder? Mark for Review
(1) Points
StringBuilder sb = "This is my String Builder";
StringBuilder sb = StringBuilder(500);
15. Which of the following are true about parsing a String? Mark for Review
(1) Points
(1) Points
2. Using the FOR loop method of incrementing through a String is beneficial if you desire to:
(Choose all that apply) Mark for Review
(1) Points
Read the String backwards (from last element to first element). (*)
3. What class is the split() method a member of? Mark for Review
(1) Points
Parse
String (*)
Array
StringBuilder
Correct
4. Split is a method for Strings that parses a string by a specified character, or, if unspecified, by
spaces, and returns the parsed elements in an array of Strings.
(1) Points
True
False (*)
Correct
5. Your teacher asks you to write a segment of code that returns true if String str contains zero
or one character(s) and false otherwise. Which of the following code segments completes this
task? Mark for Review
(1) Points
(Choose all correct answers)
return str.matches("[a-z]*");
{ return true;}
return str.contains(".");
6. Consider designing a program that organizes your contacts alphabetically by last name, then by
first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the
first name and a group for the last name considering that the string contactsName is always in the
format lastName_firstName? Mark for Review
(1) Points
7. What does the dot (.) represent in regular expressions? Mark for Review
(1) Points
8. One benefit to using groups with regular expressions is that you can segment a matching
string and recall the segments (or groups) later in your program.
(1) Points
True (*)
False
(1) Points
True (*)
False
10. Consider that you are writing a program for analyzing feedback on the video game you have
developed. You have completed everything except the segment of code that checks that the user's
input, String userI, is a valid rating. Note that a valid rating is a single digit between 1 and 5
inclusive. Which of the following segments of code returns true if the user's input is a valid rating?
Mark for Review
(1) Points
return userI.matches("{1-5}");
return userI.matches("[1-5].*");
(1) Points
Any symbol in regular expressions that indicates the number of occurrences a specified character
appears in a matching string. (*)
12. A non-linear recursive method is less expensive than a linear recursive method. True or
false? Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 3 Lesson 3.
13. Forward thinking helps when creating linear recursive methods. True or false? Mark for
Review
(1) Points
True
False (*)
Correct
14. A linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1 (*)
2 or more
None
Incorrect. Refer to Section 3 Lesson 3.
15. Which case does a recursive method call last? Mark for Review
(1) Points
Recursive Case
Convergence Case
Basic Case
6. Square brackets are a representation for any character in regular expressions "[ ]".
(1) Points
True
False (*)
Which of the following methods are specific to StringBuilders? Mark for Review
(1) Points
append
delete
insert
replace
String (*)
Parse
Array
StringBuilder
StringBuilder sb = StringBuilder(500);
4. Using the FOR loop method of incrementing through a String is beneficial if you desire to:
(Choose Three)
Read the String backwards (from last element to first element). (*)
True or false?
True
False (*)
char[] ca = "java";
True or false?
True
False (*)
9. Your teacher asks you to write a segment of code that returns true if String str contains zero or
one character(s) and false otherwise. Which of the following code segments completes this task?
(Choose Two)
return str.contains(".");
return str.matches("[a-z]*");
{ return true;}
return userI.matches("[1-5].*");
return userI.matches("{1-5}");
11. The following code correctly initializes a pattern with the regular expression
"[0-9]{2}/[0-9]{2}/[0-9]{2}".
True or false?
True (*)
False
12. Which of the following does not correctly match the regular expression symbol to its proper
function?
"{x}" means there must be x occurrences of the preceding character in the string to be a match.
"?" means there may be zero or one occurrences of the preceding character in the string to be a
match.
"+" means there may be zero or more occurrences of the preceding character in the string to be a
match. (*)
"{x,}" means there may be x or more occurrences of the preceeding character in the string to be a
match.
"{x,y}" means there may be between x and y occurrences of the preceding character in the string
to be a match.
Indicates that the preceding character may occur 0 or 1 times in a proper match.
Indicates that the preceding character may occur 0 or more times in a proper match. (*)
14. Square brackets are a representation for any character in regular expressions "[ ]".
True or false?
True
False (*)
symbol in regular expressions that indicates the number of occurrences a specified character
appears in a matching string. (*)
16. Which statement added at line one allows the code to compile and run?
//line one
System.out.println("Java");
include java.io.*;
import java.io.OutputStreamWriter
import java.io.PrintWriter;
import java.io.*;
17. What is one step you must do to create your own exception?
True or false?
True
False (*)
try {return;}
The code compiles and prints out モ you are in Finally" (*)
None of them execute since you cannot have multiple catch statements.
21. Multiple exceptions can be caught in one catch statement.
True or false?
True (*)
False
22. The finally clause only executes when an exception is not caught and thrown.
True or false?
True
False (*)
/data
\Users\UserName\data
/home/user/username
C:\Users\UserName\data (*)
24, Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.
True or false?
True (*)
False
25. An absolute path always starts from the drive letter or mount point.
True (*)
False
26. The normalize() method removes redundant name elements from a qualified path.
True or false?
True (*)
False
27. The Paths class provides a static get() method to find a valid Path.
true or false?
True (*)
False
A PrintStream (*)
A BufferedReader stream
A Reader stream
A BufferedWriter stream
An OutputStream
30. The Files class provides a instance method that creates a new BufferedReader.
True or false?
True (*)
False
31. Which of the following files are not required to be uploaded to a web server to deploy a JWS
java application/applet?
jar files
JNLP files
html files
jar files
JNLP
JDBC (*)
True or false?
True (*)
False
It is a way to help resolve naming conflicts when different packages have classes with the same
sames.
True or false?
True (*)
False
38. A jar file is built on the ZIP file format and is used to deploy java applets.
True or false?
True (*)
False
39. What option do you choose from the File menu in Eclipse to start the process of creating a
runnable JAR file?
Export (*)
Switch Workspace
Properties
Import
True or false?
An example of two tier architecture would be a client application working with a server
application.
True or false?
True (*)
False
41. To deploy java applications you may use Java Web Start.
True or false?
True (*)
False
42. Which of the following are files that must be uploaded to a web server to deploy a Java
application/applet?(Choose Three)
.java files
43. How would you make an instance of Car in a class that didn't import the vehicle package
below?
package vehicle;
public Car(){}
44. If a class is in a package, the system's CLASSPATH must be altered to access the class.
True or false?
True
False (*)
45. An example of two tier architecture would be a client application working with a server
application.
True or false?
True (*)
False
46. Which two statements can create an instance of an array? (Choose Two)
char[] ca = "java";
12 or more (*)
None
1 (*)
2 or more
None
True or false?
True (*)
False
Matcher has a find method that checks if the specified pattern exists as a sub-string of the string
being matched.
True or false?
True (*)
False
Consider designing a program that organizes your contacts alphabetically by last name, then by
first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the
first name and a group for the last name considering that the string contactsName is always in the
format lastName_firstName?
Square brackets are a representation for any character in regular expressions "[ ]".
True or false?
True
False (*)
A class in the java.util.regex package that stores the matches between a pattern and a string. (*)
A class in the java.util.regex package that stores the format of a regular expression.
Consider that you are making a calendar and decide to write a segment of code that returns true if
the string month is April, May, June, or July. Which code segment correctly implements use of
regular expressions to complete this task?
return month.matches("April"|"May"|"June"|"July");
return month.substring(0,3);
Consider designing a program that organizes your contacts alphabetically by last name, then by
first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the
first name and a group for the last name considering that the string contactsName is always in the
format lastName_firstName?
True or false?
True (*)
False
Which of the following methods for the String class take a regular expression as a parameter and
returns true if the string matches the expression?
equals(String regex)
equalsIgnoreCase(String regex)
compareTo(String regex)
str += 23;
System.out.print(str);
23
91204
91227
9120423 (*)
StringBuilder sb = StringBuilder(500);
append
delete
insert
replace
Forward
Backward (*)
True or false?
True
False (*)
1 (*)
2 or more
None
True or false?
True
False (*)
File permissions are the same across all of the different operating systems.
True
False(*)
InputStream
FileInputStream
PipedInputStream
FilterInputStream(*)
InputStream
True(*)
False
throws ServerException
throw ServerException
raise ServerException
Bugs in code that make your program run different than expected (*)
try{
String[] s=null;
s[0]="Java";
System.out.println(s[0]);
}catch(Exception e) {
System.out.println("Exception");
}catch(NullPointerException e){
System.out.println("NullPointerException");
}
NullPointerException
Java
Exception
&&
The way that you read from a file has changed since the introduction of Java 7.
True or false?
True (*)
False
Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.
True or false?
True (*)
False
New dataInputStream("java.txt");
The new Paths class lets you resolve .. (double dot) path notation.
True or false?
True(*)
False
Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.
True or false?
True(*)
False
The java.io package has problems with no support for symbolic links.
True or false?
True(*)
False
Which three types of objects can be thrown using a throw statement? (Choose Three)
Object
Event
Error (*)
Throwable (*)
Exception (*)
Assertions can be disabled at run time which may cause unexpected results in your assertions. (*)
Not all methods have parameters, therefore assertions should never be used on parameters.
Bugs in code that make your program run different than expected (*)
True (*)
False
Which statements are true when you compile and run this code.(Choose Two)
5. }
7. sayHello("Java");
8. }
9. }
The class Test compiles if line 6 contains a throws statement. public static void main(String[] args)
throws Exception{ (*)
The class Test compiles if line 7 is enclosed in a try-catch block. try{ sayHello("Java"); }
catch(Exception e){} (*)
Compilation succeeds
True or false?
True (*)
False
import com.test.*,
import com.test.code.*
True or false?
True
False(*)
The import keyword allows you to access classes of the package without package Fully Qualified
Name.
True (*)
False
The import keyword allows you to access classes of the package without package Fully Qualified
Name.
True (*)
False
An example of two tier architecture would be a client application working with a server
application.
True or false?
True (*)
False
True or false?
True (*)
False
1. When an object is able to pass on its state and behaviors to its children, this is called: Mark for
Review
(1) Points
Inheritance (*)
Encapsulation
Isolation
Polymorphism
Correct
2. Which of the following are important to your survival as a programmer? Mark for Review
(1) Points
3. Which of the following statements about inheritance is false? Mark for Review
(1) Points
A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
Inheritance allows you to reuse the fields and methods of the super class without having to write
them yourself.
Inheritance allows you to minimize the amount of duplicate code in an application by sharing
common code among several subclasses.
Through inheritance, a parent class is a more specialized form of the child class. (*)
4. Which of the following is not a good technique to follow when reading code written by
others? Mark for Review
(1) Points
Perform testing.
Find the author of the code and ask him how it works. (*)
Understand the constructs.
Learn the high level structure and starting point, and then figure out how it branches.
5. Reading great code is just as important for a programmer as reading great books is for a
writer. True or false? Mark for Review
(1) Points
True (*)
False
Correct
6. Which of the following statements about arrays and ArrayLists in Java are true?
IV. In an ArrayList you need to know the length and the current number of elements stored. Mark
for Review
(1) Points
II and IV only
7. Unit testing is the phase in software testing in which individual software modules are
combined and tested as a whole. True or false? Mark for Review
(1) Points
True
False (*)
(1) Points
In an Array you need to know the length and the current number of elements stored.
9. When all unit tests succeed, you can have high confidence your code is solid. True or false?
Mark for Review
(1) Points
True (*)
False
10. Arrays have built-in operations including add, clear, contains, get and remove. True or
false? Mark for Review
(1) Points
True
False (*)
The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working
correctly before it is combined with other components in the system. True or false? Mark for
Review
(1) Points
True (*)
False
Correct
12. In the relationship between two objects, the class that is being inherited from is called the
maxi-class. True or false? Mark for Review
(1) Points
True
False (*)
Correct
13. Where are the quizzes for this course located? Mark for Review
(1) Points
academy.oracle.com
iacademy.oracle.com
ilearning.oracle.com (*)
Correct
14. What courses are part of the Oracle Academy? Mark for Review
(1) Points
Big Data
Java Fundamentals
Incorrect. Refer to Section 1 Lesson 1.
(1) Points
True (*)
False
Correct
1. Which of the following statements about inheritance is false? Mark for Review
(1) Points
A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
Inheritance allows you to reuse the fields and methods of the super class without having to write
them yourself.
Inheritance allows you to minimize the amount of duplicate code in an application by sharing
common code among several subclasses.
Through inheritance, a parent class is a more specialized form of the child class. (*)
Correct
public Car() {
(1) Points
Encapsulation
Inheritance (*)
Polymorphism
Comments
Correct
3. When all unit tests succeed, you can have high confidence your code is solid. True or false?
Mark for Review
(1) Points
True (*)
False
Correct
4. Why is it helpful for new programmers to read pre-written code? Mark for Review
(1) Points
5. Unit testing is the phase in software testing in which individual software modules are
combined and tested as a whole. True or false? Mark for Review
(1) Points
True
False (*)
Correct
6. In the relationship between two objects, the class that is being inherited from is called the
maxi-class. True or false? Mark for Review
(1) Points
True
False (*)
Correct
I. When all unit tests succeed, you can have high confidence your code is solid.
II. If a unit test fails, you don メ t proceed until the code is fixed and the test succeeds.
III. If all unit tests succeed, you should continue writing new tests until you break the code. Mark
for Review
(1) Points
I only
I and II only
8. Which of the following is not a good technique to follow when reading code written by
others? Mark for Review
(1) Points
Find the author of the code and ask him how it works. (*)
Learn the high level structure and starting point, and then figure out how it branches.
Perform testing.
Correct
9. When an object is able to pass on its state and behaviors to its children, this is called: Mark
for Review
(1) Points
Encapsulation
Polymorphism
Inheritance (*)
Isolation
Correct
10. Reading great code is just as important for a programmer as reading great books is for a
writer. True or false? Mark for Review
(1) Points
True (*)
False
Correct
11. Which of the following statements about arrays and ArrayLists in Java are true?
IV. In an ArrayList you need to know the length and the current number of elements stored. Mark
for Review
(1) Points
II and IV only
III. They both can be dynamically re-sized during execution of a program. Mark for Review
(1) Points
I only
II only
True (*)
False
Correct
14. Where are the quizzes for this course located? Mark for Review
(1) Points
ilearning.oracle.com (*)
academy.oracle.com
iacademy.oracle.com
Correct
15. What courses are part of the Oracle Academy? Mark for Review
(1) Points
Big Data
Java Fundamentals