0% found this document useful (0 votes)
148 views95 pages

05 - BTJB - Quiz1 - Java Basics &OOP in Java: Return To Assessment List

This document contains a 20 question quiz on Java basics and object-oriented programming concepts in Java. The questions cover topics like variable declaration, operators, control flow, arrays, strings, and more. For each question, multiple choice options for the output of sample code snippets are provided.

Uploaded by

Nguyễn Thư
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views95 pages

05 - BTJB - Quiz1 - Java Basics &OOP in Java: Return To Assessment List

This document contains a 20 question quiz on Java basics and object-oriented programming concepts in Java. The questions cover topics like variable declaration, operators, control flow, arrays, strings, and more. For each question, multiple choice options for the output of sample code snippets are provided.

Uploaded by

Nguyễn Thư
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 95

05_BTJB_Quiz1_Java Basics &OOP in Java

Return to Assessment List

Part 1 of 1 - 95.0/ 100.0 Points

Question 1 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
int a = 1; // 1
short b = 1; // 2
long c = 1; // 3
a = c + a; // 4
c = b + a; // 5
}
}
A compile-time error is generated at which line?

A. 1

B. 2

C. 3

D. 4

E. 5

F. None of the above


Question 2 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
// Insert code here.
}
}
Which of the following lines can be inserted at the specified location without generating a compile-time error?

A. boolean b1 = true;

B. boolean b2 = TRUE;

C. boolean b3 = 'true';

D. boolean b4 = "TRUE";

E. boolean b5 = 0;

F. None of the above

Question 3 of 20
0.0/ 5.0 Points
class E {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = a || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,true,false

B. Prints: true,true,false

C. Prints: false,true,true

D. Prints: true,false,false

E. Prints: false,false,true

F. Prints: false,false,false

G. Prints: true,true,true

H. Compile-time error

I. Run-time error


J. Prints: true,false,true

Question 4 of 20
5.0/ 5.0 Points
class JMM122 {
public static void main (String[] args) {
for (int i = 0; i < 4; i++) {
switch (i) {
case 0: System.out.print("A");
case 1: System.out.print("B");
case 2: System.out.print("C");
}
}
}
}
What is the result of attempting to compile and run the program?

A. Prints: ABC

B. Prints: ABCC

C. Prints: CBA

D. Prints: ABCBCC

E. Run-time error

F. Compile-time error

G. None of the above

Question 5 of 20
5.0/ 5.0 Points
class M {
static void m1(String s1) {
s1.replace('A','Y'); System.out.print(s1);
}
static void m2(String s1) {
s1 = s1.replace('A','Z'); System.out.print(s1);
}
public static void main(String[] s) {
String s1 = "A"; m1(s1); m2(s1);
System.out.print(s1);
}
}
What is the result of attempting to compile and run the program?

A. Prints: AAA

B. Prints: YZA

C. Prints: YAA

D. Prints: AZA

E. Compile-time error


F. Run-time error

G. None of the above

Question 6 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
String a1 = null; // 1
String b1 = 'null'; // 2
String c1 = "null"; // 3
String d1 = "'null'"; // 4
}
}
A compile-time error is generated at which line?

A. 1

B. 2

C. 3

D. 4

E. None of the above

Question 7 of 20
5.0/ 5.0 Points
class A {
public static void main(String[] args) {
boolean b;
if (b = false) {System.out.print("A");
} else if (b) {System.out.print("B");
} else if (!b) {System.out.print("C");
} else {System.out.print("D");}
}
}
What is the result of attempting to compile and run the program?

A. Prints: A

B. Prints: B

C. Prints: C

D. Prints: D

E. Run-time error

F. Compile-time error

G. None of the above

Question 8 of 20
5.0/ 5.0 Points
class M {
static boolean b;
public static void main(String[] args) {
if (b) {System.out.print("A");
} else if (b = false) {System.out.print("B");
} else if (b) {System.out.print("C");
} else if (!b) {System.out.print("D");
} else {System.out.print("E");}
}
}
What is the result of attempting to compile and run the program?

A. Prints: A

B. Prints: B

C. Prints: C

D. Prints: D

E. Prints: E

F. Run-time error

G. Compile-time error

H. None of the above


Question 9 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] args) {
int[][] a1 = {{1,2,3},{4,5,6},{7,8,9,10}};
System.out.print(a1[0][2]+","+a1[1][0]+","+a1[2][1]);
}
}
What is the result of attempting to compile and run the program?

A. Prints: 3,4,8

B. Prints: 7,2,6

C. Compile-time error

D. Run-time error

E. None of the above

Question 10 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
String s1 = "ABCDE";
System.out.print(s1.substring(1,2)+s1.substring(3));
}}
What is the result of attempting to compile and run the program?

A. Prints: AABC

B. Prints: ACDE

C. Prints: ABABC

D. Prints: ABCDE

E. Prints: BABCD

F. Prints: BDE

G. None of the above

Question 11 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
int j = 0;
for (int i = 0; i < 2; i++) do
System.out.print(i);
while (j++ < 2);
}
}
What is the result of attempting to compile and run the program?

A. Prints: 0001

B. Prints: 012

C. Prints: 012012

D. Prints: 012345

E. Prints: 001122

F. Prints: 1112

G. Prints: 111222

H. Prints: 121212

I. Run-time error

J. Compile-time error

Question 12 of 20
5.0/ 5.0 Points
class M {
static int i;
public static void main(String args[]) {
for (i=1; i<3; i++) {System.out.print(i);} // 1
for (int i=1; i<3; i++) {System.out.print(i);} // 2
int i; // 3
for (i=0; i<2; i++) {System.out.print(i);} // 4
System.out.print(M.i);
}
}
What is the result of attempting to compile and run the program?

A. Prints: 1212010

B. Prints: 1212013

