Monday, October 15, 2018

karre jawa oracle java programming midterm and section 1 -5

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

a c

a,b,c (*)

a b c

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

1 2

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

3

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

3 2 (*)

2 3

3 3

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

3 3

2 3

2 2

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
3

1

4

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

1

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
1

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

90 comments:

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

    ReplyDelete
    Replies
    1. 16. A generic class is a type of class that associates one or more non-specific Java types with it.
      True or False?


      True (*)


      False

      17.The local petting zoo is writing a program to be able to collect 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?


      public class
      animalCollection {ナ} (*)


      public class
      animalCollection(AnimalType T) {ナ}


      public class
      animalCollection {ナ}


      public class
      animalCollection(animalType) {ナ}


      None of the these.


      18.What is the result from the following code snippet?

      public static void main(String[] args) {
      List list1 = new ArrayList();
      list1.add(new Gum());
      List list2 = list1;
      list2.add(new Integer(9));
      System.out.println(list2.size());
      }


      1


      The code will not compile.


      an exception will be thrown at runtime


      2 (*)

      19.The Comparable interface defines the compareTo method.
      True or false?


      True (*)


      False

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

      (Choose all correct answers)


      Map s= new SortedMap();


      SortedMap s= new TreeMap(); (*)


      ArrayList s= new ArrayList();


      HashMap s= new HashMap(); (*)

      21.Which is the correct way to initialize a HashSet?


      HashSet classMates =
      new HashSet(); (*)


      ClassMates = public class
      HashSet();


      String classMates = new
      String();


      classMates = new HashSet[String]();


      22.Choose the best definiton for a collection.


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


      It is an interface in the java.util package that is used to define a group of objects. (*)


      It is a special type of class that is associated with one or more non-specified Java type.


      It is a subclass of List.



      23.Which of the following is a sorting algorithm that involves repeatedly incrementing through the array and swapping 2 adjacent values if they are in the wrong order until all elements are in the correct order?


      Merge Sort


      Bubble Sort (*)


      Binary Search


      Sequential Search


      Selection Sort

      Delete
  2. Section 7

    (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

    ReplyDelete
    Replies

    1. 11. A non-linear recursive method calls how many copies of itself in the recursive case? Mark for Review
      (1) Points


      0


      1


      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.


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

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


    1


    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.

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


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

    ReplyDelete
    Replies
    1. 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.

      Delete

  7. Section 8
    (Answer all questions in this section)


    1. Which of the following is an attribute of a three tier architecture application? Mark for Review
    (1) Points


    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


    Incorrect. Refer to Section4 Lesson 1.


    2. Java Web Start is used to deploy java applications.
    True or false? Mark for Review
    (1) Points


    True (*)


    False


    Incorrect. Refer to Section 4 Lesson 1.


    3. The method for connecting a Java application to a database is by using: Mark for Review
    (1) Points


    jar files


    JNLP


    JDBC (*)


    Java Web Start


    None of the above


    Incorrect. Refer to Section 4 Lesson 1.


    4. Which of the following is not a reason to use a Java package? Mark for Review
    (1) Points


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


    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


    Incorrect. Refer to Section4 Lesson 1.


    5. To deploy java applications you may use Java Web Start.
    True or false? Mark for Review
    (1) Points


    True (*)


    False


    Correct

    6. How would you make an instance of Car in a class that didn't import the vehicle package below?
    Mark for Review
    (1) Points


    Car c = new Car();


    vehicle.Car c=new Car();


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


    vehicle.Car c=new vehicle();


    None of the above


    Correct


    7. How would you make an instance of Car in a class that did import the vehicle package below?
    Mark for Review
    (1) Points


    Car c = new Car(); (*)


    vehicle.Car c=new Car();


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


    vehicle.Car c=new vehicle();


    None of the above


    Incorrect. Refer to Section 4 Lesson 1.


    8. Which of the following is an attribute of a two tier architecture application? Mark for Review
    (1) Points


    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.


    Incorrect. Refer to Section 4 Lesson 1.


    9. Which of the following are files that must be uploaded to a web server to deploy a java application/applet? Mark for Review
    (1) Points

    (Choose all correct answers)


    jar files (*)


    JNLP files (*)


    html files (*)


    .java files


    None of the above


    Incorrect. Refer to Section 4 Lesson 1.


    10. If a class is in a package, the system's CLASSPATH must be altered to access the class.
    True or false? Mark for Review
    (1) Points


    True


    False (*)


    Correct

    11. An example of two tier architecture would be a client application working with a server application.
    True or false? Mark for Review
    (1) Points


    True (*)


    False


    Incorrect. Refer to Section4 Lesson 1.


    12. The method for connecting a java application to a database is JNLP.
    True or false? Mark for Review
    (1) Points


    True


    False (*)


    Correct


    13. If a programmer uses the line import com.test.*, there is no need to import com.test.code.*
    True or false? Mark for Review
    (1) Points


    True


    False (*)

    ReplyDelete
    Replies
    1. 14. Which of the following files are not required to be uploaded to a web server to deploy a java application/applet? Mark for Review
      (1) Points


      jar files


      JNLP files


      html files


      .java files (*)


      None of the above


      Incorrect. Refer to Section4 Lesson 1.


      15. What option do you choose from the File menu in Eclipse to start the process of creating a runnable JAR file? Mark for Review
      (1) Points


      Import


      Export (*)


      Switch Workspace


      Properties


      Incorrect. Refer to Section 4 Lesson 1.

      1. Java Web Start is used to deploy java applications.
      True or false? Mark for Review
      (1) Points


      True (*)


      False


      Incorrect. Refer to Section 4 Lesson 1.


      2. If a programmer uses the line import com.test.*, there is no need to import com.test.code.*
      True or false? Mark for Review
      (1) Points


      True


      False (*)


      Correct


      3. A jar file is built on the ZIP file format and is used to deploy java applets.
      True or false? Mark for Review
      (1) Points


      True (*)


      False


      Correct


      4. To deploy java applications you may use Java Web Start.
      True or false? Mark for Review
      (1) Points


      True (*)


      False


      Incorrect. Refer to Section4 Lesson 1.


      5. An example of two tier architecture would be a client application working with a server application.
      True or false? Mark for Review
      (1) Points


      True (*)


      False


      Incorrect. Refer to Section4 Lesson 1.

      6. Which of the following is not a reason to use a Java package? Mark for Review
      (1) Points


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


      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


      Correct


      7. What option do you choose from the File menu in Eclipse to start the process of creating a runnable JAR file? Mark for Review
      (1) Points


      Properties


      Import


      Switch Workspace


      Export (*)


      Incorrect. Refer to Section 4 Lesson 1.


      8. How would you make an instance of Car in a class that did import the vehicle package below?
      Mark for Review
      (1) Points


      Car c = new Car(); (*)


      vehicle.Car c=new Car();


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


      vehicle.Car c=new vehicle();


      None of the above


      Incorrect. Refer to Section 4 Lesson 1.


      9. Which of the following is an attribute of a three tier architecture application? Mark for Review
      (1) Points


      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


      Correct


      10. The method for connecting a java application to a database is JNLP.
      True or false? Mark for Review
      (1) Points


      True


      False (*)

      Delete
    2. 11. Which of the following are files that must be uploaded to a web server to deploy a java application/applet? Mark for Review
      (1) Points

      (Choose all correct answers)


      jar files (*)


      JNLP files (*)


      html files (*)


      .java files


      None of the above


      Incorrect. Refer to Section 4 Lesson 1.


      12. How would you make an instance of Car in a class that didn't import the vehicle package below?
      Mark for Review
      (1) Points


      Car c = new Car();


      vehicle.Car c=new Car();


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


      vehicle.Car c=new vehicle();


      None of the above


      Incorrect. Refer to Section4 Lesson 1.


      13. If a class is in a package, the system's CLASSPATH must be altered to access the class.
      True or false? Mark for Review
      (1) Points


      True


      False (*)


      Correct


      14. Which of the following is an attribute of a two tier architecture application? Mark for Review
      (1) Points


      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.


      Incorrect. Refer to Section 4 Lesson 1.


      15. The method for connecting a Java application to a database is by using: Mark for Review
      (1) Points


      jar files


      JNLP


      JDBC (*)


      Java Web Start


      None of the above


      Correct

      1. A jar file is built on the ZIP file format and is used to deploy java applets.
      True or false? Mark for Review
      (1) Points


      True (*)


      False


      Incorrect. Refer to Section4 Lesson 1.


      2. An example of two tier architecture would be a client application working with a server application.
      True or false? Mark for Review
      (1) Points


      True (*)


      False


      Incorrect. Refer to Section4 Lesson 1.


      3. Which of the following is an attribute of a two tier architecture application? Mark for Review
      (1) Points


      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.


      Correct


      4. Which of the following are files that must be uploaded to a web server to deploy a java application/applet? Mark for Review
      (1) Points

      (Choose all correct answers)


      jar files (*)


      JNLP files (*)


      html files (*)


      .java files


      None of the above


      Incorrect. Refer to Section 4 Lesson 1.


      5. How would you make an instance of Car in a class that didn't import the vehicle package below?
      Mark for Review
      (1) Points


      Car c = new Car();


      vehicle.Car c=new Car();


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


      vehicle.Car c=new vehicle();


      None of the above


      Correct

      6. Which of the following is an attribute of a three tier architecture application? Mark for Review
      (1) Points


      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


      Incorrect. Refer to Section4 Lesson 1.


      7. The method for connecting a Java application to a database is by using: Mark for Review
      (1) Points


      jar files


      JNLP


      JDBC (*)


      Java Web Start


      None of the above


      Correct


      8. If a class is in a package, the system's CLASSPATH must be altered to access the class.
      True or false? Mark for Review
      (1) Points


      True


      False (*)


      Correct

      Delete
    3. 9. Which of the following files are not required to be uploaded to a web server to deploy a java application/applet? Mark for Review
      (1) Points


      jar files


      JNLP files


      html files


      .java files (*)


      None of the above


      Correct


      10. If a programmer uses the line import com.test.*, there is no need to import com.test.code.*
      True or false? Mark for Review
      (1) Points


      True


      False (*)


      Correct

      11. What option do you choose from the File menu in Eclipse to start the process of creating a runnable JAR file? Mark for Review
      (1) Points


      Switch Workspace


      Import


      Properties


      Export (*)


      Incorrect. Refer to Section 4 Lesson 1.


      12. Java Web Start is used to deploy java applications.
      True or false? Mark for Review
      (1) Points


      True (*)


      False


      Correct


      13. Which of the following is not a reason to use a Java package? Mark for Review
      (1) Points


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


      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


      Incorrect. Refer to Section4 Lesson 1.


      14. To deploy java applications you may use Java Web Start.
      True or false? Mark for Review
      (1) Points


      True (*)


      False


      Correct


      15. How would you make an instance of Car in a class that did import the vehicle package below?
      Mark for Review
      (1) Points


      Car c = new Car(); (*)


      vehicle.Car c=new Car();


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


      vehicle.Car c=new vehicle();


      None of the above



      11. The BufferedInputStream is a direct subclass of what other class? Mark for Review
      (1) Points


      InputStream


      FilterInputStream (*)


      PipedInputStream


      InputStream


      FileInputStream



      [Correct] Correct


      12.The Files class provides a instance method that creates a new BufferedReader.
      True or false? Mark for Review
      (1) Points


      True (*)


      False



      [Correct] Correct


      13.The BufferedOutputStream is a direct subclass of what other class? Mark for Review
      (1) Points


      PrintStream


      DigestOutputStream


      FilterOutputStream (*)


      OutputStream


      ObjectOutputStream



      [Correct] Correct


      14.Which of the following static methods is not provided by the Files class to check file properties or duplication? Mark for Review
      (1) Points


      Files.isWritable(Path p);


      Files.isReadable(Path p);


      Files.isArchived(Path p); (*)


      Files.isHidden(Path p);



      [Correct] Correct


      15.The Paths class provides a static get() method to find a valid Path.
      True or false? Mark for Review
      (1) Points


      True (*)


      False



      [Correct] Correct

      Delete

  8. Section 9
    (Answer all questions in this section)


    1. Which of the following can fill in the //INSERT HERE correctly? (Choose Two)

    ResultSet rset = stmt.executeQuery(sqlQuery);
    if(rs.next()){
    //INSERT HERE
    }
    Mark for Review
    (1) Points

    (Choose all correct answers)


    Object s = rs.getObject(1); (*)


    String s = rs.getString(1);


    String s = rs.getObject(0);


    String s = rs.getString(0);





    2. JDBC has a type system that can control the conversion between Oracle database types and Java types. Mark for Review
    (1) Points


    True (*)


    False





    3. From JDBC, how would you execute DML statements (i.e. insert, delete, update) in the database? Mark for Review
    (1) Points


    By making use of the execute(...) statement from DataStatement Object


    By invoking the executeDelete(...), executeUpdate(...) methods of the DataStatement


    By invoking the execute(...) or executeUpdate(...) method of a JDBC Statement object or sub-interface object (*)


    By invoking the DeleteStatement or UpdateStatement JDBC object





    4. Which type of Statement can execute parameterized queries? Mark for Review
    (1) Points


    ParameterizedStatement


    CallableStatement and ParameterizedStatement


    PreparedStatement (*)


    All of the above





    5. Which of the following is the correct statement be inserted at //INSERT CODE location that calls the database-stored procedure sayHello?

    class Test{
    public static void main(String[] args) {
    try {
    Connection conn = getConnection();
    //INSERT CODE
    cstat.setString(1, "Hello");
    cstat.registerOutParameter(2, Types.NUMERIC);
    cstat.setInt(2, 10);
    }
    catch(SQLException e){}
    }
    }
    Mark for Review
    (1) Points


    CallableStatement cstat = con.prepareCall("{sayHello(?, ?)}");


    CallableStatement cstat = con.prepareCall("{call procedure_sayHello (?, ?)}");


    CallableStatement cstat = con.prepareCall("{call sayHello}");


    CallableStatement cstat = con.prepareCall("sayHello(?, ?)");


    CallableStatement cstat = con.prepareCall("{call sayHello(?, ?)}"); (*)





    6. Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does the following output?

    String sql = "select first_name from Employees order by first_name desc";
    Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    ResultSet rset= stmt.executeQuery(sql);
    rset.absolute(1);
    rset.next();
    System.out.println(rset.getString(1));
    Mark for Review
    (1) Points


    A


    B (*)


    C


    The code does not compile.


    A SQLException is thrown.




    7. Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for Review
    (1) Points


    !


    ? (*)


    @


    #





    8. Which of the following methods will move the cursor, returning a Boolean value from the ResultSet Object? Mark for Review
    (1) Points

    (Choose all correct answers)


    beforeFirst() (*)


    absolute()


    afterFirst()


    afterLast()


    beforeLast()




    9. Which of the following is the correct order to close the database object? Mark for Review
    (1) Points


    ResultSet, Statement, Connection (*)


    Connection, Statement, ResultSet


    Statement, Connection, ResultSet


    ResultSet, Connection, Statement


    Statement,ᅠResultSet,ᅠConnection




    10. Which of the following classes or interfaces are included in the database vendor driver library? (Choose two) Mark for Review
    (1) Points

    (Choose all correct answers)


    Statement interface implementation (*)


    Java.sql.Connection


    Javax.sql.DataSource


    Javax.sql.DataSource implementation (*)


    Java.sql.DriverManager implementation





    ReplyDelete
    Replies
    1. 11. Which of the following is NOT a JDBC interface used to execute SLQ statements? Mark for Review
      (1) Points


      Statement Interface


      PreparedStatement Interface


      PrePreparedStatement Interface (*)


      CallableStatement Interface





      12. You must explicitly close ResultSet and Statement objects once they are no longer in use. Mark for Review
      (1) Points


      True (*)


      False




      13.How many categories of JDBC drivers are there? Mark for Review
      (1) Points


      1


      2


      3


      4 (*)



      14.What type of JDBC driver will convert the database invocation directly into network protocol? Mark for Review
      (1) Points


      Type 1 driver


      Type 2 driver


      Type 3 driver


      Type 4 driver (*)



      15.To execute a stored SQL procedure, which JDBC interface should be used? Mark for Review
      (1) Points


      Statement Interface


      PreparedStatement Interface


      PrePreparedStatement Interface


      CallableStatement Interface (*)

      Delete
    2. 1. Which of the following can fill in the //INSERT HERE correctly? (Choose Two)

      ResultSet rset = stmt.executeQuery(sqlQuery);
      if(rs.next()){
      //INSERT HERE
      }
      Mark for Review
      (1) Points

      (Choose all correct answers)


      Object s = rs.getObject(1); (*)


      String s = rs.getString(1);


      String s = rs.getObject(0);


      String s = rs.getString(0);





      2. Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does the following output?

      String sql = "select first_name from Employees order by first_name desc";
      Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
      ResultSet rset= stmt.executeQuery(sql);
      rset.absolute(1);
      rset.next();
      System.out.println(rset.getString(1));
      Mark for Review
      (1) Points


      A


      B (*)


      C


      The code does not compile.


      A SQLException is thrown.





      3. Which type of Statement can execute parameterized queries? Mark for Review
      (1) Points


      ParameterizedStatement


      CallableStatement and ParameterizedStatement


      PreparedStatement (*)


      All of the above




      4. Which the following statements is NOT TRUE about DataSource? Mark for Review
      (1) Points


      DataSource can be implemented as a pool of connections.


      DataSource can participate in the Distributed transaction.


      DataSource can manage a set of JDBC Drivers registered in the system. (*)


      DataSource will typically be registered with a naming service.



      5. JDBC has a type system that can control the conversion between Oracle database types and Java types. Mark for Review
      (1) Points


      True (*)


      False




      6. Which of the following methods will move the cursor, returning a Boolean value from the ResultSet Object? Mark for Review
      (1) Points

      (Choose all correct answers)


      beforeFirst() (*)


      absolute()


      afterFirst()


      afterLast()


      beforeLast()




      7. Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for Review
      (1) Points


      !


      ? (*)


      @


      #




      8. From JDBC, how would you execute DML statements (i.e. insert, delete, update) in the database? Mark for Review
      (1) Points


      By making use of the execute(...) statement from DataStatement Object


      By invoking the executeDelete(...), executeUpdate(...) methods of the DataStatement


      By invoking the execute(...) or executeUpdate(...) method of a JDBC Statement object or sub-interface object (*)


      By invoking the DeleteStatement or UpdateStatement JDBC object





      9. Which of the following is a valid JDBC URL? Mark for Review
      (1) Points


      oracle:thin:localhost@dfot/dfot:1521:xe


      jdbc::oracle-thin:dfot/dfot@oracle:1521:xe


      jdbc:oracle:thin:dfot/dfot@localhost:1521:xe (*)


      oracle:thin:jdbc:dfot/dfot@localhost:1521:xe



      Delete
    3. 10. To execute a stored SQL procedure, which JDBC interface should be used? Mark for Review
      (1) Points


      Statement Interface


      PreparedStatement Interface


      PrePreparedStatement Interface


      CallableStatement Interface (*)




      11. Which of the following is the correct order to close the database object? Mark for Review
      (1) Points


      ResultSet, Statement, Connection (*)


      Connection, Statement, ResultSet


      Statement, Connection, ResultSet


      ResultSet, Connection, Statement


      Statement,ᅠResultSet,ᅠConnection




      12. The java.sql.DriverManager class will typically be registered with a naming service based on the Java Naming Directory (JNDI) API. Mark for Review
      (1) Points


      True


      False (*)





      13. How many categories of JDBC drivers are there? Mark for Review
      (1) Points


      1


      2


      3


      4 (*)





      14. Given the following code, assume there are rows of data in the table EMP. What is the result?

      1 Connection conn - new Connection(URL);
      2 Statement stmt = conn.createStatement();
      3 ResultSet result - stmt.executeQuery("select count(*) from EMP");
      4 if(rs.next()){
      5 System.out.println(rs.getInt(1));
      6 } Mark for Review
      (1) Points


      Compiler error on line 2


      Runtime error on line 3


      2


      0


      Compiler error on line 1 (*)




      15.You must explicitly close ResultSet and Statement objects once they are no longer in use. Mark for Review
      (1) Points


      True (*)


      False

      Delete
  9. Java Programming Final Exam



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




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





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




    4.Which of the following is a sorting algorithm that involves repeatedly incrementing through the array and swapping 2 adjacent values if they are in the wrong order until all elements are in the correct order? Mark for Review
    (1) Points


    Sequential Search


    Merge Sort


    Bubble Sort (*)


    Binary Search


    Selection Sort




    5.Binary searches can be performed on sorted and unsorted data.
    True or false? Mark for Review
    (1) Points


    True


    False (*)





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






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





    8.Stacks are identical to Queues.
    True or false? Mark for Review
    (1) Points


    True


    False (*)




    9.FIFO stands for: Mark for Review
    (1) Points


    Fast In Fast Out


    Fast Interface Fast Output


    First Interface First Output


    First In First Out (*)




    10.The Comparable interface defines the compareTo method.
    True or false? Mark for Review
    (1) Points


    True (*)


    False

    ReplyDelete
    Replies
    1. 11.The Comparable interface includes a method called compareTo.
      True or false? Mark for Review
      (1) Points


      True (*)


      False




      12.A LinkedList is a type of Stack.
      True or false? Mark for Review
      (1) Points


      True (*)


      False





      13.Which of the following is a list of elements that have a first in last out ordering. Mark for Review
      (1) Points


      Stacks (*)


      Arrays


      Enums


      HashMaps





      14.Which class is an ordered collection that may contain duplicates? Mark for Review
      (1) Points


      enum


      set


      array


      list (*)





      15.Which of the following correctly adds "Cabbage" to the ArrayList vegetables? Mark for Review
      (1) Points


      vegetables.get("Cabbage");


      vegetables += "Cabbage";


      vegetables[0] = "Cabbage";


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




      16. ArrayList and Arrays both require you to define their size before use.
      True or false? Mark for Review
      (1) Points


      True


      False (*)




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





      18.Which is the correct way to initialize a HashSet? Mark for Review
      (1) Points


      ClassMates = public class
      HashSet();


      classMates = new HashSet[String]();


      String classMates = new
      String();


      HashSet classMates =
      new HashSet(); (*)





      19.An example of an upper bounded wildcard is. Mark for Review
      (1) Points


      ArrayList


      ArrayList


      ArrayList


      ArrayList (*)




      20.Generic methods are required to be declared as static.
      True or False? Mark for Review
      (1) Points


      True


      False (*)

      Delete
    2. 21.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




      22.< ? extends Animal > would only allow classes or subclasses of Animal to be used.
      True or False? Mark for Review
      (1) Points


      True (*)


      False





      23.public static void printArray(T[] array){ナ.
      is an example of what? Mark for Review
      (1) Points


      A concreate method.


      A generic method (*)


      A generic class


      A generic instance




      24.What is the result from the following code snippet?

      public static void main(String[] args) {
      List list1 = new ArrayList();
      list1.add(new Gum());
      List list2 = list1;
      list2.add(new Integer(9));
      System.out.println(list2.size());
      } Mark for Review
      (1) Points


      The code will not compile.


      2 (*)


      1


      an exception will be thrown at runtime





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




      26.Square brackets are a representation for any character in regular expressions "[ ]".
      True or false? Mark for Review
      (1) Points


      True


      False (*)




      27.Which of the following correctly defines Pattern? Mark for Review
      (1) Points


      A regular expression symbol that represents any character.


      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.


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




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




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





      30.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);
      }
      } Mark for Review
      (1) Points


      9120423 (*)


      91227


      Compile fails.


      23


      91204

      Delete
    3. 31.Which of the following correctly defines a StringBuilder? Mark for Review
      (1) Points


      A class inside the java.util.regex package.


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




      32.The base case condition can work with a constant or variable.
      True or false? Mark for Review
      (1) Points


      True (*)


      False





      33.A non-linear recursive method can call how many copies of itself? Mark for Review
      (1) Points


      1


      2 or more (*)


      None




      34.Consider the following recursive method recur(x, y). What is the value of recur(4, 3)?

      public static int recur(int x, int y) {
      if (x == 0) {
      return y;
      }
      return recur(x - 1, x + y);
      } Mark for Review
      (1) Points


      12


      10


      13 (*)


      9





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





      36.If a programmer uses the line
      import com.test.*,
      there is no need to use
      import com.test.code.*
      True or false? Mark for Review
      (1) Points


      True


      False (*)




      37.An example of two tier architecture would be a client application working with a server application.
      True or false? Mark for Review
      (1) Points


      True (*)


      False



      38.The method for connecting a java application to a database is JNLP.
      True or false? Mark for Review
      (1) Points


      True


      False (*)





      39.Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.
      True or false? Mark for Review
      (1) Points


      True (*)


      False




      40.The java.nio.file package has improved exception handling.
      True or false? Mark for Review
      (1) Points


      True (*)


      False

      Delete
    4. 41.The System.in is what type of stream? Mark for Review
      (1) Points


      A BufferedReader stream


      A Reader stream


      A BufferedWriter stream


      A PrintStream


      An InputStream (*)




      42.An ObjectInputStream lets you read a serialized object.
      True or false? Mark for Review
      (1) Points


      True (*)


      False




      43.To execute a stored SQL procedure, which JDBC interface should be used? Mark for Review
      (1) Points


      Statement Interface


      PreparedStatement Interface


      PrePreparedStatement Interface


      CallableStatement Interface (*)




      44.Which of the following classes or interfaces are included in the database vendor driver library? (Choose two) Mark for Review
      (1) Points

      (Choose all correct answers)


      Statement interface implementation (*)


      Java.sql.Connection


      Javax.sql.DataSource


      Javax.sql.DataSource implementation (*)


      Java.sql.DriverManager implementation




      45.How many categories of JDBC drivers are there? Mark for Review
      (1) Points


      1


      2


      3


      4 (*)




      46.Given the following code, assume there are rows of data in the table EMP. What is the result?

      1 Connection conn - new Connection(URL);
      2 Statement stmt = conn.createStatement();
      3 ResultSet result - stmt.executeQuery("select count(*) from EMP");
      4 if(rs.next()){
      5 System.out.println(rs.getInt(1));
      6 } Mark for Review
      (1) Points


      Compiler error on line 2


      Runtime error on line 3


      2


      0


      Compiler error on line 1 (*)





      47.Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does the following output?

      String sql = "select first_name from Employees order by first_name desc";
      Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
      ResultSet rset= stmt.executeQuery(sql);
      rset.absolute(1);
      rset.next();
      System.out.println(rset.getString(1));
      Mark for Review
      (1) Points


      A


      B (*)


      C


      The code does not compile.


      A SQLException is thrown.




      48.From JDBC, how would you execute DML statements (i.e. insert, delete, update) in the database? Mark for Review
      (1) Points


      By making use of the execute(...) statement from DataStatement Object


      By invoking the executeDelete(...), executeUpdate(...) methods of the DataStatement


      By invoking the execute(...) or executeUpdate(...) method of a JDBC Statement object or sub-interface object (*)


      By invoking the DeleteStatement or UpdateStatement JDBC object




      49.Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for Review
      (1) Points


      !


      ? (*)


      @


      #




      50.JDBC has a type system that can control the conversion between Oracle database types and Java types. Mark for Review
      (1) Points


      True (*)


      False

      Delete
  10. 11.Bytecode contains different opcodes for every type of loop written in source code.


    True


    False (*)

    ReplyDelete
    Replies
    1. 3.Class Object is the root of the Java class hierarchy. True or False?


      True (*)


      False

      Delete
    2. 5. When do you use try-catch statements?


      If you want to switch different values for a certain variable.


      When you want to handle an exception. (*)


      When you want to exit your code before an exception is caught.


      Every time you would like to assign a new value to a variable that is being asserted.


      7.The instanceof operator enables to discover the type of object it was invoked upon.
      True or false?


      True (*)


      False



      8.Java provides virtual method invocation as a feature and it doesn't require specialized coding.
      True or false?


      True (*)



      False


      13.Making a class immutable means:


      That it is directly subclassed from the Object class


      To create an instance of the class.


      To create a sub class from a parent class


      That it cannot be extended. (*)


      15.Which one of the following statements is true?


      A Java program can only contain one super class


      A class is an intance of an object


      A class is a Java primitive


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

      Delete
    3. 17.Choose which opcode is used to fetch a field from object.


      istore


      idc


      pop


      bipush


      getfield (*)


      26.Arrays have built-in operations including add, clear, contains, get and remove. True or false?


      True


      False (*)





      27.In the relationship between two objects, the class that is being inherited from is called the maxi-class. True or false?


      True


      False (*)


      30. Which of the following is not a good technique to follow when reading code written by others?


      Perform testing.


      Build and run the code.


      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.



      31. Which of the following are important to your survival as a programmer?


      Being good at reading code.


      Looking for opportunities to read code.


      Being good at testing.


      All of these. (*)


      36.When are control flow invariants used?


      To test compilation errors in your code.


      To test specific variable values of your code.


      To test the correct flow of your code. (*)


      To test run time errors in code.


      44.The instanceof operator works with class instances and primitive data types.
      True or false?


      True


      False (*)


      49.An interfaces can declare public constants.
      True or False?


      True (*)


      False

      Delete
    4. 4.Generic methods can only belong to generic classes.
      True or False?


      True


      False (*)


      8.Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?
      The steps are shown below:

      {'M', 'S', 'A', 'T', 'H'}
      {'M', 'A', 'S', 'T', 'H'}
      {'A', 'M', 'S', 'T', 'H'}
      {'A', 'M', 'S', 'H', 'T'}
      {'A', 'M', 'H', 'S', 'T'}
      {'A', 'H', 'M', 'S', 'T'}


      Sequential Search


      Binary Search


      Merge Sort


      Bubble Sort (*)


      Selection Sort



      9.Which of the following describes a deque.

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


      13. A collection is an interface in the Java API.
      True or false?


      True (*)


      False




      14.Sets may contain duplicates.
      True or false?


      True


      False (*)

      Delete
    5. 1. Which of the following methods are StringBuilder methods?

      append


      delete


      insert


      replace


      All of the above. (*)




      2. Which of the following correctly defines a StringBuilder?


      A method that adds characters to a string.


      There is no such thing as a StringBuilder in Java.


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


      A class inside the java.util.regex package.




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

      (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




      4. Which of the following methods can be used to replace a segment in a string with a new string?


      remove(String oldString, String newString)


      replaceAll(String oldString, String newString) (*)


      replaceAll(String newString)


      substring(int start, int end, String newString)


      None of the above. There is no replaceAll(String newString) method with one argument.


      9. Consider that you are making a calendar and decide to write a segment of code that returns true if the string month is April, May, June, or July. Which code segment correctly implements use of regular expressions to complete this task?


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


      return month.substring(0,3);


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


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


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

      Delete
  11. 1. Which of the following is an absolute Windows path?


    /


    C:\Users\UserName\data (*)


    data


    \Users\UserName\data


    /home/user/username




    2. The way that you read from a file has changed since the introduction of Java 7.
    True or false? Mark for Review
    (1) Points


    True (*)


    False





    3. Java 7 requires you create an instance of java.nio.file.File class.
    True or false?


    True


    False (*)





    4. The new Paths class lets you resolve .. (double dot) path notation.
    True or false?


    True (*)


    False




    5. An absolute path always starts from the drive letter or mount point.


    True (*)


    False

    ReplyDelete
    Replies
    1. 6. Which of the following are files that must be uploaded to a web server to deploy a Java application/applet?(Choose Three)

      (Choose all correct answers)


      jar files (*)


      JNLP files (*)


      html files (*)


      .java files


      None of the above





      7. A jar file is built on the ZIP file format and is used to deploy java applets.
      True or false?


      True (*)


      False





      8. Java Web Start is used to deploy Java applications.
      True or false?


      True (*)


      False




      9. If a programmer uses the line
      import com.test.*,
      there is no need to use
      import com.test.code.*
      True or false?


      True


      False (*)



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


      Delete
    2. 11. The System.out is what type of stream?


      A BufferedReader stream


      A Reader stream


      A BufferedWriter stream


      An OutputStream


      A PrintStream (*)




      12. You can read input by character or line.
      True or false?


      True (*)


      False





      13. Which of the following static methods is not provided by the Files class to check file properties or duplication?


      Files.isReadable(Path p);


      Files.isArchived(Path p); (*)


      Files.isHidden(Path p);


      Files.isWritable(Path p);





      14. The read() method of java.io.Reader class lets you read a character at a time.
      True or false?


      True (*)


      False




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


      True


      False (*)

      Delete
  12. 5. The import keyword allows you to access classes of the package without package Fully Qualified Name.
    True or false?


    True (*)


    False

    10. The Files class lets you check for file properties.
    True or false?


    True (*)


    False



    11. The new Paths class lets you resolve .. (double dot) path notation.
    True or false?


    True (*)


    False





    12. Which of the following is an absolute Windows path


    /home/user/username


    data


    C:\Users\UserName\data (*)


    \Users\UserName\data


    /




    13. The Files class can perform which of the following functions?


    Works with absolute paths


    Navigates the file system


    Works across disk volumes


    Works with relative paths


    Creates files (*)



    14. The normalize() method removes redundant name elements from a qualified path.
    True or false?


    True (*)


    False




    15. Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.
    True or false?


    True (*)


    False

    ReplyDelete
  13. 5. Given the following code, assume there are rows of data in the table EMP. What is the result?

    1 Connection conn - new Connection(URL);
    2 Statement stmt = conn.createStatement();
    3 ResultSet result - stmt.executeQuery("select count(*) from EMP");
    4 if(rs.next()){
    5 System.out.println(rs.getInt(1));
    6 }


    Compiler error on line 2


    Runtime error on line 3


    2


    0


    Compiler error on line 1 (*)

    13. Which JDBC interface can be used to access information such as database URL, username and table names?


    Statement Interface


    PreparedStatement Interface


    DatabaseMetaData Interface (*)


    CallableStatement Interface

    ReplyDelete
  14. 1. Which of the following statements can be compiled?(Choose Three) Mark for Review
    (1) Points

    (Choose all correct answers)


    List list = new ArrayList();


    List list = new ArrayList(); (*)


    List list = new ArrayList(); (*)


    List list = new ArrayList(); (*)



    [Correct] Correct


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


    Line 1


    Line 2


    Line 3 (*)



    [Correct] Correct


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



    [Correct] Correct


    4. Sets may contain duplicates.
    True or false? Mark for Review
    (1) Points


    True


    False (*)



    [Correct] Correct


    5. Which interface forms the root of the collections hierarchy? Mark for Review
    (1) Points


    java.util.List


    java.util.Collection (*)


    java.util.Collections


    java.util.Map

    ReplyDelete
    Replies
    1. 6. Stacks are identical to Queues.
      True or false? Mark for Review
      (1) Points


      True


      False (*)



      [Correct] Correct


      7. Which scenario best describes a queue? 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 queue.



      [Correct] Correct


      8. The Comparable interface defines the compareTo method.
      True or false? Mark for Review
      (1) Points


      True (*)


      False



      [Correct] Correct


      9. Where you enqueue an element in the list? Mark for Review
      (1) Points


      removes it from the end of the list


      removes it from the front of the list


      adds it to the start of the list


      adds it to the end of the list (*)



      [Correct] Correct


      10. What are maps that link a Key to a Value? Mark for Review
      (1) Points


      HashSets


      ArrayLists


      HashMaps (*)


      Arrays

      Delete
    2. 11. 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


      12. Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?
      The steps are shown below:

      {'M', 'S', 'A', 'T', 'H'}
      {'M', 'A', 'S', 'T', 'H'}
      {'A', 'M', 'S', 'T', 'H'}
      {'A', 'M', 'S', 'H', 'T'}
      {'A', 'M', 'H', 'S', 'T'}
      {'A', 'H', 'M', 'S', 'T'} Mark for Review
      (1) Points


      Binary Search


      Merge Sort


      Sequential Search


      Bubble Sort (*)


      Selection Sort



      [Correct] Correct


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



      [Correct] Correct


      14. Which of the following is a sorting algorithm that involves repeatedly incrementing through the array and swapping 2 adjacent values if they are in the wrong order until all elements are in the correct order? Mark for Review
      (1) Points


      Merge Sort


      Binary Search


      Selection Sort


      Sequential Search


      Bubble Sort (*)



      [Correct] Correct


      15. 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, 2, 7, 0, 9, 5, 6, 4, 8, 3}


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


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


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


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

      Delete
    3. 16. Which of the following best describes lexicographical order? Mark for Review
      (1) Points


      A simple sorting algorithm that is inefficient on large arrays.


      The order of indicies after an array has been sorted.


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


      A complex sorting algorithm that is efficient on large arrays.



      [Correct] Correct


      17. Which of the following best describes lexicographical order? Mark for Review
      (1) Points


      The order of indicies after an array has been sorted.


      A complex sorting algorithm that is efficient on large arrays.


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


      A simple sorting algorithm that is inefficient on large arrays.



      [Correct] Correct


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



      [Correct] Correct


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



      [Correct] Correct


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

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


      III only


      I only


      I and II (*)


      II only


      II and III



      [Correct] Correct


      22. The local petting zoo is writing a program to be able to collect 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 these.



      [Incorrect] Incorrect. Refer to Section 6 Lesson 1.


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


      2


      1 2 (*)


      The code will not compile.


      1



      [Correct] Correct


      24. What is the result from the following code snippet?

      public static void main(String[] args) {
      List list1 = new ArrayList();
      list1.add(new Gum());
      List list2 = list1;
      list2.add(new Integer(9));
      System.out.println(list2.size());
      } Mark for Review
      (1) Points


      2 (*)


      an exception will be thrown at runtime


      The code will not compile.


      1



      [Correct] Correct



      Section 7
      (Answer all questions in this section)

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

      Delete
    5. 26. 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



      [Correct] Correct


      27. What is the function of the asterisk (*) in regular expressions? Mark for Review
      (1) Points


      Indicates that the preceding character may occur 1 or more 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 0 or 1 times in a proper match.



      [Correct] Correct


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



      [Correct] Correct


      29. Which of the following are true about parsing a String?(Choose Three) Mark for Review
      (1) Points

      (Choose all correct answers)


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


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


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



      [Correct] Correct


      30. Which of the following methods can be used to replace a segment in a string with a new string? Mark for Review
      (1) Points


      remove(String oldString, String newString)


      replaceAll(String oldString, String newString) (*)


      replaceAll(String newString)


      substring(int start, int end, String newString)


      None of the above. There is no replaceAll(String newString) method with one argument.

      Delete
    6. 31. 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.



      [Correct] Correct


      32. Which case handles the last recursive call? Mark for Review
      (1) Points


      The convergence case


      The primary case


      The base case (*)


      The recursive case


      The secondary case



      [Correct] Correct


      33. Which two statements can create an instance of an array? (Choose Two) Mark for Review
      (1) Points

      (Choose all correct answers)


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


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


      char[] ca = "java";


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


      double da = new double [5];



      [Correct] Correct


      34. The base case condition can work with a constant or variable.
      True or false? Mark for Review
      (1) Points


      True (*)


      False



      [Correct] Correct


      35. Forward thinking helps when creating linear recursive methods.
      True or false? Mark for Review
      (1) Points


      True


      False (*)

      Delete
    7. 36. Which of the following are files that must be uploaded to a web server to deploy a Java application/applet?(Choose Three) Mark for Review
      (1) Points

      (Choose all correct answers)


      jar files (*)


      JNLP files (*)


      html files (*)


      .java files


      None of the above



      [Correct] Correct


      37. To deploy java applications you may use Java Web Start.
      True or false? Mark for Review
      (1) Points


      True (*)


      False



      [Correct] Correct


      38. Which of the following files are not required to be uploaded to a web server to deploy a JWS java application/applet? Mark for Review
      (1) Points


      jar files


      JNLP files


      html files


      .java files (*)


      None of the above



      [Correct] Correct


      39. Which statement determine that "java" is a directory? Mark for Review
      (1) Points


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


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


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


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



      [Correct] Correct


      40. You can read input by character or line.
      True or false? Mark for Review
      (1) Points


      True (*)


      False

      Delete
    8. 41. The java.nio.file package has improved exception handling.
      True or false? Mark for Review
      (1) Points


      True (*)


      False



      [Correct] Correct


      42. Which of these construct a DataInputStream instance? Mark for Review
      (1) Points


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


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


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


      New dataInputStream("java.txt");


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



      [Correct] Correct



      Section 9
      (Answer all questions in this section)

      43. Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does the following output?

      String sql = "select first_name from Employees order by first_name desc";
      Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
      ResultSet rset= stmt.executeQuery(sql);
      rset.absolute(1);
      rset.next();
      System.out.println(rset.getString(1));
      Mark for Review
      (1) Points


      A


      B (*)


      C


      The code does not compile.


      A SQLException is thrown.



      [Correct] Correct


      44. Which type of Statement can execute parameterized queries? Mark for Review
      (1) Points


      ParameterizedStatement


      CallableStatement and ParameterizedStatement


      PreparedStatement (*)


      All of the above



      [Correct] Correct


      45. Which of the following is the correct statement be inserted at //INSERT CODE location that calls the database-stored procedure sayHello?

      class Test{
      public static void main(String[] args) {
      try {
      Connection conn = getConnection();
      //INSERT CODE
      cstat.setString(1, "Hello");
      cstat.registerOutParameter(2, Types.NUMERIC);
      cstat.setInt(2, 10);
      }
      catch(SQLException e){}
      }
      }
      Mark for Review
      (1) Points


      CallableStatement cstat = con.prepareCall("{sayHello(?, ?)}");


      CallableStatement cstat = con.prepareCall("{call procedure_sayHello (?, ?)}");


      CallableStatement cstat = con.prepareCall("{call sayHello}");


      CallableStatement cstat = con.prepareCall("sayHello(?, ?)");


      CallableStatement cstat = con.prepareCall("{call sayHello(?, ?)}"); (*)

      Delete
    9. 46. Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for Review
      (1) Points


      !


      ? (*)


      @


      #



      [Correct] Correct


      47. How many categories of JDBC drivers are there? Mark for Review
      (1) Points


      1


      2


      3


      4 (*)



      [Correct] Correct


      48. What type of JDBC driver will convert the database invocation directly into network protocol? Mark for Review
      (1) Points


      Type 1 driver


      Type 2 driver


      Type 3 driver


      Type 4 driver (*)



      [Correct] Correct


      49. Which of the following is NOT a JDBC interface used to execute SLQ statements? Mark for Review
      (1) Points


      Statement Interface


      PreparedStatement Interface


      PrePreparedStatement Interface (*)


      CallableStatement Interface



      [Correct] Correct


      50. You must explicitly close ResultSet and Statement objects once they are no longer in use. Mark for Review
      (1) Points


      True (*)


      False

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

    boolean status=false;
    int i=1;
    if( (++i>1) && (status=true))
    i++;
    if( (++i>3) || (status=false))
    i++;
    System.out .println (i); Mark for Review
    (1) Points

    3
    4
    5 (*)
    6

    ReplyDelete
    Replies
    1. Virtual method invocation occurs: Mark for Review
      (1) Points

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

      Correct Correct

      Delete
  16. This is very great thinks. It was very comprehensive post and powerful concept. Thanks for your sharing with us. Keep it up..
    Oracle Training in Chennai | Oracle Training Institutes in Chennai

    ReplyDelete
  17. Which of the following methods will move the cursor, returning a Boolean value from the ResultSet Object?

    beforeFirst() (*)
    absolute()
    afterFirst()
    afterLast()
    beforeLast()
    previous() (*)

    ReplyDelete
  18. What is the output from the following code snippet?

    Integer[] ar = {1, 2, 1, 3};
    Set set = new TreeSet(Arrays.asList(ar));
    set.add(4);
    for (Integer element : set) {
    System.out.print(element);
    }

    11234
    1213
    12134
    1234 (*)

    ReplyDelete
  19. What is the output from the following code snippet?

    TreeSett=new TreeSet();

    if (t.add("one"))

    if (t.add("two"))

    if (t.add ("three"))

    t.add("four");

    for (String s : t)

    System.out.print (s);

    twofouronethree
    The code does not compiles.
    onetwothreefour
    fouronethreetwo (*)

    ReplyDelete
  20. Unit testing is the phase in software testing in which individual software modules are combined and tested as a whole. True or false?

    True
    False (*)

    ReplyDelete
  21. What is the result from the following code snippet?

    interface Shape {}
    class Circle implements Shape{}
    class Rectangle implements Shape{}
    public class Test{
    public static void main(String[] args) {
    List ls= new ArrayList();//line 1
    ls.add(new Circle());
    ls.add(new Rectangle());// line 2
    ls.add(new Integer(1));// line 3
    System.out.println(ls.size());// line 4
    }

    Compilation error at line 3

    3 (*)
    Compilation error at line 2
    Compilation error at line 4
    Compilation error at line 1

    ReplyDelete
  22. Examine the code below. Which statement about this code is true?

    1.class Shape { }
    2.class Circle extends Shape { }
    3.class Rectangle extends Shape { }

    4.class Node { }

    5.public class Test{

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

    7.Node nc = new Node<>();
    8.Node ns = nc;
    }
    }

    An error at line 7 causes compilation to fail.
    An error at line 8 causes compilation to fail. (*)
    The code compiles.
    An error at line 4 causes compilation to fail.

    ReplyDelete
  23. Which of the following is a valid JDBC URL?

    oracle:thin:localhost@dfot/dfot:1521/xepdb1
    jdbc::oracle-thin:dfot/dfot@oracle:1521/xepdb1
    jdbc:oracle:thin:dfot/dfot@localhost:1521/xepdb1 (*)
    oracle:thin:jdbc:dfot/dfot@localhost:1521/xepdb1

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

    ReplyDelete
  25. terima kasih sangat membantu boss good

    ReplyDelete
  26. Thank you for valuable information.I am privilaged to read this post. oracle training in chennai

    ReplyDelete
  27. This comment has been removed by the author.

    ReplyDelete
  28. Nice Post! Thanks for sharing such an amazing article, really informative, it helps me a lot.
    Oracle Java Certifications

    ReplyDelete
  29. 6. Modeling business problems requires understanding the interaction between interfaces, abstract and concrete classes, subclasses, and enum classes.
    Mark for Review

    (1) Points
    True (*)
    False

    ReplyDelete

  30. 6. The following code can be compiled, True/False?
    byte b = 1 + 1;
    Mark for Review

    (1) Points
    True (*)
    False

    ReplyDelete
  31. 14. A base case can handle nested conditions.
    True or false?

    True (*)
    False

    ReplyDelete
  32. Wildcards in generics allows us greater control on the types that can be used.
    True or False?

    True (*)
    False

    ReplyDelete
  33. When you delete files, directories, or links with the delete(Path p) method which of the following exceptions can occur (Choose all that apply).
    Mark for Review

    (1) Points
    NoSuchFileException
    (*)
    DirectoryNotEmptyException
    (*)
    No exception is thrown

    IOException
    (*)

    ReplyDelete
  34. The java.io package has problems with no support for symbolic links.
    True or false?
    Mark for Review

    (1) Points
    True (*)
    False

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

    ReplyDelete
  36. Which is the correct way to initialize a HashSet?
    Mark for Review

    (1) Points
    classMates = new HashSet[String]();
    ClassMates = public class
    HashSet();
    String classMates = new
    String();
    HashSet classMates =
    new HashSet>(); (*)

    ReplyDelete
  37. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose Three)
    Mark for Review

    (1) Points
    Read the String backwards (from last element to first element).
    (*)
    Parse the String.
    (*)
    Search for a specific character or String inside of the String.
    (*)
    You don't use a FOR loop with Strings

    ReplyDelete
  38. Which of the following is NOT TRUE about Java?
    Mark for Review

    (1) Points
    The JVM offers a secure environment to run a Java application
    Bytecode is not portable, and needs to be compiled again in order to run on a different platform. (*)
    The JVM can interpret bytecode.
    Once Java source code is compiled, it converts to bytecode.

    ReplyDelete
  39. Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list.

    True (*)
    False

    ReplyDelete
  40. A serialized class implements which interface?

    Serializable (*)
    SerializedObject
    Serializer
    Serializing
    Serialized

    ReplyDelete
  41. 38. Which of the following methods adds a Key-Value map to a HashMap?

    add(Key, Value)
    put(Key, Value) (*)
    remove(Key, Value)
    get(Key, Value)

    ReplyDelete
  42. When you import a package, subpackages will not be imported.
    True or false?

    True (*)
    False

    ReplyDelete
  43. < ? > is an example of a bounded generic wildcard.
    True or False?
    (0/1) Points
    True
    False (*)

    ReplyDelete
  44. The local petting zoo is writing a program to be able to collect 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?
    (0/1) Points
    public class
    animalCollection {...} (*)
    public class
    animalCollection(AnimalType T) {...}
    public class
    animalCollection {...}
    public class
    animalCollection(animalType) {...}
    None of the these.

    ReplyDelete
  45. A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering.
    True or false?
    (0/1) Points
    True (*)
    False

    ReplyDelete
  46. Implementing the Comparable interface in your class allows you to define its sort order.
    True or false?
    (0/1) Points
    True (*)
    False

    ReplyDelete
  47. 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)?
    (1/1) Points
    Sequential Search
    Merge Sort
    Selection Sort
    Binary Search (*)
    All of the above
    None of the above.

    ReplyDelete
  48. What is the result of the following code snippet??

    1. abstract class AbstractBankAccount {
    2. abstract int getBalance ();
    3. }
    4. public class CreditAccount extends AbstractBankAccount{
    5. private int balance;
    6. private int getBalance (){
    7. return balance;
    8. }
    9.}
    Compilation is successful.
    An error at line 6 causes compilation to fail. (*)
    An error at line 4 causes compilation to fail.
    An error at line 2 causes compilation to fail.

    ReplyDelete
  49. 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?
    True
    False (*)

    ReplyDelete

  50. We appreciate your interest in the Oracle Java programming midterm and sections 1-5. However, it is important to maintain academic integrity and uphold the value of individual learning. Instead of providing direct answers to specific exams, we encourage you to utilize this platform for meaningful discussions and collaborative learning. Feel free to share your insights, experiences, and questions related to Java programming. Engage in conceptual discussions, problem-solving collaborations, code reviews, and resource sharing. By fostering a supportive and inclusive community, we can collectively enhance our understanding of Java programming and grow as developers. Let's create an environment that promotes learning, cheap camera for photography, collaboration, and the exchange of ideas.

    ReplyDelete
  51. Nice blog, Java programming is best choice for career. Learn Java course in Bhopal to grow your career.

    ReplyDelete
  52. Great Post this help me a lot in my college project java Programming is best for backened language. If you know more about It course it include a Full stack development course in pune to enhance your carrer.

    ReplyDelete