You are on page 1of 331

java programming

Section 1

(Answer all questions in this section)

10. The function of Garbage Collection in Java is: Mark for Review

(1) Points

The JVM uses GC to clear the program output.

The JVM GC deletes all unused Java files on the system.

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. (*)

A .class file contains platform independent bytecode.

Correct Correct

2. Which of the following statements describe the Java programming language? Mark for Review

(1) Points

Java is a high-level programming language.

The Java programming language includes a garbage collection feature.

Java is an object oriented programming language.

All of the above (*)

Correct Correct
3. Given the java snippet below:

public class Foo{

int x;

public void testFoo(){

int y=100;

Which of the following statements is TRUE? Mark for Review

(1) Points

Compile error, as the variable x is not initialized.

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

javac command (*)

java command

Incorrect Incorrect. Refer to Section 1 Lesson 1.

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.

All of the above (*)

Incorrect Incorrect. Refer to Section 1 Lesson 1.

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

Incorrect Incorrect. Refer to Section 1 Lesson 1.

9. Given the following output from the Minor GC:

[GC [DefNew: 4032K->64K(4032K), 0.0429742 secs] 9350K->7748K(32704K), 0.0431096 secs]

Which of the following statements is TRUE? Mark for Review

(1) Points
Entire heap is 9350k.

Young Generation usage decreased by 3968k. (*)

The pause time spent in Young Generation is 0.0431096

The size of Eden space is 4032k.

Incorrect Incorrect. Refer to Section 1 Lesson 2.

10. Given the following code snippet:

String str = new String("Hello");

The "Hello" String literal will be located in which memory area in the JVM during runtime? Mark
for Review

(1) Points

In the Heap area of the run-time data area in the JVM.


In the Method area of the run-time data area in the JVM.

In the Stack area of the run-time data area in the JVM.

In the constant pool area of the run-time data area in the JVM. (*)

Incorrect Incorrect. Refer to Section 1 Lesson 2.

11. Given the following code snippet:

String str = new String("Hello");

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.

Incorrect Incorrect. Refer to Section 1 Lesson 2.

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

Incorrect Incorrect. Refer to Section 1 Lesson 2.

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();

Only the garbage collection system can destroy an object. (*)

Correct Correct

14. Which of following statements describes Parallel and Serial Garbage collection? Mark for
Review

(1) Points

A Serial garbage collector uses multiple threads to manage heap space.

A Parallel garbage collector uses multiple threads to manage heap space. (*)
A Parallel garbage collector uses multiple threads to manage stack space.

A Serial garbage collector uses multiple threads to manage stack space.

Incorrect Incorrect. Refer to Section 1 Lesson 2.

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. (*)

The Heap can be managed by the Garbage Collector.

The Heap can be shared among all Java threads.

Class instance and arrays are allocated in the Heap Memory.

Correct Correct
1. Given the java snippet below:

public class Foo{

int x;

public void testFoo(){

int y=100;

Which of the following statements is TRUE? Mark for Review

(1) Points

Compile error, as the variable x is not initialized.

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

Java is a high-level programming language.

The Java programming language includes a garbage collection feature.

Java is an object oriented programming language.

All of the above (*)

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 does not understand the Java language specification.

The JVM reads Java source code, and then translates it into byte code. (*)

Incorrect Incorrect. Refer to Section 1 Lesson 1.

5. Where does an object of a class get stored? Mark for Review

(1) Points
Stack area

Method area

In the file

In the database

Heap area (*)

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

javac command (*)

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 Serial garbage collector uses multiple threads to manage heap space.

A Parallel garbage collector uses multiple threads to manage heap space. (*)

A Parallel garbage collector uses multiple threads to manage stack space.

A Serial garbage collector uses multiple threads to manage stack space.

Correct Correct

10. Given the following output from the Minor GC:

[GC [DefNew: 4032K->64K(4032K), 0.0429742 secs] 9350K->7748K(32704K), 0.0431096 secs]


Which of the following statements is TRUE? Mark for Review

(1) Points

Entire heap is 9350k.

Young Generation usage decreased by 3968k. (*)

The pause time spent in Young Generation is 0.0431096

The size of Eden space is 4032k.

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. (*)

The Heap can be managed by the Garbage Collector.


The Heap can be shared among all Java threads.

Class instance and arrays are allocated in the Heap Memory.

Correct Correct

12. Given the following code snippet:

String str = new String("Hello");

The "Hello" String literal will be located in which memory area in the JVM during runtime? Mark
for Review

(1) Points

In the Heap area of the run-time data area in the JVM.

In the Method area of the run-time data area in the JVM.

In the Stack area of the run-time data area in the JVM.

In the constant pool area of the run-time data area in the JVM. (*)
Incorrect Incorrect. Refer to Section 1 Lesson 2.

13. Given the following output from the Minor GC:

[GC [DefNew: 4032K->64K(4032K), 0.0429742 secs] 9350K->7748K(32704K), 0.0431096 secs]

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

Incorrect Incorrect. Refer to Section 1 Lesson 2.


14. 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();

Only the garbage collection system can destroy an object. (*)

Correct Correct

15. Given the following code snippet:

String str = new String("Hello");

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

(Answer all questions in this section)

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

Incorrect Incorrect. Refer to Section 2 Lesson 1.

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:

9 public static void method1(){

10 x=100;

11 }

public static void method1();

Code:

0: bipush 100

2: putstatic #7 //Field x:I

5: return

Which statement is true?

Step completed: "thread-main", Example.method1(), line=11 bci=5

Mark for Review

(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.

From the bytecode, we can assume the Variable x is an instance variable.


Correct Correct

6. The javac command can be used to display native code in Java Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 1.

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

All of the above (*)

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

Incorrect Incorrect. Refer to Section 2 Lesson 1.

9. Which of the following statements is NOT TRUE for the jdb command? Mark for Review

(1) Points
jdb can display the source code.

jdb can set the break pont for the program.

jdb can dump the stack of the current thread.

jdb can track the GC activity of the program. (*)

Incorrect Incorrect. Refer to Section 2 Lesson 1.

10. The class file contains the definition it inherits from the superclass. Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 2.


11. Given the following instance variable:

public void foo(){

int i=888888;

Which of the following statements is NOT TRUE? Mark for Review

(1) Points

The variable i is a local variable.

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. (*)

The field descriptor for the variable i is I.

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

13. Given the following declaration of the method test:

public static void test(String s, int i);

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

Incorrect Incorrect. Refer to Section 2 Lesson 2.

14. Given the following class structure:

public class Shape{

void foo(){}

public class Circle extends Shape{

void draw(){}

Which of the following statements is TRUE? Mark for Review

(1) Points

The foo method definition appears in the Circle class.

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.

Incorrect Incorrect. Refer to Section 2 Lesson 2.

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

(Answer all questions in this section)

1. opcode invokespecial is used to invoke an instance initialization method. Mark for Review

(1) Points

True (*)

False

Correct Correct

2. Bytecode is an intermediate representation of a program, somewhere between source code


and machine code. Mark for Review

(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

Incorrect Incorrect. Refer to Section 3 Lesson 1.

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

Incorrect Incorrect. Refer to Section 3 Lesson 1.

5. Java bytecode is generated by the javac command. Mark for Review

(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

Incorrect Incorrect. Refer to Section 3 Lesson 1.

7. .class files are loaded into memory all at once, when a Java application is launched. Mark for
Review

(1) Points

True
False (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.

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)

public class Foo{

public void test(){

Class.forName("HelloClass");
}

Mark for Review

(1) Points

(Choose all correct answers)

The forName() method does not initialize the HelloClass. (*)

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.

The forName method will instantiate a HelloClass object. (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.

10. The process of linking involves which of the following processes? Mark for Review
(1) Points

verification

preparation

resolution

All of the above (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.

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

custom class loader

application class loader


bootstrap class loader (*)

extension class loader

Incorrect Incorrect. Refer to Section 3 Lesson 2.

12. Which of the following exceptions is thrown by the loadClass() method of ClassLoader class?
Mark for Review

(1) Points

IOException

SystemException

ClassFormatError

ClassNotFoundException (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.


13. The same class cannot be loaded by the JVM more than one time. Mark for Review

(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

Extension Class Loader

Custom Class Loader

Bootstrap Class Loader (*)


Application Class Loader

Incorrect Incorrect. Refer to Section 3 Lesson 2.

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 (*)

Incorrect Incorrect. Refer to Section 3 Lesson 2.

Section 4

(Answer all questions in this section)

1. What is the output from the following code?

String s= "a,b,c";

Scanner sc = new Scanner (s);


while (sc.hasNext())

System.out.print (sc.next() +" "); Mark for Review

(1) Points

a,b

ac

a,b,c (*)

abc

Correct Correct

2. You declare a method:

public void act(Student s){}

Which of following arguments can be passed into the method? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)


Type of Object class

Interface

Type of Student class (*)

Type of the subclass of Student (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

3. Which three are valid declarations for a float value? (Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

float f = -1; (*)

float f = 2.0f; (*)

float f = 3.0L;
float f = 0x345; (*)

float f = 1.0;

Incorrect Incorrect. Refer to Section 4 Lesson 1.

4. Which two statements prevent a method from being overriden? (Choose Two) Mark for
Review

(1) Points

(Choose all correct answers)

Void final act() {}

Final abstract void act() {}

Static final void act() {} (*)

Final void act() {} (*)


Static void act() {}

6. Which of the following operators are relational operators?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

"+="

"!=" (*)

">=" (*)

"="

Incorrect Incorrect. Refer to Section 4 Lesson 1.

7. Which of the following operators are logic operators?(Choose Two) Mark for Review

(1) Points
(Choose all correct answers)

&& (*)

<=

>

! (*)

9. What is the output from the following code snippet?

int i=0, j=0;

i=i++;

j=i++;

System.out.println("i=" + i + " " + "j=" + j); Mark for Review

(1) Points

The code will compile and print "i=1 j=0" (*)


The code will compile and print "i=1 j=1"

The code will not compile.

The code will compile and print "i=1 j=1"

The code will compile and print "i=0 j=0"

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};

int i[1] id;

int id[]; (*)


Incorrect Incorrect. Refer to Section 4 Lesson 1.

3. Using the code below, what will be the output if a Student object is instantiated?

public class Student

public Student()

System.out.print("1");

super();

System.out.print("2");

} Mark for Review

(1) Points

The code will not compile. (*)

12

2
1

Correct Correct

4. What is the final value of result from the following code snippet?

int i = 1;

int [] id = new int [3];

int result = id [i];

result = result + i; Mark for Review

(1) Points

The code will compile, result has the value of 0

The code will compile, result has the value of 2

The code will not compile, result has the value of 2

The code will compile, result has the value of 1 (*)

An exception is thrown.
Correct Correct

5. What is the output from the following code?

System.out.print("i=");

for (int i=0; i < l0; i++){

if(i==3)

break;

System.out.print(i);

} Mark for Review

(1) Points

i=0123456789

i=012 (*)

i=0123

i=012456789

Incorrect Incorrect. Refer to Section 4 Lesson 1.


6. Examine the following Classes:

Student and TestStudent

What is the output from the println statement in TestStudent?

public class Student {

private int studentId = 0;

public Student(){

studentId++;

public static int getStudentId(){

return studentId;

public class TestStudent {

public static void main(String[] args) {

Student s1 = new Student();

Student s2 = new Student();

Student s3 = new Student();

System.out.println(Student.getStudentId());

} Mark for Review

(1) Points

TestStudent will throw an exception


1

No output. Compilation of TestStudent fails (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

7. Which of following relationships does not use inheritance? Mark for Review

(1) Points

Car and Tire (*)

People and Student

Bank card and Credit Card

Animal and Cat


Correct Correct

8. Which statements are true?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

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. (*)

A constructor can not be overloaded.

In a constructor, you can call a superclass constructor. (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.


9. What is the output from the following code snippet?

int i=0,j=0;

i=++i;

j=i++;

System.out.println("i=" + i + " " + "j=" + j); Mark for Review

(1) Points

The code will compile and print "i=1 j=2"

The code will compile and print "i=2 j=2"

The code does not compile.

The code will compile and print "i=1 j=1"

The code will compile and print "i=2 j=1" (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.


10. Which two statements best describe data encapsulation? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

The access modifier to member data is private. (*)

Member data can be modified directly.

Methods provide for access and modification of data. (*)

The access modifier for methods is protected.

Incorrect Incorrect. Refer to Section 4 Lesson 1.

11. What is the output from the following code?

int x=0;

int y=5;

do{

++x;

y--;

}while(x<3);

System.out.println(x + " " + y); Mark for Review


(1) Points

22

3 2 (*)

23

33

Incorrect Incorrect. Refer to Section 4 Lesson 1.

12. The following code can be compiled, True/False?

byte b = 1;

b = b + 1; Mark for Review

(1) Points

True

False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.

13. What is the output from the following code snippet?

int[] myarray={1,2,3,4,5};

int sum=0;

for (int x : myarray)

sum+=x;

System.out.println("sum= " + sum); Mark for Review

(1) Points

10

The code will not compile.

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)

java.lang.Object obj = new java.lang.Object(); Mark for Review

(1) Points

(Choose all correct answers)

Memory is allocated for a new object, if available. (*)

Reference obj can be reassigned to any other type of object. (*)

This Object instance will not be created because you never defined class Object.

A new instance of class Object is created. (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

15. What is the output from the following code snippet?


public class Test {

public static void main(String[] args) {

System.out.println(1 + 2 + "java" + 3);

} Mark for Review

(1) Points

The code does not compile.

The code will compile and print "12java3"

The code will compile and print "6java"

The code will compile and print "3java3" (*)

The code will compile and print "java3"

Incorrect Incorrect. Refer to Section 4 Lesson 1.

1. Which of following relationships does not use inheritance? Mark for Review

(1) Points

People and Student


Animal and Cat

Bank card and Credit Card

Car and Tire (*)

Correct Correct

2. What is the output from the following code?

int x=0;

int y=5;

do{

++x;

y--;

}while(x<3);

System.out.println(x + " " + y); Mark for Review

(1) Points

3 2 (*)

33
23

22

Incorrect Incorrect. Refer to Section 4 Lesson 1.

3. Which statement is incorrect regarding a constructor? Mark for Review

(1) Points

When no constructor is defined in the class, the compiler will create a default constructor.

The default constructor initializes the instance variables.

A constructor can not return value, it must be declared as void. (*)

The default constructor is the no-parameter constructor.


Correct Correct

4. What is the output from the following code snippet?

for (int i = 0; i < 10; i++) {

if (i == 3) {

break;

System.out.print(i); Mark for Review

(1) Points

The code will compile and print "123"

The code does not compile.

The code will compile and print "0123"

The code will compile and print "012" (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

5. A class can be extended by more than one class. True or False? Mark for Review
(1) Points

True (*)

False

Correct Correct

6. What is the output from the following code snippet?

String str1 = "java";

char[] c = {'j', 'a', 'v', 'a'};

System.out.println(str1.equals(c));

System.out.println(t == c); Mark for Review

(1) Points

The code will compile and print "true true"

The code will compile and print "false, true"

The code does not compile. (*)


The code will compile and print "false,false"

The code will compile and print "true, false"

Incorrect Incorrect. Refer to Section 4 Lesson 1.

7. What is the output from the following code snippet?

int i=0,j=0;

i=++i;

j=i++;

System.out.println("i=" + i + " " + "j=" + j); Mark for Review

(1) Points

The code will compile and print "i=2 j=2"

The code will compile and print "i=2 j=1" (*)

The code will compile and print "i=1 j=2"

The code does not compile.


The code will compile and print "i=1 j=1"

Incorrect Incorrect. Refer to Section 4 Lesson 1.

8. Which combination of the following overload the Student constructor?(Choose Two) Mark for
Review

(1) Points

(Choose all correct answers)

public Object Student(int x,int y){}

public Student(){} (*)

protected int Student(){}

public void Student(int x, int y){}

public Student(int x,int y){} (*)


Incorrect Incorrect. Refer to Section 4 Lesson 1.

9. Which two statements are access modifier keywords in Java?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

abstract

final

protected (*)

public (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

10. What is the output from the following code snippet?


String str1 = "java";

String str2 = "java";

System.out.println(str1.equals(str2) + "," + str1.equals(new String("hello"))); Mark for Review

(1) Points

The code will not compile.

The code will compile and print "true, false" (*)

The code will compile and print "false, true"

The code will compile and print "false, false"

The code will compile and print "true, true"

Incorrect Incorrect. Refer to Section 4 Lesson 1.

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

12. Which statements are true?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

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. (*)

A constructor can not be overloaded.

In a constructor, you can call a superclass constructor. (*)


Correct Correct

13. Which ofthe following declarations are wrong?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

abstract final class Hello{} (*)

public abstract class Student{}

protected private int id; (*)

abstract private void act(){} (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

14. Which statement is true when run the following statement?


1. String str = null;

2. if ((str != null) && (str.length() > 1)) {

3. System.out.println("great that number 1");

4. } else if ((str != null) & (str.length() < 2)) {

5. System.out.println("less than number 2");

6. } Mark for Review

(1) Points

The code compiles and will throw an exception at line 2.

The code compiles and will throw an exception at line 3.

The code compiles and will throw an exception at line 4. (*)

The code compiles and will throw an exception at line 5

The code does not compile.

Correct Correct
15. What is the output from the following code snippet?

int x = 1;

int y;

while(++x < 5)

y++;

System.out.println(y); Mark for Review

(1) Points

The code will not compile. (*)

Incorrect Incorrect. Refer to Section 4 Lesson 1.

Section 5

(Answer all questions in this section)


1. Immutable classes do allow instance variables to be changed by overriding methods.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.

2. An interface can implement methods.

True or False? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.


3. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.

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

Incorrect Incorrect. Refer to Section 5 Lesson 4

6. Which statement is true for the class java.util.ArrayList? Mark for Review

(1) Points

The elements in the collection are accessed using key.

The elements in the collection are ordered. (*)

The elements in the collection are immutable.

The elements in the collection are synchronized.


Incorrect Incorrect. Refer to Section 5 Lesson 4.

7. Which of the following is the correct way to throw cumstom ServerException? Mark for
Review

(1) Points

throw ServerException

throws ServerException

throw new 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 | (*)

&&

(==) (equals equals)

None, multiple exceptions can't be handled in one catch statement.

Incorrect Incorrect. Refer to Section 5 Lesson 3.

9. What is the output from the following code snippet?

class Shape{

public void paint(){System.out.print("Shape");}

class Circle extends Shape{

public void paint() throws Exception{

System.out.print("Circle ");

throw new Exception();

public static void main(String[] args){

try{new Circle().paint();}
catch(Exception e){System.out.println("Exception");

} Mark for Review

(1) Points

Circle

Shape

ShapeCircle

Exception

Compile fails (*)

Incorrect Incorrect. Refer to Section 5 Lesson 3.

10. Assertions are boolean statements to test and debug your programs.

True or false? Mark for Review

(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

(Choose all correct answers)

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.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

13. The instanceof operator allows you to determine the type of an object.

True or false? Mark for Review

(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 abstract Animal {}

public Animal{}

public abstract Animal extends class{}

public abstract class Animal{} (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.


15. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points

True (*)

False

1. Immutable classes can be subclassed.

True or false? Mark for Review

(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 {}

public Animal extends Interface {}

public class Animal implements Interface {}

public interface Animal {} (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.

3. Immutable classes do allow instance variables to be changed by overriding methods.

True or false? Mark for Review

(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.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

5. Which method will force a subclass to implement it? Mark for Review

(1) Points

Abstract public void act(); (*)

Public double act();

Protected void act(String name){}


Static void act(String name) {}

Public native double act();

Correct Correct

Section 5

(Answer all questions in this section)

1. What do Arrays and ArrayLists have in common?

I. They both store data.

II. They can both be traversed in loops.

III. They both can be dynamically re-sized during execution of a program.

Mark for Review

(1) Points

I only

II only
I and II only (*)

I, II and III only

None of these

Incorrect Incorrect. Refer to Section 5 Lesson 4.

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

4. What is the result from creating the following try-catch block?

1.try {

2.} catch (Exception e) {

3.} catch (ArithmeticException a) {

4.} Mark for Review

(1) Points

Compile fails at Line 3 (*)

Compile fails at Line 2


The code compiles

Compile fails at Line 1

Incorrect Incorrect. Refer to Section 5 Lesson 3.

5. What is one step you must do to create your own exception? Mark for Review

(1) Points

Create a new class that implements Exception.

Create a new class that extends Exception. (*)

Exceptions cannot be created. They are only built in to Java.

Declare the primitive data type Exception.


Correct Correct

. Which statement added at line one allows the code to compile and run?

//line one

public class Test (

public static void main (String[] args) {

java.io.PrintWriter out = new java.io.PrintWriter

(new java.io.OutputStreamWriter (System.out), true);

System.out.println("Java");

} Mark for Review

(1) Points

No statement is needed. (*)

import java.io.OutputStreamWriter

include java.io.*;

import java.io.PrintWriter;

import java.io.*;
Incorrect Incorrect. Refer to Section 5 Lesson 3.

7. This is correct syntax for catching an exception:

try(inputStream = "missingfile.txt");

catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 3.

8. What is exception handling? Mark for Review

(1) Points

If your program exits before you expect it to.

When a file fails to open.


An error that occurs against the flow of your program.

A consistent way of handling various errors. (*)

Incorrect Incorrect. Refer to Section 5 Lesson 3.

9. Virtual method invocation requires that the superclass method is defined as which of the
following? Mark for Review

(1) Points

A private final method.

A default final method.

A public final method.

A public static method.


A public method. (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.

10. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

11. Which line contains an compilation error?

interface Shape {}

interface InnerShape extends Shape{}

class Circle implements Shape{ }

class InnerCircle extends Circle{}

class Rectangle implements Shape{}

public class Tester {

public static void main(String[] args) {


Circle c= new Circle();

InnerCircle ic = new InnerCircle();

Rectangle rect = new Rectangle();

System.out.print(c instanceof InnerCircle); //Line 1

System.out.print(ic instanceof Circle); //Line 2

System.out.print(rect instanceof InnerCircle); //Line 3

System.out.print(rect instanceof Shape); //Line 4

} Mark for Review

(1) Points

Line 2

Line 3 (*)

Line 4

Line 1

Correct Correct
12. An abstract class can be instantiated.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.

13. In general, classes can be made immutable by placing a final key word before the class
keyword.

True or false? Mark for Review

(1) Points

False

True (*)
Correct Correct

14. The state of an object differentiates it from other objects of the same class.

True or False? Mark for Review

(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

public interface Animal {} (*)

public class Animal implements Interface {}


public class Animal {}

public Animal extends Interface {}

Correct Correct

ection 5

(Answer all questions in this section)

1. What is exception handling? Mark for Review

(1) Points

If your program exits before you expect it to.

A consistent way of handling various errors. (*)

When a file fails to open.

An error that occurs against the flow of your program.


Correct Correct

2. Which statements are true when you compile and run this code.(Choose Two)

1. public class Test{

2. public static String sayHello(String name) throws Exception{

3. if(name == null) throw new Exception();

4. return "Hello " + name;

5. }

6. public static void main(String[] args){

7. sayHello("Java");

8. }

9. } Mark for Review

(1) Points

(Choose all correct answers)

can not create Exception object in the Test Class.

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

Incorrect Incorrect. Refer to Section 5 Lesson 3.

3. Assertions are optional ways to catch logic errors in code.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

4. Assertions are boolean statements to test and debug your programs.

True or false? Mark for Review

(1) Points

True (*)
False

Incorrect Incorrect. Refer to Section 5 Lesson 3.

5. What is the output from the following code snippet?

public static void main(String[] args){

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");

} Mark for Review

(1) Points

NullPointerException

Compile fails (*)


Java

Exception

Incorrect Incorrect. Refer to Section 5 Lesson 3.

6. A upward cast means all instance variables of the subclass are permanently lost to the instance.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.

7. The instanceof operator can find subclass objects when they are passed to method which
declare a superclass type parameter.

True or false? Mark for Review

(1) Points
True (*)

False

Correct Correct

8. A downward cast of a superclass to subclass allows you to access a subclass specialized


method call.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

9. You can't downcast an object explicitly because you must use virtual method invocation.

True or false? Mark for Review

(1) Points
True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 1.

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?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.

III. An ArrayList can store multiple object types.

IV. In an ArrayList you need to know the length and the current number of elements stored.
Mark for Review

(1) Points

I and III only (*)

II and IV only

I, II, and III only

I, II, III and IV

None of these

Incorrect Incorrect. Refer to Section 5 Lesson 4.

12. Which statement is true for the class java.util.ArrayList? Mark for Review

(1) Points

The elements in the collection are synchronized.


The elements in the collection are accessed using key.

The elements in the collection are ordered. (*)

The elements in the collection are immutable.

Incorrect Incorrect. Refer to Section 5 Lesson 4.

13. A method with default access can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.


14. Which two statements are equivalent to line 2?

(Choose Two)

1. public interface Account{

2. int accountID=100;

3. } Mark for Review

(1) Points

(Choose all correct answers)

static int accountID=100; (*)

private int accountID=100;

Final int accountID=100; (*)

Abstract int accountID=100;

protected int accountID=100;

Incorrect Incorrect. Refer to Section 5 Lesson 2.


15. Classes define and implement what? Mark for Review

(1) Points

All methods with implementations

Variables and methods (*)

Some methods with implementations

All method definitions without any implementations

Constants and all methods with implementations

1. Virtual method invocation must be defined with the instanceof operator.

True or false? Mark for Review

(1) Points

True

False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 1.

2. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

3. You can't downcast an object explicitly because you must use virtual method invocation.

True or false? Mark for Review

(1) Points

True

False (*)
Correct Correct

4. Which method will force a subclass to implement it? Mark for Review

(1) Points

Abstract public void act(); (*)

Protected void act(String name){}

Public double act();

Static void act(String name) {}

Public native double act();

Correct Correct

5. Methods can not throw exceptions.

True or false? Mark for Review


(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 3.

6. In what order do multiple catch statements execute? Mark for Review

(1) Points

The order they are declared in ( most specific first). (*)

They all execute at the same time.

The order they are declared in (most general first).

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)

1. public class Test{

2. public static String sayHello(String name) throws Exception{

3. if(name == null) throw new Exception();

4. return "Hello " + name;

5. }

6. public static void main(String[] args){

7. sayHello("Java");

8. }

9. } Mark for Review

(1) Points

(Choose all correct answers)

can not create Exception object in the Test Class.

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

8. This is correct syntax for catching an exception:

try(inputStream = "missingfile.txt");

catch(exception e);

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct

9. Multiple exceptions can be caught in one catch statement.

True or false? Mark for Review

(1) Points
True (*)

False

Correct Correct

10. You can only implement one interface in a class.

True or False? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 5 Lesson 2.

11. Immutable classes can be subclassed.

True or false? Mark for Review

(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

public class Animal {}

public Animal extends Interface {}

public class Animal implements Interface {}

public interface Animal {} (*)


Correct Correct

13. Which of the following statements is false? Mark for Review

(1) Points

An ArrayList has a fixed length. (*)

An ArrayList can store multiple object types.

An ArrayList can grow and shrink dynamically as required.

In an Array you need to know the length and the current number of elements stored.

Incorrect Incorrect. Refer to Section 5 Lesson 4.

Test: Java Programming Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 1

(Answer all questions in this section)


1. The function of Garbage Collection in Java is: Mark for Review

(1) Points

The JVM uses GC to clear the program output.

The JVM GC deletes all unused Java files on the system.

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();

Only the garbage collection system can destroy an object. (*)

Correct Correct

3. Given the following output from the Minor GC:

[PSYoungGen: 9200K->1008K(9216K)] 9980K->3251K(19456K), 0.0045753 secs] [Times:user=0.03


sys=0.03, real=0.00 secs]

Which of the following statements is TRUE? Mark for Review

(1) Points

The pause time spent in GC is 0.03.

The size of the entire heap is 19456k (*)

This is a major garbage collection process.


The size of the tenured space is 19456k.

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

Java is a high-level programming language.


The Java programming language includes a garbage collection feature.

Java is an object oriented programming language.

All of the above (*)

Correct Correct

Page 1 of 10 Next Summary

Test: Java Programming Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 1

(Answer all questions in this section)

6. Given the java snippet below:

public class Foo{

int x;

public void testFoo(){


int y=100;

Which of the following statements is TRUE? Mark for Review

(1) Points

Compile error, as the variable x is not initialized.

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

(Answer all questions in this section)


7. The javac command can be used to display native code in Java Mark for Review

(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

jdb can display the source code.

jdb can set the break pont for the program.

jdb can dump the stack of the current thread.

jdb can track the GC activity of the program. (*)

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

Previous Page 2 of 10 Next Summary

Test: Java Programming Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 2

(Answer all questions in this section)

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

(Answer all questions in this section)

13. Which of the following opcode instructions would add 2 integer variables? Mark for Review

(1) Points

add

addi

iadd (*)

Incorrect Incorrect. Refer to Section 3 Lesson 1.

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 (*)

application class loader

bootstrap class loader

extension 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

(Answer all questions in this section)


19. Which three are valid declarations for a float value? (Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

float f = -1; (*)

float f = 0x345; (*)

float f = 3.0L;

float f = 2.0f; (*)

float f = 1.0;

Correct Correct

20. What is the final value of result from the following code snippet?

int i = 1;

int [] id = new int [3];


int result = id [i];

result = result + i; Mark for Review

(1) Points

The code will compile, result has the value of 0

The code will compile, result has the value of 1 (*)

The code will not compile, result has the value of 2

The code will compile, result has the value of 2

An exception is thrown.

Correct Correct

Previous Page 4 of 10 Next Summary

Test: Java Programming Midterm Exam


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 4

(Answer all questions in this section)

21. What is the output from the following code snippet?

String str1= "java";

String str2=new String("java");

System.out.println( str1==str2 );

System.out.println( str1==str2.intern() );

Mark for Review

(1) Points

The code does not compile.

The code will compile and print "true false"

The code will compile and print "false true" (*)

The code will compile and print "false false"

The code will compile and print "true true"


Correct Correct

22. What is the output from the following code snippet?

int[] myarray={1,2,3,4,5};

int sum=0;

for (int x : myarray)

sum+=x;

System.out.println("sum= " + sum); Mark for Review

(1) Points

The code will not compile.

10

15 (*)

20

Correct Correct
23. Examine the following Classes:

Student and TestStudent

What is the output from the println statement in TestStudent?

public class Student {

private int studentId = 0;

public Student(){

studentId++;

public static int getStudentId(){

return studentId;

public class TestStudent {

public static void main(String[] args) {

Student s1 = new Student();

Student s2 = new Student();

Student s3 = new Student();

System.out.println(Student.getStudentId());

} Mark for Review

(1) Points

3
No output. Compilation of TestStudent fails (*)

TestStudent will throw an exception

Correct Correct

24. Which ofthe following declarations are wrong?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

abstract private void act(){} (*)

public abstract class Student{}

protected private int id; (*)


abstract final class Hello{} (*)

Correct Correct

25. Which of the following types are primitive data types? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

String

boolean (*)

double (*)

Integer

Correct Correct
Previous Page 5 of 10 Next Summary

Test: Java Programming Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 5

(Answer all questions in this section)

26. Immutable classes do allow instance variables to be changed by overriding methods.

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct

27. You can only implement one interface in a class.

True or False? Mark for Review


(1) Points

True

False (*)

Correct Correct

28. Interfaces define what? Mark for Review

(1) Points

Constants and all methods with implementations

Some methods with implementations

All method definitions without any implementations (*)

All methods with implementations


Variables and methods

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

30. Classes define and implement what? Mark for Review

(1) Points

Some methods with implementations


Constants and all methods with implementations

All methods with implementations

All method definitions without any implementations

Variables and methods (*)

Correct Correct

Previous Page 6 of 10 Next Summary

Test: Java Programming Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 5

(Answer all questions in this section)

31. An interface can implement methods.

True or False? Mark for Review


(1) Points

True

False (*)

Correct Correct

32. When line 10 is executed, which method will be called?

1 class Account {

2 public void deposit(int amt, int amt1) { }

3 public void deposit(int amt){ }

4}

5 public class CreditAccount extends Account {

6 public void deposit() { }

7 public void deposit(int amt) {}

8 public static void main(String args[]){

9 Account account = new CreditAccount();

10 account.deposit(10);

11 }

12 } Mark for Review

(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.

True or false? Mark for Review

(1) Points

True (*)

False
Correct Correct

34. Which two of the following statements are true? (Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

An abstract class must contain abstrct method.

An abstract class can define constructor. (*)

An abstract class can create subclass and be constructed.

An abstract class must be difined by using the abstract keyword. (*)

Correct Correct

35. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points
True (*)

False

Correct Correct

Previous Page 7 of 10 Next Summary

Test: Java Programming Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 5

(Answer all questions in this section)

36. Virtual method invocation must be defined with the instanceof operator.

True or false? Mark for Review

(1) Points

True
False (*)

Correct Correct

37. You can't downcast an object explicitly because you must use virtual method invocation.

True or false? Mark for Review

(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

throw new ServerException() (*)

raise ServerException

Correct Correct

39. When will a finally statement be executed? Mark for Review

(1) Points

Always; no matter if an exception is thrown or not. (*)

Only if an exception is not thrown.

Never; it is there for visual purposes.

Only if multiple exceptions are caught and thrown.


Only if an exception is thrown.

Incorrect Incorrect. Refer to Section 5 Lesson 3.

40. What is the output from the following code snippet?

public static void main(String[] args){

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");

} Mark for Review

(1) Points

Exception

NullPointerException
Compile fails (*)

Java

Correct Correct

Previous Page 8 of 10 Next Summary

Test: Java Programming Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 5

(Answer all questions in this section)

41. Which statements are true when you compile and run this code.(Choose Two)

1. public class Test{

2. public static String sayHello(String name) throws Exception{

3. if(name == null) throw new Exception();

4. return "Hello " + name;

5. }
6. public static void main(String[] args){

7. sayHello("Java");

8. }

9. } Mark for Review

(1) Points

(Choose all correct answers)

The class Test compiles if line 7 is enclosed in a try-catch block. try{ sayHello("Java"); }
catch(Exception e){} (*)

Compilation succeeds

can not create Exception object in the Test Class.

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.

True or false? Mark for Review

(1) Points
True

False (*)

Correct Correct

43. In what order do multiple catch statements execute? Mark for Review

(1) Points

The order they are declared in ( most specific first). (*)

They all execute at the same time.

The order they are declared in (most general first).

None of them execute since you cannot have multiple catch statements.
Correct Correct

44. Methods can not throw exceptions.

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct

45. What do Arrays and ArrayLists have in common?

I. They both store data.

II. They can both be traversed in loops.

III. They both can be dynamically re-sized during execution of a program.

Mark for Review

(1) Points

I only
II only

I and II only (*)

I, II and III only

None of these

Correct Correct

Previous Page 9 of 10 Next Summary

Test: Java Programming Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 5

(Answer all questions in this section)

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

(Choose all correct answers)

It is not helpful to read code written by other programmers.

Learn new programming techniques. (*)

Understand code written by other programmers. (*)


Meet new programmers.

Correct Correct

48. Which of the following statements is false? Mark for Review

(1) Points

An ArrayList has a fixed length. (*)

An ArrayList can store multiple object types.

In an Array you need to know the length and the current number of elements stored.

An ArrayList can grow and shrink dynamically as required.

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

Mark for Review

(1) Points

I only

I and II only

II and III only (*)

I, II, and III

None of these

Correct Correct

50. Which of the following statements about arrays and ArrayLists in Java are true?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.

III. An ArrayList can store multiple object types.


IV. In an ArrayList you need to know the length and the current number of elements stored.

Mark for Review

(1) Points

I and III only (*)

II and IV only

I, II, and III only

I, II, III and IV

None of these

14. Why is it helpful for new programmers to read pre-written code?(Choose Two) Mark for
Review

(1) Points

(Choose all correct answers)

Learn new programming techniques. (*)

Meet new programmers.


Understand code written by other programmers. (*)

It is not helpful to read code written by other programmers.

Incorrect Incorrect. Refer to Section 5 Lesson 4.

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

(Answer all questions in this section)

1. A LinkedList is a type of Stack.

True or false? Mark for Review

(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 (*)

Incorrect Incorrect. Refer to Section 6 Lesson 3.

3. A HashMap can only store String types.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 6 Lesson 3.

4. Which of the following correctly defines a queue? Mark for Review


(1) Points

A list of elements with a first in last out order.

A list of elements with a first in first out order. (*)

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 <>.

Incorrect Incorrect. Refer to Section 6 Lesson 3.

5. Which line contains an compilation error?

interface Shape {}

class Circle implements Shape{}

public class Test{

public static void main(String[] args) {

List ls = new ArrayList(); // Line 1

List lc = new ArrayList(); // Line 2


Circle c = new Circle();

ls.add(c); // Line 3

lc.add(c); // Line 4

} Mark for Review

(1) Points

Line 2

Line 4

Line 1

Line 3 (*)

Incorrect Incorrect. Refer to Section 6 Lesson 2.

6. Which class is an ordered collection that may contain duplicates? Mark for Review

(1) Points

list (*)
enum

set

array

Incorrect Incorrect. Refer to Section 6 Lesson 2.

7. The following code is valid when working with the Collection Interface.

Collection collection = new Collection()d;

True or false? Mark for Review

(1) Points

True

False (*)

Correct Correct
8. What is the output from the following code snippet?

public static void main(String[] args){

List li=new ArrayList();

li.add(1);

li.add(2);

print(li);

public static void print(List list) {

for (Number n : list)

System.out.print(n + " ");

} Mark for Review

(1) Points

The code will not compile.

1 2 (*)

2
Incorrect Incorrect. Refer to Section 6 Lesson 1.

9. < ? extends Animal > is an example of a bounded generic wildcard.

True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct

10. What is the correct definition of Enumeration (or enum)? Mark for Review

(1) Points

Code that initializes an ArrayList

A list of elements that is dynamically stored.

A bounded generic class


A keyword that specifies a class whose objects are defined inside the class. (*)

Incorrect Incorrect. Refer to Section 6 Lesson 1.

11. Which of the following would initialize a generic class "Cell" using a String type?

I. Cell cell = new Cell(); .

II. Cell cell = new Cell(); .

III. Cell cell = new String;

Mark for Review

(1) Points

I and II (*)

II only

II and III

I only

III only
Incorrect Incorrect. Refer to Section 6 Lesson 1.

12. Why might a sequential search be inefficient? Mark for Review

(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.

Incorrect Incorrect. Refer to Section 6 Lesson 4.

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

Merge Sort (*)

Selection Sort

Binary Search

All of the above

Incorrect Incorrect. Refer to Section 6 Lesson 4.

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.

True or false? Mark for Review

(1) Points

True
False (*)

Incorrect Incorrect. Refer to Section 6 Lesson 4.

15. 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

Section 6

(Answer all questions in this section)

1. Which line contains an compilation error?

interface Shape {}
class Circle implements Shape{}

public class Test{

public static void main(String[] args) {

List ls = new ArrayList(); // Line 1

List lc = new ArrayList(); // Line 2

Circle c = new Circle();

ls.add(c); // Line 3

lc.add(c); // Line 4

} Mark for Review

(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.

Incorrect Incorrect. Refer to Section 6 Lesson 2.

3. Which code inserted into the code below guarantees that the program will output [1,2]?

import java.util.*;

public class Example{

public static void main(String[] args){

//insert code here

set.add(2);

set.add(1);
System.out.println(set);

} Mark for Review

(1) Points

Set set = new SortedSet();

Set set = new TreeSet(); (*)

Set set = new LinkedHashSet();

Set set = new HashSet();

List set = new SortedList();

Incorrect Incorrect. Refer to Section 6 Lesson 2.

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

5. Selection sort is efficient for large arrays.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 6 Lesson 4.

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

Merge Sort (*)

Selection Sort

Binary Search

All of the above

Incorrect Incorrect. Refer to Section 6 Lesson 4.

7. 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

8. Enumerations (enums) are useful for storing data : Mark for Review

(1) Points

When you know all of the possibilities of the class (*)

When the class is constantly changing

When the class is a subclass of Object.

You cannot store data in an enum.

Incorrect Incorrect. Refer to Section 6 Lesson 1.

9. A generic class increases the risk of runtime class conversion exceptions.

True or False? Mark for Review


(1) Points

True

False (*)

Correct Correct

10. Generic methods are required to be declared as static.

True or False? Mark for Review

(1) Points

True

False (*)

Correct Correct

11. The following code will compile.

True or False?
class Node implements Comparable{

public int compareTo(T obj){return 1;}

class Test{

public static void main(String[] args){

Node nc=new Node<>();

Comparable com=nc;

Mark for Review

(1) Points

True (*)

False

Correct Correct

12. Which scenario best describes a stack? Mark for Review

(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.

All of the above describe a stack.

Incorrect Incorrect. Refer to Section 6 Lesson 3.

13. Where you enqueue an element in the list? Mark for Review

(1) Points

adds it to the end of the list (*)

adds it to the start of the list

removes it from the front of the list


removes it from the end of the list

Incorrect Incorrect. Refer to Section 6 Lesson 3.

14. A LinkedList is a type of Stack.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

15. A LinkedList is a list of elements that is dynamically stored.

True or false? Mark for Review

(1) Points

True (*)
False

Correct Correct

1. All classes can by subclassed. Mark for Review

(1) Points

True

False (*)

5. What is special about including a resource in a try statement?(Choose Two) Mark for Review

(1) Points

(Choose all correct answers)

The resources will auto-close. (*)

An error will be thrown if the resources does not open. (*)


The program will fail if the resource does not open

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.

It is hard to assume expected values for parameters.

Assertions do not work 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

Posted by karre resakl at 7:27 PM

Email This

BlogThis!

Share to Twitter

Share to Facebook

Share to Pinterest

81 comments:

UnknownDecember 21, 2018 at 5:41 AM

Section 6

(Answer all questions in this section)

1. An example of an upper bounded wildcard is.

ArrayList (*)

ArrayList

ArrayList

ArrayList
2.Enumerations (enums) are useful for storing data :

When the class is constantly changing

When you know all of the possibilities of the class (*)

When the class is a subclass of Object.

You cannot store data in an enum.

3. When would an enum (or enumeration) be used?

When you already know all the possibilities for objects of that class. (*)
When you wish to remove data from memory.

When you wish to initialize a HashSet.

When you want to be able to create any number of objects of that class.

4. Enumerations (enums) must be declared in their own 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 (*)

6.Which of the following best describes lexicographical order?

An order based on the ASCII value of characters. (*)

The order of indicies after an array has been sorted.

A simple sorting algorithm that is inefficient on large arrays.

A complex sorting algorithm that is efficient on large arrays.

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

Merge Sort (*)

Selection Sort

Binary Search

All of the above


9.Which of the following correctly adds "Cabbage" to the ArrayList vegetables?

vegetables[0] = "Cabbage";

vegetables += "Cabbage";

vegetables.get("Cabbage");

vegetables.add("Cabbage"); (*)

10.Which interface forms the root of the collections hierarchy?

java.util.Map

java.util.List

java.util.Collection (*)
java.util.Collections

11. What is a set?

A collection of elements that does not contain duplicates. (*)

A keyword in Java that initializes an ArrayList.

Something that enables you to create a generic class without specifying a type between angle
brackets <>.

A collection of elements that contains duplicates.

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

14.Why can a LinkedList be considered a stack and a queue?(Choose Three)


Because you can add elements to the end of it. (*)

Because you can not add element to the beginning of it.

Because you can remove elements from the end of it. (*)

Because you can remove elements from the beginning of it. (*)

15.Which scenario best describes a stack?

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.

All of the above describe a stack.


1. The instanceof operator finds subclasses when they are passed as a superclass.

True or false? Mark for Review

(1) Points

True (*)

False

Correct

2. The instanceof operator only works with class instances.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 2 Lesson 2.

3. The instanceof operator works inside an if statement.


True or false? Mark for Review

(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

A public final method.

A default final method.

A private final method.

A public static method.


A public method. (*)

Incorrect. Refer to Section 2 Lesson 2.

5. An abstract class can implement its methods. Mark for Review

(1) Points

True (*)

False

Correct

6. Virtual method invocation occurs when you call a method from a superclass.

True or false? Mark for Review

(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

Telephones cell = new Telephones(Cellular c);

Telephones(Cellular) cell = new Telephones(Cellular);

Telephones<> cell = new Telephones<>(Cellular c);

Telephones cell = new Telephones(); (*)

None of the above.

Incorrect. Refer to Section 2 Lesson 3.

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

Some methods with implementations

All methods with implementations

All method definitions without any implementations (*)

Variables and methods

Constants and all methods with implementations

Incorrect. Refer to Section 2 Lesson 1.

11. An interface can implement methods. Mark for Review

(1) Points

True
False (*)

Incorrect. Refer to Section 2 Lesson 1.

12. Which one of the following would allow you to define an interface for Animal. Mark for
Review

(1) Points

public interface Animal {} (*)

public class Animal implements Interface {}

public class Animal {}

public Animal extends Interface {}

Correct

13. Which one of the following statements is true? Mark for Review

(1) Points
A class is an intance of an object

A Java program can only contain one super class

A class is a template that defines the features of an object (*)

A class is a Java primitive

Correct

14. The state of an object differentiates it from other objects of the same class. Mark for
Review

(1) Points

True (*)

False

Incorrect. Refer to Section 2 Lesson 1.


15. A method with default access level can be subclassed by? Mark for Review

(1) Points

Only a subclass in the same package.

A subclass in any package.

A static nested class.

An instance nested class.

None of the above. We cannot subclass a method in Java. (*)

Correct

1. Which of the following would initialise a generic class "Cell" using a String type?

I. Cell cell = new Cell(); .

II. Cell cell = new Cell(); .

III. Cell cell = new String;

Mark for Review

(1) Points
I only

II only

III only

I and II (*)

II and III

Incorrect. Refer to Section 2 Lesson 3.

2. < ? > is an example of a bounded generic wildcard. Mark for Review

(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

animalCollection {…}(*) (*)

public class

animalCollection(AnimalType T) {…}

public class

animalCollection {…}

public class

animalCollection(animalType) {…}

None of the above.


Incorrect. Refer to Section 2 Lesson 3.

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

public interface Animal {} (*)

public Animal extends Interface {}

public class Animal {}


public class Animal implements Interface {}

Correct

6. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

7. Classes define and implement what? Mark for Review

(1) Points

All method definitions without any implementations

All methods with implementations


Constants and all methods with implementations

Some methods with implementations

Variables and methods (*)

Incorrect. Refer to Section 2 Lesson 1.

8. A method with public access level can be subclassed by? Mark for Review

(1) Points

Only a subclass in the same package.

A subclass in any package.

A static nested class.

An instance nested class.


None of the above. We cannot subclass a method in Java. (*)

Incorrect. Refer to Section 2 Lesson 1.

9. An interface can implement methods. Mark for Review

(1) Points

True

False (*)

Incorrect. Refer to Section 2 Lesson 1.

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.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 2 Lesson 2.

12. Virtual method invocation requires that the superclass method is defined as which of the
following? Mark for Review

(1) Points

A public final method.

A public static method.

A default final method.


A public method. (*)

A private final method.

Incorrect. Refer to Section 2 Lesson 2.

13. Which one of the following would allow you to define the abstract class Animal. Mark for
Review

(1) Points

public abstract class Animal (*)

public Animal

public abstract Animal extends class

public abstract Animal

Incorrect. Refer to Section 2 Lesson 2.


14. Calling a subclass method by referring to a superclass works because you have access to all
specialized methods through virtual method invocation.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

15. An abstract class can be instantiated. Mark for Review

(1) Points

True

False (*)

Incorrect. Refer to Section 2 Lesson 2.

1. The instanceof operator works inside an if statement.


True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 2 Lesson 2.

2. A upward cast means all instance variables of the subclass are permanently lost to the
instance.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

3. Virtual method invocation is: Mark for Review


(1) Points

When the method of a subclass is used on a superclass reference. (*)

When the method of a superclass is used on a superclass reference.

Not part of polymorphism.

When the method of a subclass is used on a subclass reference.

Incorrect. Refer to Section 2 Lesson 2.

4. 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.


5. An abstract class can be instantiated. Mark for Review

(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.

True or false? Mark for Review

(1) Points

True

False (*)

Correct
7. A method with public access can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

8. A method with default access can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect. Refer to Section 2 Lesson 1.

9. You can only implement one interface in a class. Mark for Review
(1) Points

True

False (*)

Correct

10. You have an interface called Animal.

You wish to create an instance of Animal.

Which one of the following is correct? Mark for Review

(1) Points

Animal animal = new Animal();

Animal animal = null;

Animal animal = new Animal("Bear");

None of the other choices. (*)


Incorrect. Refer to Section 2 Lesson 1.

11. Immutable classes do allow instance variables to be changed by overriding methods.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

12. Making a class immutable means. Mark for Review

(1) Points

That it cannot be extended. (*)

That it is directly subclassed from the Object class

To create a sub class from a parent class


To create an instance of the class.

Incorrect. Refer to Section 2 Lesson 1.

13. Which one of the following can be used to declare a generic type. Mark for Review

(1) Points

All of the other responses (*)

Correct

14. public static void printArray(T[] array){….

is an example of what? Mark for Review

(1) Points
A generic instance

A concreate method.

A generic method (*)

A generic class

Incorrect. Refer to Section 2 Lesson 3.

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

(Answer all questions in this section)

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?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.

III. An ArrayList can store multiple object types.

IV. In an ArrayList you need to know the length and the current number of elements stored.

Mark for Review

(1) Points

I and III only (*)

II and IV only

I, II, and III only

I, II, III and IV

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

(Answer all questions in this section)

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;

int [] id = new int [3];

int result = id [i];

result = result + i; Mark for Review

(1) Points

The code will compile, result has the value of 1 (*)

The code will compile, result has the value of 2

An exception is thrown.

The code will compile, result has the value of 0


The code will not compile, result has the value of 2

Correct Correct

8. What is the output from the following code?

int x=5;

if (x>6)

System. out. println("x>l");

else if (x>=5)

System. out .println("x>=5");

else if (x<10)

System. out. println("x<10");

else

System.out.println("none of the above"); Mark for Review

(1) Points

x<10

None of these answers are correct


x>6

x>=5 (*)

Correct Correct

9. Examine the partial class declaration below:

class Foo{

public Foo(String s,int i ){

this(i);

public Foo(int i){

public Foo(int i,int j){

Which of following statements can not be used to create a instance of Foo?

Mark for Review

(1) Points

Foo f=new Foo("java",1);


Foo f=new Foo(1,2);

Foo f=new Foo(); (*)

Foo f=new Foo(1);

Incorrect incorrect. Refer to Section 1 Lesson 1.

Section 2

(Answer all questions in this section)

10. Virtual method invocation requires that the superclass method is defined as which of the
following? Mark for Review

(1) Points

A private final method.

A public static method.


A public final method.

A default final method.

A public method. (*)

Incorrect Incorrect. Refer to Section 2 Lesson 2.

Section 2

(Answer all questions in this section)

11. A downward cast of a superclass to subclass allows you to access a subclass specialized
method call.

True or false? Mark for Review

(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.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 2 Lesson 2.

13. Which line contains an compilation error?

interface Shape {}

interface InnerShape extends Shape{}

class Circle implements Shape{ }

class InnerCircle extends Circle{}

class Rectangle implements Shape{}

public class Tester {

public static void main(String[] args) {

Circle c= new Circle();


InnerCircle ic = new InnerCircle();

Rectangle rect = new Rectangle();

System.out.print(c instanceof InnerCircle); //Line 1

System.out.print(ic instanceof Circle); //Line 2

System.out.print(rect instanceof InnerCircle); //Line 3

System.out.print(rect instanceof Shape); //Line 4

} Mark for Review

(1) Points

Line 1

Line 3 (*)

Line 2

Line 4

Correct Correct

14. When line 10 is executed, which method will be called?


1 class Account {

2 public void deposit(int amt, int amt1) { }

3 public void deposit(int amt){ }

4}

5 public class CreditAccount extends Account {

6 public void deposit() { }

7 public void deposit(int amt) {}

8 public static void main(String args[]){

9 Account account = new CreditAccount();

10 account.deposit(10);

11 }

12 } Mark for Review

(1) Points

line 3

line 7 (*)

line 6

line 2

Correct Correct
15. An abstract class can implement its methods.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 2 Lesson 2.

Section 2

(Answer all questions in this section)

16. Upward casting an object instance means you can't access subclass specific methods.

True or false? Mark for Review

(1) Points

True (*)

False
Correct Correct

17. All classes can by subclassed. Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 1.

18. Classes define and implement what? Mark for Review

(1) Points

Some methods with implementations

All methods with implementations

All method definitions without any implementations


Variables and methods (*)

Constants and all methods with implementations

Correct Correct

19. An interface can implement methods.

True or False? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 1.

20. Which two statements are equivalent to line 2?

(Choose Two) 1. public interface Account{


2. int accountID=100;

3. } Mark for Review

(1) Points

(Choose all correct answers)

private int accountID=100;

protected int accountID=100;

static int accountID=100; (*)

Abstract int accountID=100;

Final int accountID=100; (*)

Incorrect Incorrect. Refer to Section 2 Lesson 1.

Section 2

(Answer all questions in this section)

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

public interface Animal {} (*)

public Animal extends Interface {}

public class Animal implements Interface {}

public class Animal {}


Incorrect Incorrect. Refer to Section 2 Lesson 1.

23. Immutable classes can be subclassed.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 1.

24. A generic class is a type of class that associates one or more non-specific Java types with it.

True or False? Mark for Review

(1) Points

True (*)

False
Correct Correct

25. < ? extends Animal > would only allow classes or subclasses of Animal to be used.

True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct

Section 2

(Answer all questions in this section)

26. Generic methods are required to be declared as static.

True or False? Mark for Review

(1) Points

True
False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 3.

27. < ? > is an example of a bounded generic wildcard.

True or False? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 3.

28. ArrayList and Arrays both require you to define their size before use.

True or false? Mark for Review

(1) Points
True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 4.

29. What is the output from the following code snippet?

Integer[] ar = {1, 2, 1, 3};

Set<Integer> set = new TreeSet<Integer>(Arrays.asList(ar));

set.add(4);

for (Integer element : set) {

System.out.print(element);

} Mark for Review

(1) Points

12134

11234

1234 (*)
1213

Correct Correct

30. What is a set? Mark for Review

(1) Points

Something that enables you to create a generic class without specifying a type between angle
brackets <>.

A collection of elements that contains duplicates.

A keyword in Java that initializes an ArrayList.

A collection of elements that does not contain duplicates. (*)

Section 2

(Answer all questions in this section)

31. Which code inserted into the code below guarantees that the program will output [1,2]?

import java.util.*;

public class Example{


public static void main(String[] args){

//insert code here

set.add(2);

set.add(1);

System.out.println(set);

} Mark for Review

(1) Points

Set set = new LinkedHashSet();

Set set = new HashSet();

List set = new SortedList();

Set set = new SortedSet();

Set set = new TreeSet(); (*)

Correct Correct
32. A collection is an interface in the Java API.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

33. What is the output from the following code snippet?

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

The code does not compiles.

Correct Correct

34. 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.

Incorrect Incorrect. Refer to Section 2 Lesson 4.

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

(Answer all questions in this section)


36. Selection sort is efficient for large arrays.

True or false? Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 2 Lesson 6.

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

Binary Search (*)

All of the above

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

{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}

{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}

{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)

{71, 1, 3, 28,29, 50, 22, 83, 1, 17}


{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}

41. 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

42. Binary searches can be performed on sorted and unsorted data.

True or false? Mark for Review

(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.public static void main (String[]args) {

2,//insert code here

3. s.put ("StudentID", 123);

4.} Mark for Review

(1) Points

(Choose all correct answers)

HashMap s= new HashMap(); (*)

SortedMap s= new TreeMap(); (*)

Map s= new SortedMap();

ArrayList s= new ArrayList();


Incorrect Incorrect. Refer to Section 2 Lesson 5.

44. Why can a LinkedList be considered a stack and a queue?(Choose Three) Mark for Review

(1) Points

(Choose all correct answers)

Because you can remove elements from the beginning of it. (*)

Because you can remove elements from the end of it. (*)

Because you can not add element to the beginning of it.

Because you can add elements to the end of it. (*)

Correct Correct

45. A LinkedList is a list of elements that is dynamically stored.


True or false? Mark for Review

(1) Points

True (*)

False

Section 2

(Answer all questions in this section)

46. Implementing the Comparable interface in your class allows you to define its sort order.

True or false? Mark for Review

(1) Points

True (*)

False

Correct Correct

47. Nodes are components of LinkedLists, and they identify where the next and previous nodes
are.

True or false? Mark for Review


(1) Points

True (*)

False

Correct Correct

48. Which scenario best describes a stack? Mark for Review

(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.

All of the above describe a stack.


Incorrect Incorrect. Refer to Section 2 Lesson 5.

49. Which of the following describes a deque. Mark for Review

(1) Points

It is pronounced "deck" for short.

It implements a stack.

Allows for insertion or deletion of elements from the first element added or the last one.

All of the above. (*)

Correct Correct

50. To allow our classes to have a natural order we could implement the Comparable interface.

True or false? Mark for Review

(1) Points
True (*)

False

11. Generic methods can only belong to generic classes.


True or 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 (*)

Incorrect. Refer to Section 3 Lesson 1.

Section 3 - Quiz 1 L1-L3

(Answer all questions in this section)

1. What is the correct explanation of when this code will return true?

return str.matches(".*[0-9]{6}.*"); Mark for Review

(1) Points
Any time that str contains two dots.

Any time that str contains a sequence of 6 digits. (*)

Any time that str has between zero and nine characters followed by a 6.

Any time str contains a 6.

Always.

Incorrect. Refer to Section 3 Lesson 2.

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)

Incorrect. Refer to Section 3 Lesson 2.

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. (*)

The asterisk has no function in regular expressions.

Indicates that the preceding character may occur 1 or more times in a proper match.

Incorrect. Refer to Section 3 Lesson 2.


4. Which of the following correctly defines Matcher? Mark for Review

(1) Points

A regular expression symbol that represents any character.

A method of dividing a string into a set of sub-strings.

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.

True or false? Mark for Review

(1) Points

True (*)

False
Correct

6. Which of the following correctly defines Pattern? Mark for Review

(1) Points

A regular expression symbol that represents any character.

A method of dividing a string into a set of sub-strings.

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 matches.

Incorrect. Refer to Section 3 Lesson 2.

7. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark
for Review

(1) Points

Matcher m = new Matcher();


Matcher m = str.matcher(p);

Matcher m = new Matcher(p,str);

Matcher m = p.matcher(str); (*)

Incorrect. Refer to Section 3 Lesson 2.

8. A linear recursion requires the method to call which direction? Mark for Review

(1) Points

Forward

Backward (*)

Both forward and backward

None of the above


Incorrect. Refer to Section 3 Lesson 3.

9. Which case does a recursive method call last? Mark for Review

(1) Points

Recursive Case

Convergence Case

Basic Case

Base Case (*)

None of the above

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)

Parse the String. (*)

Read the String backwards (from last element to first element). (*)

Search for a specific character or String inside of the String. (*)

You don't use a FOR loop with Strings

Incorrect. Refer to Section 3 Lesson 1.

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.

True or false? Mark for Review

(1) Points

True

False (*)
Correct

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);

StringBuilder sb = new StringBuilder(); (*)

None of the above.

Incorrect. Refer to Section 3 Lesson 1.

15. Which of the following are true about the method split? Mark for Review

(1) Points

(Choose all correct answers)


It returns an array of strings. (*)

It can be used with a string as a parameter. (*)

It's default, with no specified parameter, is parsing by spaces.

It can be used with a regular expression as a prameter. (*)

Incorrect. Refer to Section 3 Lesson 1.

1. Matcher has a find method that checks if the specified pattern exists as a sub-string of the
string being matched.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 2.


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)

matches(String regex) (*)

equals(String regex)

equalsIgnoreCase(String regex)

Incorrect. Refer to Section 3 Lesson 2.

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.

Incorrect. Refer to Section 3 Lesson 2.

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

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)


Pattern namePattern = Pattern.compile("first_last");

Pattern namePattern = new Pattern(last{5},first{5});

Pattern namePattern = new Pattern();

None of the above.

Incorrect. Refer to Section 3 Lesson 2.

5. The following code correctly initializes a pattern with the regular expression "[0-9]{2}/[0-9]
{2}/[0-9]{2}".

Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");

True or false? Mark for Review

(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.

True or false? Mark for Review

(1) Points

True

False (*)

Correct

7. What is the correct explanation of when this code will return true?

return str.matches(".*[0-9]{6}.*"); Mark for Review

(1) Points

Any time that str contains two dots.

Any time that str contains a sequence of 6 digits. (*)


Any time that str has between zero and nine characters followed by a 6.

Any time str contains a 6.

Always.

Incorrect. Refer to Section 3 Lesson 2.

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

(Choose all correct answers)

Search for a specific character or String inside of the String. (*)

Parse the String. (*)

You don't use a FOR loop with Strings


Read the String backwards (from last element to first element). (*)

Incorrect. Refer to Section 3 Lesson 1.

9. Which of the following are true about the method split? Mark for Review

(1) Points

(Choose all correct answers)

It's default, with no specified parameter, is parsing by spaces.

It can be used with a regular expression as a prameter. (*)

It can be used with a string as a parameter. (*)

It returns an array of strings. (*)

Incorrect. Refer to Section 3 Lesson 1.

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)

delete(int start, int end) (*)

Incorrect. Refer to Section 3 Lesson 1.

11. Which of the following methods are specific to StringBuilders? Mark for Review

(1) Points

append

delete

insert
replace

All of the above. (*)

Incorrect. Refer to Section 3 Lesson 1.

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

Incorrect. Refer to Section 3 Lesson 3.

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

Incorrect. Refer to Section 3 Lesson 3.

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);

Matcher m = p.matcher(str); (*)

Matcher m = new Matcher(p,str);

Matcher m = new Matcher();

Incorrect. Refer to Section 3 Lesson 2.


2. What is the correct explanation of when this code will return true?

return str.matches(".*[0-9]{6}.*"); Mark for Review

(1) Points

Any time that str contains two dots.

Any time that str contains a sequence of 6 digits. (*)

Any time that str has between zero and nine characters followed by a 6.

Any time str contains a 6.

Always.

Incorrect. Refer to Section 3 Lesson 2.

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(".");

if( str.length() == 0 || str.length() == 1)

{ return true;}

return false; (*)

return str.matches(".?"); (*)

return str.matches("[a-z]*");

Incorrect. Refer to Section 3 Lesson 2.

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.

True or false? Mark for Review

(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

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)

Pattern namePattern = Pattern.compile("first_last");

Pattern namePattern = new Pattern(last{5},first{5});

Pattern namePattern = new Pattern();

None of the above.


Incorrect. Refer to Section 3 Lesson 2.

6. The following code correctly initializes a pattern with the regular expression
"[0-9]{2}/[0-9]{2}/[0-9]{2}".

Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 2.

7. Matcher has a find method that checks if the specified pattern exists as a sub-string of the
string being matched.

True or false? Mark for Review

(1) Points

True (*)
False

Incorrect. Refer to Section 3 Lesson 2.

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

The primary case

The base case (*)


The convergence case

The recursive case

The secondary case

Incorrect. Refer to Section 3 Lesson 3.

10. 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.

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

Incorrect. Refer to Section 3 Lesson 3.

12. Which of the following are true about the method split? Mark for Review

(1) Points

(Choose all correct answers)

It can be used with a string as a parameter. (*)

It's default, with no specified parameter, is parsing by spaces.

It can be used with a regular expression as a prameter. (*)

It returns an array of strings. (*)


Incorrect. Refer to Section 3 Lesson 1.

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

(Choose all correct answers)

Read the String backwards (from last element to first element). (*)

Search for a specific character or String inside of the String. (*)

You don't use a FOR loop with Strings

Parse the String. (*)

Incorrect. Refer to Section 3 Lesson 1.

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);

StringBuilder sb = new StringBuilder(); (*)

None of the above.

Incorrect. Refer to Section 3 Lesson 1.

15. Which of the following are true about parsing a String? Mark for Review

(1) Points

(Choose all correct answers)

It is not possible to parse a string using regular expressions.

It is a way of dividing a string into a set of sub-strings. (*)


It is possible to use a for loop to parse a string. (*)

It is possible to use the String.split() method to parse a string. (*)

Incorrect. Refer to Section 3 Lesson 1.

1. Which of the following correctly defines a StringBuilder? Mark for Review

(1) Points

A class that represents a string-like object. (*)

There is no such thing as a StringBuilder in Java.

A method that adds characters to a string.

A class inside the java.util.regex package.

Incorrect. Refer to Section 3 Lesson 1.

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

(Choose all correct answers)

Search for a specific character or String inside of the String. (*)

Parse the String. (*)

Read the String backwards (from last element to first element). (*)

You don't use a FOR loop with Strings

Incorrect. Refer to Section 3 Lesson 1.

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.

True or false? Mark for Review

(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]*");

if( str.length() == 0 || str.length() == 1)

{ return true;}

return false; (*)

return str.contains(".");

return str.matches(".?"); (*)

Incorrect. Refer to Section 3 Lesson 2.

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

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)


Pattern namePattern = Pattern.compile("first_last");

Pattern namePattern = new Pattern(last{5},first{5});

Pattern namePattern = new Pattern();

None of the above.

Incorrect. Refer to Section 3 Lesson 2.

7. What does the dot (.) represent in regular expressions? Mark for Review

(1) Points

An indication for one or more occurrences of the preceding character.

A match for any character. (*)

A range specified between brackets that allows variability of a character.


Nothing, it is merely a dot.

Incorrect. Refer to Section 3 Lesson 2.

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.

True or false? Mark for Review

(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 2.

9. A regular expression is a character or a sequence of characters that represent a string or


multiple strings.

True or false? Mark for Review

(1) Points

True (*)
False

Incorrect. Refer to Section 3 Lesson 2.

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

(Choose all correct answers)

return userI.matches("[1-5]"); (*)

return userI.matches("{1-5}");

return userI.matches("[1-5]{1}"); (*)

return userI.matches("[1-5].*");

Incorrect. Refer to Section 3 Lesson 2.


11. Which of the following correctly defines a repetition operator? Mark for Review

(1) Points

A symbol that represents any character in regular expressions.

A method that returns the number of occurrences of the specified character.

Any symbol in regular expressions that indicates the number of occurrences a specified character
appears in a matching string. (*)

None of the above.

Incorrect. Refer to Section 3 Lesson 2.

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

Base Case (*)

None of the above

Incorrect. Refer to Section 3 Lesson 3.

6. Square brackets are a representation for any character in regular expressions "[ ]".

True or false? Mark for Review

(1) Points
True

False (*)

Incorrect. Refer to Section 3 Lesson 2.

Which of the following methods are specific to StringBuilders? Mark for Review

(1) Points

append

delete

insert

replace

All of the above. (*)


Incorrect. Refer to Section 3 Lesson 1

1. Which of the following correctly defines a StringBuilder?

There is no such thing as a StringBuilder in Java.

A method that adds characters to a string.

A class that represents a string-like object. (*)

A class inside the java.util.regex package.

2. What class is the split() method a member of?

String (*)

Parse

Array

StringBuilder

3. Which of the following correctly initializes a StringBuilder?

StringBuilder sb = "This is my String Builder";

StringBuilder sb = StringBuilder(500);

StringBuilder sb = new StringBuilder(); (*)

None of the above.

4. Using the FOR loop method of incrementing through a String is beneficial if you desire to:
(Choose Three)

Parse the String. (*)

Search for a specific character or String inside of the String. (*)

Read the String backwards (from last element to first element). (*)

You don't use a FOR loop with Strings

5. Which case handles the last recursive call?

The convergence case

The secondary case


The primary case

The base case (*)

The recursive case

6. A non-linear recursive method is less expensive than a linear recursive method.

True or false?

True

False (*)

7. Which two statements can create an instance of an array? (Choose Two)

double da = new double [5];

Object oa = new double[5]; (*)

char[] ca = "java";

int[] ia = new int [5]; (*)

int ia[][] = (1,2,3) (4,5,6);

8. Forward thinking helps when creating linear recursive methods.

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]*");

if( str.length() == 0 || str.length() == 1)

{ return true;}

return false; (*)

return str.matches(".?"); (*)


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?
(Choose Two)

return userI.matches("[1-5].*");

return userI.matches("{1-5}");

return userI.matches("[1-5]"); (*)

return userI.matches("[1-5]{1}"); (*)

11. The following code correctly initializes a pattern with the regular expression
"[0-9]{2}/[0-9]{2}/[0-9]{2}".

Pattern dateP = Pattern.compile("[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.

13. What is the function of the asterisk (*) in regular expressions?

The asterisk has no function in regular expressions.


Indicates that the preceding character may occur 1 or more times in a proper 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 (*)

15. Which of the following correctly defines a repetition operator?

A symbol that represents any character in regular expressions.

A method that returns the number of occurrences of the specified character.

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

public class Test (

public static void main (String[] args) {

java.io.PrintWriter out = new java.io.PrintWriter

(new java.io.OutputStreamWriter (System.out), true);

System.out.println("Java");

include java.io.*;

import java.io.OutputStreamWriter

No statement is needed. (*)

import java.io.PrintWriter;

import java.io.*;
17. What is one step you must do to create your own exception?

Declare the primitive data type Exception.

Create a new class that implements Exception.

Create a new class that extends Exception. (*)

Exceptions cannot be created. They are only built in to Java.

18. Methods can not throw exceptions.

True or false?

True

False (*)

19. What is the output from the following code?

public class Foo{

public static void main(String[] args){

try {return;}

finally{System.out.println("you are in Finally");}

The code compiles and prints out モ you are in Finally" (*)

The code will not compile.

The code compiles and print nothing

The code compiles, but an exception is thrown.

20. In what order do multiple catch statements execute?

The order they are declared in ( most specific first). (*)

They all execute at the same time.

The order they are declared in (most general first).

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 (*)

23. Which of the following is an absolute Windows path?

/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

28. Which statement determine that "java" is a directory?

Boolean isDir=(new File("java")).isDir();

Boolean isDir=Directory.exists ("java");

Boolean isDir=(new Directory("java")).exists(); (*)

Boolean isDir=(new File("java")).isDirectory();

29. The System.out is what type of stream?

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

.java files (*)

None of the above

32. Which of the following is an attribute of a three tier architecture application?

an application of that type has a client and server only

an complex application that includes a client, a server and database (*)

an application of that type runs on a single computer

None of the above

All of the above

33. The method for connecting a Java application to a database is by using:

jar files

JNLP

JDBC (*)

Java Web Start

None of the above

34. Java Web Start is used to deploy Java applications.

True or false?

True (*)

False

35. Which of the following is an attribute of a two tier architecture application?

An application of that has a client and server only. (*)

A complex application that includes a client, a server and database.

An application of that runs on a single computer.

None of the above.


36. Which of the following is not a reason to use a Java package?

It is a way to organize files when a project consists of multiple modules.

It is a way to help resolve naming conflicts when different packages have classes with the same
sames.

It is a way to protect data from being used by the non-authorized classes.

It is a way to allow programmers to receive packets of information from databases. (*)

None of the above

37. When you import a package, subpackages will not be imported.

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

40. The method for connecting a java application to a database is JNLP.

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)

jar files (*)

JNLP files (*)

html files (*)

.java files

None of the above

43. How would you make an instance of Car in a class that didn't import the vehicle package
below?

package vehicle;

public class Car{

public Car(){}

Car c = new Car();

vehicle.Car c=new Car();

vehicle.Car c=new vehicle.Car(); (*)

vehicle.Car c=new vehicle();

None of the above

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)

double da = new double [5];

Object oa = new double[5]; (*)

char[] ca = "java";

int[] ia = new int [5]; (*)

int ia[][] = (1,2,3) (4,5,6);

A non-linear recursive method can call how many copies of itself?

12 or more (*)

None

linear recursive method can call how many copies of itself?

1 (*)

2 or more

None

he base case condition can work with a constant or variable.

True or false?

True (*)

False

Which of the following correctly defines a repetition operator?

A symbol that represents any character in regular expressions.

A method that returns the number of occurrences of the specified character.


symbol in regular expressions that indicates the number of occurrences a specified character
appears in a matching string. (*)

None of the above.

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?

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)

Pattern namePattern = Pattern.compile("first_last");

Pattern namePattern = new Pattern(last{5},first{5});

Pattern namePattern = new Pattern();

None of the above.

Square brackets are a representation for any character in regular expressions "[ ]".

True or false?

True

False (*)

Which of the following correctly defines Matcher?

A class in the java.util.regex package that stores the matches between a pattern and a string. (*)

A regular expression symbol that represents any character.

A method of dividing a string into a set of sub-strings.

A class in the java.util.regex package that stores the format of a regular expression.

What does the dot (.) represent in regular expressions?

An indication for one or more occurrences of the preceding character.

A match for any character. (*)

A range specified between brackets that allows variability of a character.


Nothing, it is merely a dot.

Which of the following are true about parsing a String?(Choose Three)

It is possible to use a for loop to parse a string. (*)

It is possible to use the String.split() method to parse a string. (*)

It is not possible to parse a string using regular expressions.

It is a way of dividing a string into a set of sub-strings. (*)

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.equals("April, May, June, July");

return month.compareTo("April, May, June, July");

return month.matches("April|May|June|July"); (*)

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?

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)

Pattern namePattern = Pattern.compile("first_last");

Pattern namePattern = new Pattern(last{5},first{5});

A regular expression is a character or a sequence of characters that represent a string or multiple


strings.

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)

matches(String regex) (*)

What is the result from the following code?

public class Test {

public static void main(String[] args) {

String str = "91204";

str += 23;

System.out.print(str);

23

91204

91227

9120423 (*)

Which of the following correctly initializes a StringBuilder?

StringBuilder sb = "This is my String Builder";

StringBuilder sb = StringBuilder(500);

StringBuilder sb = new StringBuilder(); (*)

None of the above.

Which of the following are true about parsing a String?(Choose Three)

It is a way of dividing a string into a set of sub-strings. (*)

It is possible to use the String.split() method to parse a string. (*)

It is possible to use a for loop to parse a string. (*)

It is not possible to parse a string using regular expressions.

Which of the following methods are StringBuilder methods?

append

delete

insert
replace

All of the above. (*)

A linear recursion requires the method to call which direction?

Forward

Backward (*)

Both forward and backward

None of the above

A non-linear recursive method is less expensive than a linear recursive method.

True or false?

True

False (*)

A linear recursive method can call how many copies of itself?

1 (*)

2 or more

None

Forward thinking helps when creating linear recursive methods.

True or false?

True

False (*)

File permissions are the same across all of the different operating systems.

True

False(*)

The BufferedInputStream is a direct subclass of what other class?

InputStream

FileInputStream

PipedInputStream

FilterInputStream(*)

InputStream

You can read input by character or line.


TRue or false?

True(*)

False

When will a finally statement be executed?

Only if an exception is not thrown.

Always; no matter if an exception is thrown or not. (*)

Only if an exception is thrown.

Only if multiple exceptions are caught and thrown.

Never; it is there for visual purposes.

Which of the following is the correct way to throw cumstom ServerException?

throws ServerException

throw new ServerException() (*)

throw ServerException

raise ServerException

What is the definition of a logic error?

Bugs in code that make your program run different than expected (*)

Computer malfunction that makes your code run incorrectly.

Something that causes your computer to crash.

Wrong syntax that will be caught at compile time.

What is the output from the following code snippet?

public static void main(String[] args){

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

Compile fails (*)

Exception

What symbol(s) is used to separate multiple exceptions in one catch statement?

none, multiple exceptions can't be handled in one catch statement.

(==) (equals equals)

A single vertical bar | (*)

&&

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

Which of these construct a DataInputStream instance?

New dataInputStream(new writer("java.txt"));

New dataInputStream(new InputStream("java.txt"));

New dataInputStream("java.txt");

New dataInputStream(new FileInputStream("java.txt")); (*)

New dataInputStream(new file("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 (*)

Why should you not use assertions to check parameters?

It is hard to assume expected values for parameters.

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.

Assertions do not work on parameters.

What is exception handling?

A consistent way of handling various errors. (*)

When a file fails to open.

An error that occurs against the flow of your program.

If your program exits before you expect it to

What is the definition of a logic error?

Something that causes your computer to crash.

Computer malfunction that makes your code run incorrectly.

Bugs in code that make your program run different than expected (*)

Wrong syntax that will be caught at compile time.

Assertions are boolean statements to test and debug your programs.


True or false?

True (*)

False

Which statements are true when you compile and run this code.(Choose Two)

1. public class Test{

2. public static String sayHello(String name) throws Exception{

3. if(name == null) throw new Exception();

4. return "Hello " + name;

5. }

6. public static void main(String[] args){

7. sayHello("Java");

8. }

9. }

can not create Exception object in the Test Class.

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

You can read input by character or line.

True or false?

True (*)

False

If a programmer uses the line

import com.test.*,

there is no need to use

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

When you import a package, subpackages will not be imported.

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

Being good at reading code.

Looking for opportunities to read code.

Being good at testing.

All of the above. (*)

Incorrect. Refer to Section 1 Lesson 2.

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. (*)

Incorrect. Refer to Section 1 Lesson 2.

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.

Build and run the code.

Incorrect. Refer to Section 1 Lesson 2.

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?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.


III. An ArrayList can store multiple object types.

IV. In an ArrayList you need to know the length and the current number of elements stored. Mark
for Review

(1) Points

I and III only (*)

II and IV only

I, II, and III only

I, II, III and IV

None of the above

Incorrect. Refer to Section 1 Lesson 2.

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 (*)

Incorrect. Refer to Section 1 Lesson 2.

8. Which of the following statements is false? Mark for Review

(1) Points

In an Array you need to know the length and the current number of elements stored.

An ArrayList has a fixed length. (*)

An ArrayList can store multiple object types.

An ArrayList can grow and shrink dynamically as required.

Incorrect. Refer to Section 1 Lesson 2.

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

Incorrect. Refer to Section 1 Lesson 2.

10. Arrays have built-in operations including add, clear, contains, get and remove. True or
false? Mark for Review

(1) Points

True

False (*)

Incorrect. Refer to Section 1 Lesson 2.

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

(Choose all correct answers)

Database Programming with PL/SQL

Big Data

Database Design and Programming with SQL (*)

Java Fundamentals
Incorrect. Refer to Section 1 Lesson 1.

15. Oracle Academy is awesome. Mark for Review

(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

2. Examine the following code snippet. What is this an example of?

public class Car extends Vehicle {

public Car() {

} Mark for Review

(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

(Choose all correct answers)

It is not helpful to read code written by other programmers.


Meet new programmers.

Learn new programming techniques. (*)

Understand code written by other programmers.

Incorrect. Refer to Section 1 Lesson 2.

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

7. 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. 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

II and III only (*)

I, II, and III


None of the above

Incorrect. Refer to Section 1 Lesson 2.

8. Which of the following is not a good technique to follow when reading code written by
others? Mark for Review

(1) Points

Understand the constructs.

Find the author of the code and ask him how it works. (*)

Build and run the code.

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?

I. An Array has a fixed length.

II. An Array can grow and shrink dynamically as required.

III. An ArrayList can store multiple object types.

IV. In an ArrayList you need to know the length and the current number of elements stored. Mark
for Review

(1) Points

I and III only (*)

II and IV only

I, II, and III only

I, II, III and IV

None of the above


Incorrect. Refer to Section 1 Lesson 2.

12. What do Arrays and ArrayLists have in common?

I. They both store data.

II. They can both be traversed in loops.

III. They both can be dynamically re-sized during execution of a program. Mark for Review

(1) Points

I only

II only

I and II only (*)

I, II and III only

None of the above

Incorrect. Refer to Section 1 Lesson 2.

13. Oracle Academy is awesome. Mark for Review


(1) Points

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

(Choose all correct answers)

Database Design and Programming with SQL (*)

Database Programming with PL/SQL

Big Data

Java Fundamentals

Incorrect. Refer to Section 1 Lesson 1.

You might also like