C. Compile-time error at line 1

D. Compile-time error at line 2

E. Compile-time error at line 4

F. Run-time error

G. None of the above

Question 13 of 20
5.0/ 5.0 Points
class A {
public static void main(String[] args) {
char a = 'a', b = 'b'; // 'a' = 97, 'b' = 98
System.out.print(a + b + "" + a + b);
}
}
What is the result of attempting to compile and run the program?

A. Prints: 390

B. Prints: 195195

C. Prints: 195ab

D. Prints: ab195

E. Prints: abab

F. Run-time error

G. Compile-time error

H. None of the above

Question 14 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] s) {
String s1 = new String("ABCDEFG"), s2 = new String("EFGHIJ");
String s3 = s1.substring(4,7), s4 = s2.substring(0,3);
System.out.println((s3 == s4) + "," + (s3 + s4).equals(s4 + s3));
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false

B. Prints: false,true

C. Prints: true,false

D. Prints: true,true

E. Compile-time error

F. Run-time error

G. None of the above

Question 15 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] args) {
boolean b;
if (b = false) {System.out.print("A");
} else if (b) {System.out.print("B");
} else if (!b) {System.out.print("C");
} else {System.out.print("D");}
}
}
What is the result of attempting to compile and run the program?

A. Prints: A

B. Prints: B

C. Prints: C

D. Prints: D

E. Run-time error

F. Compile-time error

G. None of the above

Question 16 of 20
5.0/ 5.0 Points
class A {
public static void main(String[] args) {
for (int i = 0; i < 4; i++) {
switch (i) {
case 0:
System.out.print("A");
case 1:
System.out.print("B");
case 2:
System.out.print("C");
}
}
}
}

A. Prints: ABC

B. Prints: ABCC

C. Prints: CBA

D. Prints: ABCBCC

E. Run-time error

F. Compile-time error

G. None of the above

Question 17 of 20
5.0/ 5.0 Points
class E {
public static void main(String args[]) {
int a = 1; a += ++a + a++; System.out.print(a);
}
}
What is the result of attempting to compile and run the above program?

A. Prints: 3

B. Prints: 4

C. Prints: 5

D. Prints: 6

E. Prints: 7

F. Run-time error

G. Compile-time error

H. None of the above

Question 18 of 20
5.0/ 5.0 Points
class E {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false,false

B. Prints: false,false,true

C. Prints: false,true,false

D. Prints: false,true,true

E. Prints: true,false,false

F. Prints: true,false,false

G. Prints: true,true,false

H. Prints: true,true,true

I. Run-time error

J. Compile-time error

Question 19 of 20
5.0/ 5.0 Points
class A {
public static void main(String args[]) {
for (int i = 0; i<5 ;i++) {
switch(i) {
case 0: System.out.print("v ");break;
case 1: System.out.print("w ");
case 2: System.out.print("x ");break;
case 3: System.out.print("y ");
case 4: System.out.print("z ");break;
default: System.out.print("d ");
}
}
}
}
What is the result of attempting to compile and run the program?

A. Prints: v w x y z

B. Prints: v w x y z d

C. Prints: v w x x y z z

D. Prints: v w w x y y z d

E. Prints: d d d d d d

F. Run-time error

G. Compile-time error

H. None of the above

Question 20 of 20
5.0/ 5.0 Points
class M {
public static void main(String args[]) {
int x = 6; int success = 0;
do {
switch(x) {
case 0: System.out.print("0"); x += 5; break;
case 1: System.out.print("1"); x += 3; break;
case 2: System.out.print("2"); x += 1; break;
case 3: System.out.print("3"); success++; break;
case 4: System.out.print("4"); x -= 1; break;
case 5: System.out.print("5"); x -= 4; break;
case 6: System.out.print("6"); x -= 5; break;
}
} while ((x != 3) || (success < 2));
}
}
What is the result of attempting to compile and run the program?

 A. Prints: 60514233
 B. Prints: 6152433
 C. Run-time error
 D. Prints: 61433
 E. Prints: 6143
 F. Compile-time error
05_BTJB_Quiz2_Advanced OOP in Java
Return to Assessment List

Part 1 of 1 - 90.0/ 100.0 Points

Question 1 of 20
5.0/ 5.0 Points
class A {void m1(A a) {System.out.print("A");}}
class B extends A {void m1(B b) {System.out.print("B");}}
class C extends B {void m1(C c) {System.out.print("C");}}
class D {
public static void main(String[] args) {
A a1 = new A(); A b1 = new B(); A c1 = new C(); C c4 = new C();
a1.m1(c4); b1.m1(c4); c1.m1(c4);
}
}
What is the result of attempting to compile and run the program?

A. Prints: AAA

B. Prints: ABC

C. Prints: CCC

D. Compile-time error

E. Run-time error

F. None of the above


Question 2 of 20
5.0/ 5.0 Points
class G {
static void m(Object x) {System.out.print("Object");}
static void m(String x) {System.out.print("String");}
public static void main(String[] args) {m(null);}
}
What is the result of attempting to compile and run the program?

A. Prints: Object

B. Prints: String

C. Compile-time error

D. Run-time error

E. None of the above

Question 3 of 20
5.0/ 5.0 Points
class A {void m1(A a) {System.out.print("A");}}
class B extends A {void m1(B b) {System.out.print("B");}}
class C extends B {void m1(C c) {System.out.print("C");}}
class D {
public static void main(String[] args) {
A c1 = new C(); B c2 = new C(); C c3 = new C(); C c4 = new C();
c4.m1(c1); c4.m1(c2); c4.m1(c3);
}
}
What is the result of attempting to compile and run the program?

A. Prints: AAA

B. Prints: ABC

C. Prints: CCC

D. Compile-time error

E. Run-time error

F. None of the above

Question 4 of 20
5.0/ 5.0 Points
class A {
public static void main (String[] args) {
private int x = 1; protected int y = 2; public int z = 3;
System.out.println(x+y+z);
}
}
What is the result of attempting to compile and run the program?


A. Prints: 123

B. Prints: 1 2 3

C. Prints: 6

D. Run-time error

E. Compile-time error

F. None of the above

Question 5 of 20
5.0/ 5.0 Points
class A {void m1(A a) {System.out.print("A");}}
class B extends A {void m1(B b) {System.out.print("B");}}
class C extends B {void m1(C c) {System.out.print("C");}}
class D {
public static void main(String[] args) {
A c1 = new C(); C c2 = new C(); c1.m1(c2);
}
}
What is the result of attempting to compile and run the program?

A. Prints: A

B. Prints: B

C. Prints: C

D. Compile-time error

E. Run-time error

F. None of the above

Question 6 of 20
5.0/ 5.0 Points
Which of the following modifiers can be applied to the declaration of a field?(Multi choice)

A. abstract

B. final

C. private

D. protected

E. Public
Question 7 of 20
5.0/ 5.0 Points
public class Basics {} // 1
class Basics1 {} // 2
protected class Basics2 {} // 3
private class Basics3 {} // 4
Class Basics4 {} // 5

Suppose these are top-level class declarations and not nested class declarations; and suppose that all of the
declarations are contained in one file named Basics.java. Compile-time errors are generated at which lines? (Multi
choice)
A. 1

B. 2

C. 3

D. 4

E. 5
Question 8 of 20
5.0/ 5.0 Points
class G {
int x; // 1
public static void main(String[] args) { // 2
int y = 0; // 3
System.out.print(x+","); // 4
System.out.print(y); // 5
}
}
What is the result of attempting to compile and run the program?

A. Prints: 0,0

B. Compile-time error at line 1.

C. Compile-time error at line 1.

D. Compile-time error at line 2.

E. Compile-time error at line 3.


F. Compile-time error at line 4.

G. Compile-time error at line 5.

H. Run-time error

I. None of the above

Question 9 of 20
5.0/ 5.0 Points
Which of the following modifiers can not be used with the abstract modifier in a method declaration? (Multi choice)

A. final

B. private

C. protected

D. public

E. static

F. synchronized

G. native
Question 10 of 20
0.0/ 5.0 Points
Which of the following statements is true?

A. An abstract method can not be overridden by an abstract method.


B. An instance method that is not abstract can not be overridden by an abstract method.

C. An abstract method declaration can not include a throws clause.

D. The body of an abstract method is represented by a set of empty brackets.

E. None of the above.

Question 11 of 20
5.0/ 5.0 Points
class G {
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
int a1 = 1; long b1 = 2; System.out.print(m(a1)+","+ m(b1));
}
}
What is the result of attempting to compile and run the program?

A. Prints: float,float

B. Prints: float,double

C. Prints: double,float


D. Prints: double,double

E. Compile-time error

F. Run-time error

G. None of the above

Question 12 of 20
5.0/ 5.0 Points
class Basics {
int x = 1, y = 2;
public static void main (String[] args) {System.out.println(x+y);}
}
What is the result of attempting to compile and run the program?

A. Prints: x+y

B. Prints: 12

C. Prints: 3

D. Run-time error

E. Compile-time error

F. None of the above

Question 13 of 20
5.0/ 5.0 Points
class G {
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
char a1 = 1; long b1 = 2; System.out.print(m(a1)+","+ m(b1));
}
}
What is the result of attempting to compile and run the program?

A. Prints: float,float

B. Prints: float,double

C. Prints: double,float

D. Prints: double,double

E. Compile-time error

F. Run-time error


G. None of the above

Question 14 of 20
5.0/ 5.0 Points
Which of the following modifiers can be applied to a constructor?

A. private

B. abstract

C. final

D. volatile

E. native

F. None of the above.

Question 15 of 20
0.0/ 5.0 Points
class A {void m1(A a) {System.out.print("A");}}
class B extends A {void m1(B b) {System.out.print("B");}}
class C extends B {void m1(C c) {System.out.print("C");}}
class D {
public static void main(String[] args) {
A a1 = new A(); B b1 = new B(); C c1 = new C(); C c2 = new A();
c2.m1(a1); c2.m1(b1); c2.m1(c1);
}
}
What is the result of attempting to compile and run the program?

A. Prints: AAA

B. Prints: ABC

C. Prints: CCC

D. Compile-time error

E. Run-time error

F. None of the above

Question 16 of 20
5.0/ 5.0 Points
class Red {
public int a; public static int b;
public static void main (String[] in) {
Red r1 = new Red(), r2 = new Red(); r1.a++; r1.b++;
System.out.print(r1.a+", "+r1.b+", "+r2.a+", "+r2.b);
}
}
What is the result of attempting to compile and run the program?


A. Prints: 0, 0, 0, 0

B. Prints: 0, 1, 1, 1

C. Prints: 1, 1, 1, 0

D. Prints: 1, 1, 0, 1

E. Prints: 1, 1, 0, 0

F. Prints: 1, 1, 1, 1

G. Compile-time error

H. Run-time error

I. None of the above

Question 17 of 20
5.0/ 5.0 Points
Which of the following modifiers can not be applied to a method?

A. abstract

B. private

C. protected

D. public

E. volatile

F. None of the above.

Question 18 of 20
5.0/ 5.0 Points
class A {
static int x; // 1
public static void main(String[] args) { // 2
int y; // 3
System.out.println("x="+x); // 4
System.out.println("y="+y); // 5
}
}
What is the result of attempting to compile and run the program?

A. Compile-time error at line 1.

B. Compile-time error at line 2.


C. Compile-time error at line 3.

D. Compile-time error at line 4.

E. Compile-time error at line 5.

F. Run-time error

G. None of the above

Question 19 of 20
5.0/ 5.0 Points
class G {
static String m(int i) {return "int";}
static String m(float i) {return "float";}
public static void main (String[] args) {
long a1 = 1; double b1 = 2; System.out.print(m(a1)+","+ m(b1));
}
}
What is the result of attempting to compile and run the program?

A. Prints: float,float

B. Prints: float,double

C. Prints: double,float

D. Prints: double,double

E. Compile-time error

F. Run-time error

G. None of the above

Question 20 of 20
5.0/ 5.0 Points
class A {} class B extends A {} class C extends B {}
class D {
void m1(A a) {System.out.print("A");}
void m1(B b) {System.out.print("B");}
void m1(C c) {System.out.print("C");}
public static void main(String[] args) {
A c1 = new C(); B c2 = new C(); C c3 = new C(); D d1 = new D();
d1.m1(c1); d1.m1(c2); d1.m1(c3);
}
}
What is the result of attempting to compile and run the program?

 A. Prints: AAA
 B. Prints: ABC
 C. Prints: CCC
 D. Compile-time error
 E. Run-time error
 F. None of the above
05_BTJB_Quiz3_Exception Handling & Utility Classes
Return to Assessment List

Part 1 of 1 - 75.0/ 100.0 Points

Question 1 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
String s1 = "ABC";
StringBuffer s2 = new StringBuffer(s1);
System.out.print(s2.equals(s1) + "," + s1.equals(s2));
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false

B. Prints: false,true

C. Prints: true,false

D. Prints: true,true

E. Compile-time error

F. Run-time error


G. None of the above

Question 2 of 20
5.0/ 5.0 Points
• Entries are organized as key/value pairs.
• Duplicate entries replace old entries.
• Entries are sorted using a Comparator or the Comparable interface.
Which interface of the java.util package offers the specified behavior?

A. List

B. Map

C. Set

D. SortedSet

E. SortedMap

F. None of the above

Question 3 of 20
5.0/ 5.0 Points
class A {
public static void main (String[] args) {
Error error = new Error();
Exception exception = new Exception();
System.out.print((exception instanceof Throwable) + ",");
System.out.print(error instanceof Throwable);
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false

B. Prints: false,true

C. Prints: true,false

D. Prints: true,true

E. Compile-time error

F. Run-time error

G. None of the above

Question 4 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] s) {
String s1 = "A", s2 = " B ", s3 = "C";
s2.trim(); s3.concat("D");
System.out.print(s1 + s2 + s3);
}
}
What is the result of attempting to compile and run the program?

A. Prints: ABC

B. Prints: A B C

C. Prints: ABCD

D. Prints: ABDC

E. Prints: A B CD

F. Prints: A B DC

G. Compile-time error

H. Run-time error

I. None of the above

Question 5 of 20
5.0/ 5.0 Points
• Entries are organized as key/value pairs.
• Duplicate entries replace old entries.
Which interface of the java.util package offers the specified behavior?

A. List

B. Map

C. Set

D. None of the above

Question 6 of 20
5.0/ 5.0 Points
• Stores key/value pairs.
• Allows null elements, keys, and values.
• Duplicate entries replace old entries.
• Entries are not sorted.
Which of these classes provides the specified features?

A. LinkedList

B. TreeMap

C. TreeSet

D. HashMap

E. HashSet

F. Hashtable

G. None of the above

Question 7 of 20
5.0/ 5.0 Points
class B {
public static void main (String args[]) {
Byte b1 = new Byte(1); // 1
Byte b2 = new Byte('2'); // 2
Byte b3 = new Byte("3"); // 3
byte i1 = b1.byteValue()+b2.byteValue()+b3.byteValue(); // 4
System.out.print(i1);
}
}
What is the result of attempting to compile and run the program? (Multi choice)

A. Compile-time error at 1

B. Compile-time error at 4

C. Run-time error

D. Compile-time error at 3

E. Compile-time error at 2

F. Prints: 6
Question 8 of 20
5.0/ 5.0 Points
class M {
static void m1(StringBuffer s1) {
s1.append("B"); System.out.print(s1);
}
static void m2(StringBuffer s1) {
s1 = new StringBuffer("C"); System.out.print(s1);
}
public static void main(String[] s) {
StringBuffer s1 = new StringBuffer("A");
m1(s1); m2(s1);
System.out.print(s1);
}
}
What is the result of attempting to compile and run the program?

A. Prints: AAA

B. Prints: ABCA

C. Prints: ABCAB

D. Prints: ABCABC

E. Prints: ABCAC

F. Prints: ABABCABC

G. Compile-time error

H. Run-time error

I. None of the above

Question 9 of 20
5.0/ 5.0 Points
class G {
public static void main (String[] args) {
Integer i1 = new Integer("1"), i2 = new Integer("1");
StringBuffer sb1 = new StringBuffer("1");
StringBuffer sb2 = new StringBuffer("1");
System.out.print(sb1.equals(sb2)+","+i1.equals(i2));
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false

B. Prints: false,true

C. Prints: true,false

D. Prints: true,true

E. Compile-time error


F. Run-time error

G. None of the above

Question 10 of 20
5.0/ 5.0 Points
class M {
static void m1(StringBuffer s1) {
s1 = s1.append("B"); System.out.print(s1);
}
static void m2(StringBuffer s1) {
s1.append("C"); System.out.print(s1);
}
public static void main(String[] s) {
StringBuffer s1 = new StringBuffer("A");
m1(s1); m2(s1);
System.out.print(s1);
}
}
What is the result of attempting to compile and run the program?

A. Prints: AAA

B. Prints: ABAA

C. Prints: ABACA

D. Prints: ABABAB

E. Prints: ABABCAB

F. Prints: ABABCABC

G. Prints: ABCABCABC

H. Compile-time error

I. Run-time error

J. None of the above

Question 11 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] args) {
String s1 = "A", s2 = "a", s3 = "b";
s1.toLowerCase(); s3.replace('b','a');
System.out.print((s1.equals(s2)) + "," + (s2.equals(s3)));
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false

B. Prints: false,true


C. Prints: true,false

D. Prints: true,true

E. Compile-time error

F. Run-time error

G. None of the above

Question 12 of 20
0.0/ 5.0 Points
class A {
public static void main (String args[]) {
Double d1 = new Double(1.0);
Double d2 = new Double(d1);
System.out.print(d1.equals(d2));
}
}
What is the result of attempting to compile and run the program?

A. Prints: false

B. Prints: true

C. Compile-time error

D. Run-time error

E. None of the above

Question 13 of 20
0.0/ 5.0 Points
class H {
public static void main (String[] args) {
int i1, i2; Integer i3, i4;
i1=new Integer(Integer.parseInt("1")).intValue(); // 1
i3=new Integer(Integer.parseInt("1")).intValue(); // 2
i2=Integer.parseInt(Integer.valueOf("1").toString()); // 3
i4=Integer.parseInt(Integer.valueOf("1").intValue()); // 4
}
}
What is the result of attempting to compile and run the program? (Multi choice)

A. Compile-time error

B. Compile-time error at 1.

C. Compile-time error at 4.

D. Run-time error

E. Compile-time error at 2.

F. Compile-time error at 3.
Question 14 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
String s1 = new String("ABC"), s2 = new String("ABC");
StringBuffer sb1 = new StringBuffer(s1);
StringBuffer sb2 = new StringBuffer(s2);
System.out.print(s1.equals(s2) + "," + sb1.equals(sb2));
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false

B. Prints: false,true

C. Prints: true,false

D. Prints: true,true

E. Compile-time error

F. Run-time error

G. None of the above

Question 15 of 20
5.0/ 5.0 Points
class B {
public static void main (String[] args) {
byte b1 = 11;
System.out.print(new Integer(b1).equals(new Integer(b1)) + ",");
System.out.print(new Integer(b1).equals(new Short(b1)) + ",");
System.out.print(new Integer(b1).equals(new Byte(b1)));
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false,false

B. Prints: false,false,true

C. Prints: false,true,false

D. Prints: false,true,true

E. Prints: true,false,false

F. Prints: true,false,true

G. Prints: true,true,false

H. Compile-time error

I. Run-time error

J. None of the above

Question 16 of 20
5.0/ 5.0 Points
class D {
public static void main (String[] args) {
Boolean b1 = new Boolean("trUE"); // 1
Boolean b2 = new Boolean("What's This?"); // 2
Boolean b3 = new Boolean(null); // 3
System.out.print(b1 + "," + b2 + "," + b3);
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false,false

B. Prints: false,false,true

C. Prints: false,true,false

D. Prints: false,true,true

E. Prints: true,false,false

F. Prints: true,false,true

G. Prints: true,true,false

H. Prints: true,true,true

I. Compile-time error

J. Run-time error

K. None of the above

Question 17 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] s) {
String s1 = "1", s2 = "2", s3 = s1 + s2;
s1 += s2; s3 += s1;
System.out.println(s3);
}
}
What is the result of attempting to compile and run the program?

A. Prints: 3

B. Prints: 6

C. Prints: 33

D. Prints: 1212


E. Compile-time error

F. Run-time error

G. None of the above

Question 18 of 20
0.0/ 5.0 Points
class B {
public static void main (String args[]) {
Long i1 = new Long(1);
Long i2 = new Long(i1);
System.out.print((i1==i2) + "," + i1.equals(i2));
}
}
What is the result of attempting to compile and run the program?

A. Prints: false,false

B. Prints: false,true

C. Prints: true,false

D. Prints: true,true

E. Compile-time error

F. Run-time error

 G. None of the above

Question 19 of 20 0.0/ 5.0 Points


class B {
public static void main (String args[]) {
Long i1 = new Long(1);
Long i2 = new Long(i1);
System.out.print((i1==i2) + "," + i1.equals(i2));
}
}
What is the result of attempting to compile and run the program?

 A. Prints: false,false
 B. Prints: false,true
 C. Prints: true,false
 D. Prints: true,true
 E. Compile-time error
 F. Run-time error
 G. None of the above

Question 20 of 20 0.0/ 5.0 Points


class A {
public static void main (String args[]) {
Integer i1 = new Integer(1);
Integer i2 = new Integer(i1);
System.out.print(i1.equals(i2));
}
}
What is the result of attempting to compile and run the program?

 A. Prints: false
 B. Prints: true
 C. Compile-time error
 D. Run-time error
 E. None of the above

05_BTJB_Quiz4_Database Programming with JDBC


Return to Assessment List

Part 1 of 1 - 90.0/ 100.0 Points

Question 1 of 20
0.0/ 5.0 Points
You use a ____ object to access a database from a Java program. ?

A. ResultSet

B. Connection

C. ODBC

D. JDBC

Question 2 of 20
5.0/ 5.0 Points
How is the forName() method of the "Class" class used with JDBC?


A. To load a result set

B. To establish a database connection

C. To load a JDBC driver

D. To execute a SQL statementresses

Question 3 of 20
5.0/ 5.0 Points
A __________ result set has a cursor that moves both forward and backward and can be moved to a particular row

A. nonscrollable

B. scrollable

C. Unscrollable

Question 4 of 20
5.0/ 5.0 Points
Which of the following methods finds the maximum number of connections that a specific driver can obtain

A. DatabaseMetaData.getMaxConnections

B. Connection.getMaxConnections

C. ResultSetMetaData.getMaxConnections

D. Database.getMaxConnections

Question 5 of 20
5.0/ 5.0 Points
What is, in terms of JDBC, a DataSource

A. A DataSource is the basic service for managing a set of JDBC drivers

B. A DataSource is a registry point for JNDI-services

C. A DataSource is the Java representation of a physical data source


D. A DataSource is a factory of connections to a physical data source

Question 6 of 20
5.0/ 5.0 Points
Which interface of the JDBC API executes pre-compiled SQL statements?

A. Statement

B. Resultset

C. PreparedStatement

Question 7 of 20
5.0/ 5.0 Points
The methods of what type of object can be used to move the cursor through a result set? ?

A. Statement

B. Connection

C. URL

D. ResultSet

Question 8 of 20
5.0/ 5.0 Points
What statements are correct about positioned updates (i.e. cursor updates) in ResultSets

A. Using the cursor technique is currently the only possible way to change the data in the current row of a ResultSet

B. Only scrollable updateable ResultSets can use this approach to change the data in the current row of a ResultSet

C. The name of the cursor is specified by the setCursorName(String name) method the Statement object.

D. Insert statements are only supported when using scrollable cursors.


Question 9 of 20
0.0/ 5.0 Points
Which of arguments are used by DriverManager.getConnection(…) (2 correct answers)

A. url: Database url where stored or created your database

B. portNumber: the port number

C. userName: User name

D. databaseName: The database name


Question 10 of 20
5.0/ 5.0 Points
A file that stores one or more SQL statements is known as a _________. ?


A. result set

B. connection

C. SQL script

D. SQL statement

Question 11 of 20
5.0/ 5.0 Points
Conn = Driver Manager.getConnection(“jdbc:odbc:Employee”,“”,“”);

What does the above statement do?

A. Gets a database connection with the Employee data source.

B. Gets connectioned to the employee database.

C. Retrieves data from the employee table.


D. Inidicates that jdbc is to be used in the application.

Question 12 of 20
5.0/ 5.0 Points
Which java.sql class provides the getConnection() method?

A. ResultSet 71

B. DriverManager

C. Driver

D. Connection

Question 13 of 20
5.0/ 5.0 Points
The _______ class is traditional management layer of JDBC, working between the user and the drivers

A. Connection


B. DriverManager

C. Resultset

Question 14 of 20
5.0/ 5.0 Points
To improve the performance of database operations, an application can use _________ where a limited number of
connections are opened and are shared by users of the database. ?

A. init

B. OR mapping (object to relational)

C. ResultSetMetaData

D. connection pooling

Question 15 of 20
5.0/ 5.0 Points
Which of the following is false as far as type 4 driver is concern


A. Type 4 drivers are 100% Java compatible

B. Type 4 drivers uses Socket class to connect to the database

C. Type 4 driver is “native protocol, pure java” driver

D. Type 4 drivers cannot be used with Netscape

Question 16 of 20
5.0/ 5.0 Points
How can you start a database transaction in the database

A. By calling the method beginTransaction() on the Connection object

B. By asking a Transaction object to your Connection, and setting the autoCommit property of the
Transaction to false

C. By asking a Transaction object to your Connection, and calling the method begin() on it

D. By setting the autoCommit property of the Connection to false, and execute a statement in the database
Question 17 of 20
5.0/ 5.0 Points
Which type of Statement can execute parameterized queries

A. All kinds of Statements (i.e. which implement a sub interface of Statement)

B. ParameterizedStatement and CallableStatement

C. PreparedStatement

D. ParameterizedStatement

Question 18 of 20
5.0/ 5.0 Points
If one intends to work with a ResultSet, which of these PreparedStatement methods will not work?

A. execute()

B. executeUpdate()

C. executeQuery()

Question 19 of 20
5.0/ 5.0 Points
A JDBC application does the following in what order of steps?
i) Connects to a JDBC data source
ii) Parses the results of the query
iii)Executes a query
iv) closes the connection after the database operation

A. i-iii-ii-iv

B. iv-iii-ii-i

C. i-ii-iii-iv

D. ii-iii-iv-i

Question 20 of 20
5.0/ 5.0 Points
Which statements about JDBC are true (2 correct answers)

A. JDBC is an API to access relational databases, spreadsheets and flat files


B. JDBC is an API to connect to relational-, object- and XML data sources

C. JDBC stands for Java DataBase Connectivity

D. JDBC is an API to bridge the object-relational mismatch between OO programs and relational databases
05_BTJB_Quiz4_Database Programming with JDBC
Return to Assessment List

Part 1 of 1 - 50.0/ 100.0 Points

Question 1 of 20
5.0/ 5.0 Points
Which character is used to represent an input parameter in a CallableStatement?

A. *

B. #

C. ?

D. %

Question 2 of 20
5.0/ 5.0 Points
When the message “No Suitable Driver” occurs

A. When the driver is not registered by Class.forname() method


B. When the JDBC database URL passed is not constructed properly

C. When the user name, password and the database does not match

D. When the type 4 driver is used

Question 3 of 20
0.0/ 5.0 Points
Which java.sql class provides the getConnection() method?

A. ResultSet 71

B. DriverManager

C. Driver

D. Connection

Question 4 of 20
5.0/ 5.0 Points
After a SELECT statement, a _________ is a logical table that's created temporarily within the database. ?

A. recordset

B. datareader

C. dataset

D. result set

Question 5 of 20
5.0/ 5.0 Points
Which type of Statement can execute parameterized queries

A. All kinds of Statements (i.e. which implement a sub interface of Statement)

B. ParameterizedStatement and CallableStatement

C. PreparedStatement

D. ParameterizedStatement

Question 6 of 20
5.0/ 5.0 Points
A __________ result set has a cursor that moves both forward and backward and can be moved to a particular row

A. nonscrollable

B. scrollable

C. Unscrollable

Question 7 of 20
5.0/ 5.0 Points
The different types of JDBC driver are

A. Jdbc-odbc bridge, plus odbc driver

B. Native-API, partly Java driver

C. Jdbc-net, pure Java driver

D. Native-API, pure Java driver


Question 8 of 20
0.0/ 5.0 Points
A __________ object contains information about a result set like the numbers and names of the columns in the result
set. ?

A. prepared statements

B. connection pooling

C. OR mapping (object to relational)

D. ResultSetMetaData

Question 9 of 20
5.0/ 5.0 Points
A JDBC application does the following in what order of steps?
i) Connects to a JDBC data source
ii) Parses the results of the query
iii)Executes a query
iv) closes the connection after the database operation

A. i-iii-ii-iv

B. iv-iii-ii-i

C. i-ii-iii-iv

D. ii-iii-iv-i

Question 10 of 20
5.0/ 5.0 Points
The _______ interfaces is used to encapsulate SQL queries used for retrieving data from the database ?

A. Statement

B. Prepared

C. Parameter

D. Callable

Question 11 of 20
5.0/ 5.0 Points
Which of the following is NOT a way to insert data into a table?

A. a LOAD command

B. an INSERT statement

C. a SQL script

D. a configuration file

Question 12 of 20
0.0/ 5.0 Points
Which of the following methods are needed for loading a database driver in JDBC

A. registerDriver() method

B. getConnection()

C. Both A and B


D. Class.forName()

Question 13 of 20
0.0/ 5.0 Points
Which of arguments are used by DriverManager.getConnection(…) (2 correct answers)

A. url: Database url where stored or created your database

B. portNumber: the port number

C. userName: User name

D. databaseName: The database name


Question 14 of 20
0.0/ 5.0 Points
Which of the following statements is false as far as different type of statements is concern in JDBC

A. Regular Statement

B. Prepared Statement

C. Callable Statement

D. Interim Statement

Question 15 of 20
0.0/ 5.0 Points
Which java.sql class or interface is used to create the object that is necessary for calling stored procedures?

A. Statement

B. PreparedStatement

C. CallableStatement

D. ResultSet

Question 16 of 20
0.0/ 5.0 Points
What is, in terms of JDBC, a DataSource

A. A DataSource is the basic service for managing a set of JDBC drivers

B. A DataSource is a registry point for JNDI-services


C. A DataSource is the Java representation of a physical data source

D. A DataSource is a factory of connections to a physical data source

Question 17 of 20
0.0/ 5.0 Points
Which of the following communicates with a database server on behalf of a user or application?
Database table

A. Web browser

B. Database table

C. Web server

D. Database client

Question 18 of 20
5.0/ 5.0 Points
The ________ interface is used to encapsulate SQL queries used for retrieving data from the database

 A. statement
 B. Driver

Question 19 of 20
0.0/ 5.0 Points
Which statement is static and synchronized in JDBC API

 A. executeUpdate()

 B. getConnection()

 C. executeQuery()

 D. prepareCall()

Question 20 of 20
0.0/ 5.0 Points
What is correct about DDL statements (create, grant,...)

 A. DDL statements are treated as normal SQL statements, and are executed by calling the execute()
method on a Statement (or a sub interface thereof) object

 B. To execute DDL statements, you have to install additional support files

 C. Support for DDL statements will be a feature of a future release of JDBC

D. DDL statements cannot be executed by making use of JDBC, you should use the native database tools for
this.

05_BTJB_Quiz5_Database Programming with Hibernate


Return to Assessment List
Part 1 of 1 - 87.5/ 100.0 Points

Question 1 of 20
5.0/ 5.0 Points
What is true for session.get() method?

A. Will return null if there is no data in db or cache.

B. None of the above

C. Will throw exception if there is no data in db or cache

D. May return a lazily initiliazed proxy

Question 2 of 20
5.0/ 5.0 Points
Which of the following is a tag NOT used in hibernate.cfg.xml ?

A. <mapping>

B. <hbm2ddl.auto>

C. <session-factory>

D. <property>

Question 3 of 20
5.0/ 5.0 Points
Using Criteria Query to

A. Update object

B. Query that are built up using lots of conditional logic, avoid messy string manipulation

C. Insert Object

D. Delete object

Question 4 of 20
5.0/ 5.0 Points
Load child object automatically when parent object is loaded?

A. lazy=yes

B. lazy=true

C. lazy=no

D. lazy=fasle

Question 5 of 20
5.0/ 5.0 Points
Which interface are not the core interfaces of Hibernate framework?

A. SessionFactory interface

B. Configuration interface

C. Session interface


D. User Interface

E. Query and Criteria interfaces

Question 6 of 20
5.0/ 5.0 Points
What does session.createCriteria().uniqueResult() return?

A. ResultSet

B. HibernateResultSet

C. Object

D. String

Question 7 of 20
5.0/ 5.0 Points
ORM stands for


A. Object Relational Matching

B. Over related Matching

C. Over related Mapping

D. Object Relational Mapping

Question 8 of 20
5.0/ 5.0 Points
An object emp can be saved to database using method save(emp) of following :

A. Configuration

B. Session

C. Transaction

D. SessionFactory
Question 9 of 20
5.0/ 5.0 Points
Which of the following is NOT a step in the Hibernate communication with RDBMS?

A. Execute query to get list containing Java objects

B. Create session from configuration object

C. Get one session from the session factory

D. Create HQL Query

E. Load the Hibernate configuration file and create configuration object

Question 10 of 20
5.0/ 5.0 Points
Which of following is NOT an annotation used with a class in hibernate?

A. @Entity

B. @Column

C. @Table

D. None of the above

Question 11 of 20
5.0/ 5.0 Points
Choose incorrect sentence

A. Transaction cannot rollback

B. Transaction is a set of database operations which must be executed in entirely or not at all

C. Transaction should and either with a commit or a rollback

D. All communication with a database has to occur inside a transaction


Question 12 of 20
5.0/ 5.0 Points
What are the main advantages of ORM like hibernate?

A. Mapping Java class to table

B. Support multi databases

C. Steep learning curve

D. Support for Query Language


Question 13 of 20
5.0/ 5.0 Points
hibernate.cfg.xml is used for

A. Building the mapping between class and table

B. No such file is required for hibernate

C. Contains the configuration like database details

D. Is a generated file at runtime

Question 14 of 20
5.0/ 5.0 Points
How can get a session object ?

A. SessionFactory.get();

B. SessionFactory.getSession();

C. SessionFactory.openSession();

D. SessionFactory.getObject();

Question 15 of 20
5.0/ 5.0 Points
If the property of a class should not take part in persistence mechanism than the property should be marked as

A. @Temporary

B. @Enum

C. @Transient


D. @Lob

Question 16 of 20
0.0/ 5.0 Points
"Is this configuration correct in hibernate?
<property name = ""abcd"" column=""abcd"" type=""string"" length= ""200"">
<property name = ""abcd"" column=""dcba"" type=""string"" length= ""500"">"

A. Yes

B. None of the above

C. No

Question 17 of 20
5.0/ 5.0 Points
How do you map Java Objects with Database table?

A. Both

B. XML mapping hbm.xml


C. Anotation

Question 18 of 20
2.5/ 5.0 Points
Which property are used to configure diver class in hibernate?

A. hibernate.connection.datasource

B. getParameterValues("name");

C. hibernate.connection.driver_class

D. getParameters("name");
Question 19 of 20
5.0/ 5.0 Points
Which of the following are most common configuration methods of Hibernate Configuation?

A. hibernate.cfg.xml

B. persistence.xml

C. http.conf

Question 20 of 20
0.0/ 5.0 Points
Hibernate Query Language
 A. Is native SQL

 B. Uses class name instead of table name, and property names instead of column name

 C. Is JPA Query language

 D. Is naming query language

05_BTJB_Quiz6_Logging & Automation Unit Test


Return to Assessment List

Part 1 of 2 - Part 1 70.0/ 70.0 Points

Question 1 of 20
5.0/ 5.0 Points
What part of log4J config file defines the level of log message

 A. message level
 B. log level
 C. log message level
 D. logger

Question 2 of 20
5.0/ 5.0 Points
Which of the following genres does Log4j produce?

 A. Gospel music
 B. Action game
 C. Avant-rock
 D. Logging Tool

Question 3 of 20
5.0/ 5.0 Points
The rolling output file type is an output file of which the content is

 A. replaced after a predefined period of time


 B. replaced at each running of the logged target
 C. put in a history file when the file size attends a predefined size

Question 4 of 20
5.0/ 5.0 Points
What is a log4j logger used for?

 A. To define which log message will be caught

 B. To logs a log message

 C. To receive the log message

Question 5 of 20
5.0/ 5.0 Points
Which is(are) the message level will be logged with the logger level "info"?

 A. info, error, fatal, warn


 B. info, trace, debug, warn
 C. info, debug, warn, fatal
 D. info, debug, warn

Question 6 of 20
5.0/ 5.0 Points
Which of the following platforms does Log4j run on?

 A. Debian
 B. Cross-platform
 C. Windows Server 2008

Question 7 of 20
5.0/ 5.0 Points
The most generic logger is

 A. ceil
 B. base
 C. root
 D. floor

Question 8 of 20
5.0/ 5.0 Points
What part of log4J config file defines the log message output

 A. appender
 B. log message file
 C. output file
 D. output

Question 9 of 20
5.0/ 5.0 Points
Which action is not a logging implement action?

 A. Define logger
 B. Define appender
 C. Define log schedule
 D. Define log message

Question 10 of 20
5.0/ 5.0 Points
What is a log4j logger?

 A. A configuration section
 B. A log output file
 C. Java class that logs a log message

Question 11 of 20
5.0/ 5.0 Points
Which is syntax used to log a message?

 A. logger.message(loglevel, "log message");


 B. logger.message("log message");
 C. message.log();
 D. logger.info("log message");

Question 12 of 20
5.0/ 5.0 Points
The logger declaration order is

 A. No order at all
 B. from most generic case to specific case
 C. from most specific case to generic case

Question 13 of 20
5.0/ 5.0 Points
Which config section define the format of log message?

 A. output section
 B. format section
 C. layout section
 D. display section

Question 14 of 20
5.0/ 5.0 Points
A logger cannot be defined for

 A. A method

 B. A package

 C. A class

 D. A project

Part 2 of 2 - Part 2 30.0/ 30.0 Points

Question 15 of 20
5.0/ 5.0 Points
How to pause the debugging at a statement in Eclipse debug function

 A. Use break point function

 B. Use pause statement function

 C. Use pause line function

Question 16 of 20
5.0/ 5.0 Points
How to run the debugging statement by statement with Eclipse debug function

 A. Use step over function

 B. Use step into function


 C. Use step return function

Question 17 of 20
5.0/ 5.0 Points
How to bypass a method in the debugging with Eclipse debug function

 A. Use step over function

 B. Use step return function

 C. Use step into function

Question 18 of 20
5.0/ 5.0 Points
How to ignore the rest of debugging with Eclipse debug function

 A. Use continue debugging function

 B. Use step return function

 C. Use stop debugging function

Question 19 of 20
5.0/ 5.0 Points
How to ignore the rest of debugging of a method with Eclipse debug function

 A. Use step over function

 B. Use step return function

 C. Use continue debugging function

Question 20 of 20
5.0/ 5.0 Points
How to ignore the debugging until the next check point with Eclipse debug function
 A. Use step return function

 B. Use continue debugging function

 C. Use step over function

You might also like