Uploaded by gaukmda12345

Java Web Development Test: Variant 1 & 2

advertisement
Java Web Development. Test, Variant 1, Variant 2
Summary
Java Fundamentals
easy – 4
medium – 1
hard –
OOP Concepts
easy – 3
medium –
hard –
Classes
easy –
medium – 2
hard – 2
Packages
easy – 1
medium – 1
hard –
Inheritance&Interfaces
easy – 1
medium –
hard – 2
Enums
easy –
medium – 2
hard –
Classes into Classes
easy –
medium – 2
hard –
Exceptions and Errors
JDBC
easy – 1
medium –
hard –
Java I/O
easy – 1
medium – 1
hard –
XML&XSD
easy – 2
medium – 1
hard – 1
Generics
easy – 1
medium – 1
hard – 1
Java EE Architecture
easy – 1
medium – 1
hard –
Collections
easy –
medium – 1
hard –
Servlets
easy –
medium – 1
hard – 1
Strings
easy –
medium – 2
hard –
Threads
easy –
medium – 2
hard –
Regular Expressions
easy – 1
medium –
hard – 1
easy – 2
medium – 2
hard –
JSPs
easy – 2
medium – 1
hard – 1
Total – 100 (50/50).
Variant 1
Variant 2
Java Fundamentals
What is the result of compiling and running the following code?
What is the result of compiling and running the following code?
public class PrimType1 {
public class PrimType2 {
static void test(float x) {
System.out.print("float");
}
static void test(float x) {
System.out.print("float");
}
static void test(double x) {
System.out.print("double");
}
static void test(double x) {
System.out.print("double");
}
public static void main(String[] args) {
test(99.9);
}
public static void main(String[] args) {
test((float)99.9);
}
easy
1
easy
2
3
}
}
_____
float
double
Compilation error
Exception is thrown at run time
In Java byte, short, int and long all of these are
______
float
double
Compilation error
Exception is thrown at run time
The code is given:
________
signed
unsigned
both of the above
none of these
double static = 2.5;
System.out.println(static);
easy
In Java arrays are
________
Objects
Object references
Primitive data type
None of the above
What will be result of compiling and running this code?
________
Console output 2.5
Raises an error as STATIC in used as a variable which is a keyword
Raises an exception
None of these
Which of the following is the return type of a constructor?
________
void
boolean
No return type
The code is given:
The code is given:
public class Zoo {
public class Zooo {
public static void main(String[] args) {
int x = 5;
Zoo z = new Zoo();
z.z(x);
System.out.print(" main x = " + x);
}
public static void main(String[] args) {
int x = 5;
Zooo z = new Zooo();
z.z(x);
System.out.print(" main x = " + x);
}
void z(int x) {
System.out.print("z x = " + x++);
}
void z(int x) {
System.out.print("z x = " + x--);
}
medium
4
easy
5
}
}
What is the result? (1 answer)
What is the result? (1 answer)
________
Compilation fails;
An exception is thrown at runtime;
z x = 6 main x = 6;
z x = 5 main x = 5;
z x = 5 main x = 6;
z x = 6 main x = 5;
According to JavaBean naming standards, which of the following is
correct to getting id?
________
Compilation fails;
An exception is thrown at runtime;
z x = 6 main x = 6;
z x = 5 main x = 5;
z x = 5 main x = 6;
z x = 6 main x = 5;
According to JavaBean naming standards, which of the following is correct to
setting id?
________
public int get_Id(){}
public int getid(){}
public int getId(){}
public int getId(int id){}
________
public void set_Id(int id){}
public void setid(int id){}
public void setId(int id){}
public void setID(int id){}
OOP Concepts
6
easy
If X has a subclass Y, which relationship exists among them?
easy
7
easy
8
________
IS-A
HAS-A
None of the above
The following code illustrates what kind of relationship between the X and Y
classes?
class X{}
class Y{
X s;
}
A non-static method in the superclass cannot be overridden to be static in
the subclass.
________
IS-A
HAS-A
None of these
A non-static method in the superclass can be overridden to be static in the
subclass.
________
True
False
Object is
________
True
False
Which of the following statements are true for inherited classes?
________
A scheme for organizing related pieces of information.
Named entity that includes both data and functions.
A section of a program that performs a particular task.
Allocated memory space accessed by reference.
________
Can have the same name as super class.
Will have all methods that super class has.
Can have own fields and methods rather that super class.
Classes
Which of the following statements about the implementation of the equals() method of
Object class as shown in the following code is true?
public class Hash1 {
private int number;
public class Eq1 {
private int number;
public Hash1(int i) {
number = i;
}
public Eq1(){}
10
public boolean equals(Eq1 obj){
if (number == obj.number){
return true;
}
return false;
}
// other methods
public int hashCode() {
int i = (int) (Math.random() * 100);
return i * number;
}
// other methods
medium
9
Which of the following statements about the implementation of the hashCode()
method of Object class as shown in the following code is true?
}
}
________
The code implements hashCode() method correctly.
The code does not implement hashCode() method correctly.
This implementation of hashCode() method is correct if only if the equals()
method is not overridden.
The given code does not contain enough information to comment on the
correctness of the hashCode() method implementation.
None of these.
________
The code implements equals() method correctly.
The code does not implement equals() method correctly.
This implementation of equals() method is correct if only if the hashCode() method is
not overridden.
The given code does not contain enough information to comment on the correctness of
the equals() method implementation.
None of these.
Given:
The code is given:
public class St2 {
public class St1 {
int[] a;
static int[] a;
{
hard
static {
a[0] = 2;
}
public static void main(String[] args) {
a[0] = 2;
}
public static void main(String[] args) {
new St1();
}
}
}
}
Which exception or error will be thrown when a programmer attempts to
run this code? (1 answer)
Which exception or error will be thrown when a programmer attempts to run
this code? (1 answer)
________
java.lang.StackOverflowError
java.lang.IllegalStateException
java.lang.ExceptionInInitializerError
java.lang.ArrayIndexOutOfBoundsException
None of the above
________
java.lang.StackOverflowError
java.lang.IllegalStateException
java.lang.ExceptionInInitializerError
java.lang.ArrayIndexOutOfBoundsException
None of the above
The code is given:
The code is given:
public class VarArg2 {
public String var(int[] vals) {
return "a";
}
public class VarArg1 {
public String var(int x, int y) {
return "a";
}
public String var(int... vals) {
return "b";
}
public String var(int... vals) {
return "b";
}
public static void main(String[] args) {
VarArg2 v = new VarArg2();
System.out.println(v.var(4, 5));//line 1
}
public static void main(String[] args) {
VarArg1 v = new VarArg1();
System.out.println(v.var(4, 5));//line 1
}
medium
11
}
What will be result of compiling and running?
What will be result of compiling and running?
________
Line 1 prints “a” to System.out;
Line 1 prints “b” to System.out;
An exception is thrown at line 1 at runtime;
Compilation of class VarArg2 will fail
The code is given:
________
Line 1 prints “a” to System.out;
Line 1 prints “b” to System.out;
An exception is thrown at line 1 at runtime;
Compilation of class VarArg1 will fail
The code is given:
public class GenOver1 {
public class GenOver2 {
public static void main(String[] args){
Object[] obj = {"one", "two", "three"};
GenOver1 gen = new GenOver1();
gen.f(obj);
//line 1
}
public static void main(String[] args){
Object[] obj = {new Integer(1), new Integer(2), new Integer(3)};
GenOver2 gen = new GenOver2();
gen.f(obj);
}
public void f(Object obj){}//method1
public void f(String str){}//method2
public void f(String ... str){}//method3
public static void f(Object ... str){}//method4
public static void f(Object[] ... str){}//method5
public static void f(String[] ... str){}//method6
public static void f(Object ... str){}//method1
public static void f(Object[] ... str){}//method2
public static void f(Integer[] ... str){ }//method3
public void f(Object obj){ }//method4
public void f(Integer str){ }//method5
public void f(Integer ... str){ }//method6
hard
12
}
}
}
What method will be chosen in line 1 for running?
What method will be chosen in line 1 for running?
________
method1
method2
method3
method4
method5
method6
________
method1
method2
method3
method4
method5
method6
Packages
13
easy
The code is given:
//line 1
public class QP1 {
public static void main(String[] args) {
println("Java forever");
}
}
medium
14
Which operator can be inserted (line 1) separately and code will be
compile? (1 answer)
________
import java.lang.*;
import java.lang.System;
import static java.lang.System.out;
import static java.lang.System.out.println;
None of the above is correct.
Given the program defined in three different files with two classes and an
interface: (1 answer)
package app;
public interface IApp {
void meth();
}
package app;
public class App implements IApp {
void meth() {
System.out.println("Java");
}
}
package app.start;
import app.App;
import app.IApp;
public class Start {
public static void main(String[] args) {
IApp a = new App();
a.meth();
}
}
What will be the result of compiling and running?
________
Line “Java” in console
Compile warning in interface IApp
Compile warning in class App
Compile error in interface IApp
Compile error in class App
The code is given:
public class QP2 {
public static void main(String[] args) {
out.println(sqrt(4));
}
}
Which statements do you need to include in program to compile and run
without exceptions? (2 answers)
________
import java.lang.*;
import java.lang.Math;
import static java.lang.Math.sqrt;
import static java.lang.System.out;
import static java.lang.System.out.println;
Given the program defined in three different files with two classes and an
interface: (2 answers)
package prog;
public interface IProg {
abstract void meth();
}
package prog;
public class Prog implements IProg{
void meth(){
System.out.println("Java");
}
}
package prog.start;
import prog.IProg;
import prog.Prog;
public class Start {
public static void main(String[] args) {
IProg prog = new Prog();
prog.meth();
}
}
What will be the result of compiling and running?
________
Line “Java” in console
Compile warning in interface IProg
Compile warning in class Prog
Compile error in interface IProg
Compile error in class Prog
Inheritance&Interfaces
easy
15
hard
16
The code is given: (1 answer)
The code is given: (1 answer)
class InhBase{
InhBase(){
System.out.print("InhBase");
}
}
class InhBase{
InhBase(){
System.out.print("InhBase");
}
}
public class Inh1 extends InhBase{
public static void main(String[] args){
new InhBase();
new Inh1();
}
}
public class Inh2 extends InhBase {
public static void main(String[] args) {
new InhBase();
new InhBase();
}
}
What is the result?
________
InhBase
InhBaseInhBase
Compilation fails
The code runs with no output
An exception is thrown at runtime
The code is given:
What is the result?
________
InhBase
InhBaseInhBase
Compilation fails
The code runs with no output
An exception is thrown at runtime
The code is given:
public interface ISome {
int mSome();
}
public class Base1 {
public int mSome() { return 1; }
}
public abstract class A extends Base1 implements ISome{
public abstract int mSome();
}
public interface ISome {
int mSome();
}
public class Base2 implements ISome{
public int mSome() { return 1;}
}
What will be result of compiling this code?
________
Compile will finish without any warnings or errors
There will be compiled error in the class A
There will be compiled error in the class Base1
There will be compiled errors in the class A and the class Base1
What will be result of compiling this code?
________
Compile will finish without any warnings or errors
There will be compiled error in the class B
There will be compiled error in the class Base2
There will be compiled errors in the class B and the class Base2
public abstract class B extends Base1 {
public abstract int mSome();
}
17
What will be result of compiling and running this code?
What will be result of compiling and running this code?
public class OverOver1 {
static A f(A a) { return a;}
static B f(B b) { return b;}
public class OverOver2 {
static A f(A a) {
return a;
};
public static void main(String[] args) {
A a = f(new A());
B b = f(new B());
a.f(b);
a = b;
a.f(a);
}
hard
}
class A {
void f(B b) { System.out.print("B");}
void f(A a) { System.out.print("BA");}
};
class B extends A {
void f(B b) { System.out.print("AB");}
void f(A a) { System.out.print("A");}
};
________
AA
BB
BA
compile error
runtime error
static B f(B b) {
return b;
};
public static void main(String[] args) {
A a = f(new A());
B b = f(new B());
b.f(b);
b = (B) a;
b.f(a);
}
}
class A {
void f(B b) { System.out.print("B");}
void f(A a) { System.out.print("BA");}
};
class B extends A {
void f(B b) { System.out.print("AB");}
void f(A a) { System.out.print("A");}
};
________
AA
BB
BA
compile error
runtime error
Enums
Select all the incorrect statements regarding Enums (Select any 2 options)
________
All enums are subclasses of interface java.lang.Enum.
Enums is simply a data structure and hence it is not compiled to a .class file.
Enums enable you to define a new data type. For example, If you create an
Enum 'Days' you can declare a variable of type 'Days'.
All instances of Enums are serializable by default.
19
________
All enums are subclasses of interface java.lang.Enum.
Enums is simply a data structure and hence it is not compiled to a .class
file.
Enums enable you to define a new data type. For example, If you create
an Enum 'Days' you can declare a variable of type 'Days'.
All instances of Enums are serializable by default.
What is the output of the following code:
public enum IceCream {
VANILLA("white"), STRAWBERRY("pink"), WALNUT("brown"),
CHOCOLATE("dark brown");
public enum Day {
MONDAY, WEDNESDAY
{//line 3
public String toString() {
return "Good";
}
},
THURSDAY, FRIDAY, SATURDAY, SUNDAY;
medium
18
Select all the correct statements regarding Enums (Select any 2 options)
String color;
IceCream(String color) {
this.color = color;
}
What is the output of the following code:
medium
Day() { }
public static void main(String[] args) {
System.out.println(VANILLA);// line 14
System.out.println(CHOCOLATE);// line 15
}
public static void main(String[] args) {
System.out.println(MONDAY);// line 14
System.out.println(WEDNESDAY);//line 15
}
}
}
________
Compilation error : Cannot run an enum as a standalone application.
Compilation error at line no 14 & 15 : cannot access VANILLA and
CHOLOCLATE in 'static' main method.
No errors. Output:
VANILLA
CHOCOLATE
No errors. Output:
white
dark brown
________
Compilation error at line number 3 : Invalid code.
Compilation error at line no 14 & 15 : cannot access MONDAY and
WEDESDAY in 'static' main method.
Runtime error : Cannot execute enum 'Day' as a standalone application.
Executes OK giving OUTPUT:
MONDAY
WEDNESDAY
Executes OK giving OUTPUT:
MONDAY
Good
Classes into classes
medium
20
medium
21
The inner class is given:
The nested class is given:
public class OuterX {
public class InnerX{}
}
public class OuterY {
public static class NestedY{}
}
How to create an instance of this class out of the OuterX class?
How to create an instance of this class out of the OuterY class?
________
new OuterX.InnerX();
new OuterX().InnerX;
new OuterX().new InnerX();
new OuterX().InnerX();
OuterX().new InnerX();
The two fragments of code are given:
1)
new Object() {
public void meth() { System.out.print("Hello!"); }
}.meth();
________
new OuterY.NestedY();
new OuterY().new NestedY();
new OuterY.NestedY();
new OuterY().NestedY;
OuterY().new NestedY();
The two fragments of code are given
1)
Anonym2 obj = new Anonym2() { public void meth() {
System.out.print("Hello!"); }
};
obj.meth();
2)
Object obj = new Object() { public void meth() {
System.out.print("Hello!"); }
};
obj.meth();
2)
new Anonym2() {
public void meth() { System.out.print("Hello!"); }
}.meth();
What will be the result of compiling and running?
What will be the result of compiling and running?
_______
First and second fragments will be compiled without errors and the string
“Hello!” will print.
First fragment will be compiled without errors and the string “Hello!”
will print. Second fragment will be compiled with errors.
Second fragment will be compiled without errors and the string “Hello!”
will print. First fragment will be compiled with errors.
First and second fragments will be compiled with errors.
________
First and second fragments will be compiled without errors and the string
“Hello!” will print.
First fragment will be compiled without errors and the string “Hello!” will
print. Second fragment will be compiled with errors.
Second fragment will be compiled without errors and the string “Hello!” will
print. First fragment will be compiled with errors.
First and second fragments will be compiled with errors.
Exceptions and Errors
22
easy
The code is given:
public class Exc1 {
public static void main(String [] args) {
try{
badMethod();
System.out.print("A");
}catch(Exception e){
System.out.print("B");
}finally{
System.out.print("C");
}
System.out.print("D");
}
The code is given:
public class Exc2 {
public static void main(String [] args) {
try{
badMethod();
System.out.print("A");
}catch(Exception e){
System.out.print("B");
}finally{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod(){
throw new RuntimeException();
}
public static void badMethod() {
throw new ArrayIndexOutOfBoundsException();
}
}
}
What will be result of compiling and running? (1 answer)
________
AC
BD
ACD
ABCD
Compilation fails
No correct answer
What will be result of compiling and running? (1 answer)
________
AC
BD
ACD
ABCD
Compilation fails
No correct answer
Java I/O
Which of these are valid parameter types for the write() methods of Which of these are valid parameter types for the write() methods of the
the Writer class? (3 answers)
OutputStream class? (2 answers)
easy
23
medium
24
________
String
char
char[]
int
________
String
byte
byte[]
int
Which code, when inserted at line 1, will result in the program compiling
and running without errors?
Which code, when inserted at line 1, will result in the program compiling and
running without errors?
public class IO1 {
public static void main(String[] args) throws IOException {
String fileName = "greetings.txt";
// (1) insert code here
public class IO2 {
public static void main(String[] args) throws IOException {
String fileName = "greetings.txt";
// (1) inser code here
writeGreetings(stream);
stream.close();
writeGreetings(stream);
stream.close();
}
}
private static void writeGreetings(Writer writer) throws IOException {
BufferedWriter bw = new BufferedWriter(writer);
}
private static void writeGreetings(OutputStream stream) throws
IOException {
BufferedOutputStream bw = new BufferedOutputStream(stream);
}
}
}
________
FileOutputStream fos = new FileOutputStream(fileName);
OutputStreamWriter stream = new OutputStreamWriter(fos);
FileOutputStream fos = new FileOutputStream(fileName);
InputStreamWriter stream = new InputStreamWriter(fos);
________
FileOutputStream stream = new FileOutputStream(fileName);
FileOutputStream fos = new FileOutputStream(fileName);
InputStreamWriter stream = new InputStreamWriter(fos);
FileOutputStream stream = new FileOutputStream(fileName);
FileOutputStream stream = new FileOutputStream(fileName);
PrintWriter stream = new PrintWriter(fileName);
PrintWriter stream = new PrintWriter(fileName);
FileWriter stream = new FileWriter(fileName);
easy
25
FileWriter stream = new FileWriter(fileName);
How many methods are defined in the Serializable interface?
Which interface is used to declare objects serializable?
________
None
One
Two
Three
None of the above.
________
Clonable
Serializator
Serializable
Serialisable
None of the above
The code is given:
The code is given:
class A {
public int a = 0;
class A {
public int a = 0;
public A() {
a = 1;
}
public A(int _a) {
a = _a;
}
}
}
class B extends A implements Serializable {
public int b = 0;
class B extends A implements Serializable {
public int b = 0;
public B() {
a = 2;
b = 3;
}
public B() {
super(2);
b = 3;
}
hard
26
}
An object of the class B was created and serialized. Which values will
take variables after deserialization of the object?
_______
field a=1, field b=3
field a=2, field b=3
field a=0, field b=0
field a=0, field b=3
field a=1, field b=0
Deserialization is impossible, the class A doesn’t implement interface
Serializable
None of the above
}
An object of the class B was created and serialized. Which values will take
variables after deserialization of the object?
________
field a=1, field b=3
field a=2, field b=3
field a=0, field b=0
field a=0, field b=3
field a=1, field b=0
Deserialization is impossible, the class A doesn’t implement interface
Serializable
None of the above
Generics
medium
27
esay
28
The classes hierarchy is given:
The classes hierarchy is given:
class MedicalStaff{}
class Doctor extends MedicalStaff{}
class Nurse extends MedicalStaff{}
class HeadDoctor extends Doctor{}
class MedicalStaff{}
class Doctor extends MedicalStaff{}
class Nurse extends MedicalStaff{}
class HeadDoctor extends Doctor{}
Choose the operators which will be compiled without errors
Choose the operators which will be compiled without errors
________
List<Doctor> list1= new ArrayList<Doctor>();
List<MedicalStaff> list2 = new ArrayList<Doctor>();
List<Doctor> list3 = new ArrayList<MedicalStaff>();
List<Object> list4 = new ArrayList<Doctor>();
List<Object> list5 = new ArrayList<Object>();
________
Set<Doctor> list1= new HashSet<Doctor>();
Set<MedicalStaff> list2 = new HashSet<Doctor>();
Set<Doctor> list3 = new HashSet<MedicalStaff>();
Set<Object> list4 = new HashSet<Doctor>();
Set<Object> list5 = new HashSet<Object>();
The class is given
public class X <T> {
T t;
}
The class is given
public class X <T> {
T t;
}
Which types can you choose to create an object of this class?
Which operators will be compiled without errors?
________
Object
Integer
Number
Comparator
int
double
char
________
new X<Object>();
new X<Integer>();
new X<Number>();
new X<Comparator>();
new X<double>();
new X<char>();
new X<int>();
Collections
What will be the result of compiling and running the following code? (1 answer)
30
ArrayList<String> ar = new ArrayList<String>();
ar.add("one");
ar.add("two");
List<Object> list = ar;
System.out.println(list);
________
Compiler error
Throws ClassCastException in runtime
Prints [one, two]
Prints [two, one]
The class is given:
TreeSet<String> ar = new TreeSet<String>();
ar.add("one");
ar.add("two");
Set<Object> set = ar;
System.out.println(set);
________
Compiler error
Throws ClassCastException in runtime
Prints [one, two]
Prints [two, one]
The class is given:
class Item {
private int x;
public Item(int x) { setX(x); }
public int getX() { return x; }
public void setX(int x) { this.x = x; }
public String toString() { return x + ""; }
}
class Item {
private int x;
public Item(int x) { setX(x); }
public int getX() { return x; }
public void setX(int x) { this.x = x; }
public String toString() { return x + ""; }
}
What will be the result of compiling and running the following code? (1 answer)
Item item1 = new Item(1); Item item2 = new Item(2);
Item item3 = new Item(3);
What will be the result of compiling and running the following code? (1 answer)
Item item1 = new Item(1); Item item2 = new Item(2);
Item item3 = new Item(3);
Map<String, Item> map = new HashMap<String, Item>();
Map<String, Item> map = new HashMap<String, Item>();
map.put("one", item1); map.put("two", item2);
map.put("three", item3);
map.put("one", item1); map.put("two", item2);
map.put("three", item3);
Set<Map.Entry<String, Item>> set = map.entrySet();// line 1
Object[] arrayMapEntry = new Object[set.size()];
for (Map.Entry<String, Item> mapEntry : map.entrySet()) {// line 1
if ("two".equals(mapEntry.getKey())) {
mapEntry.setValue(new Item(4)); // line 2
break;
}
}
System.out.println(map);
________
Compile error in line 1
Compile error in line 2
Prints {two=4, one=1, three=3}
Prints {two=2, one=1, three=3}
Runtime error in line 1
Runtime error in line 2
hard
medium
29
What will be the result of compiling and running the following code? (1 answer)
arrayMapEntry = set.toArray(arrayMapEntry);
((Map.Entry<String, Item>)arrayMapEntry[0])
.setValue(new Item(4)); // line 2
System.out.println(map);
________
Compile error in line 1
Compile error in line 2
Prints {two=4, one=1, three=3}
Prints {two=2, one=1, three=3}
Runtime error in line 1
Runtime error in line 2
Strings
medium
31
medium
32
The code is given:
The code is given:
String str1 = "Java";
String str2 = new String("Java");
String str1 = new String ("Java");
String str2 = new String("Java");
if (str1.equals(str2.intern())){ System.out.print("true"); }
else {System.out.print( "false"); }
if (str1.intern().equals(str2.intern())){ System.out.print("true"); }
else{ System.out.print("false"); }
if(str1==str2){ System.out.print("true"); }
else{ System.out.print("false"); }
if(str1==str2){ System.out.print("true"); }
else{ System.out.print("false"); }
What will be result of compiling and running? (1 answer)
________
Console out “truefalse”
Console out “truetrue”
Console out “falsefalse”
Console out “falsetrue”
Compile error, given incorrect parameter for method equals()
The code is given:
What will be result of compiling and running? (1 answer)
________
Console out “truefalse”
Console out “truetrue”
Console out “falsefalse”
Console out “falsetrue”
Compile error, given incorrect parameter for method equals()
The code is given:
StringBuilder sb1 = new StringBuilder("Java");
StringBuffer sb2 = new StringBuffer("Java");
StringBuffer sb1 = new StringBuffer("Java");
StringBuilder sb2 = new StringBuilder("Java");
if (sb1.equals(sb2)){ // line 1
System.out.println("A");
}else{
System.out.println("B");
}
if (sb1.equals(sb2)){
System.out.println("A");
}else{
System.out.println("B");
}
What will be result of compiling and running? (1 answer)
________
Console out “A”
Console out “B”
Compile error in line 1, object with type StringBuffer cann’t be a
parameter of method equals()
Rintime error in line 1, it is impossible to cast SringBuffer type to
StringBuilder type.
What will be result of compiling and running? (1 answer)
________
Console out “A”
Console out “B”
Compile error in line 1, object with type StringBuffer cann’t be a parameter of
method equals()
Rintime error in line 1, it is impossible to cast SringBuffer type to
StringBuilder type.
Threads
33
Which one statement is always true about the following application? (1 answer)
public class Thr1 extends Thread {
Thr1(){
setPriority(10);
}
Which one statement is always true about the following application? (1 answer)
public class Thr2 implements Runnable{
Thr2(){
}
public void run(){
System.out.println("Thread was started");
while(true){}
}
public void run(){
System.out.println("Thread was started");
while(true){}
}
public static void main(String[] args){
Thread th1 = new Thread(new Thr2());
Thread th2 = new Thread(new Thr2());
Thread th3 = new Thread(new Thr2());
th1.setPriority(10);
th2.setPriority(10);
th2.setPriority(10);
th1.start();
th2.start();
th3.start();
}
medium
public static void main(String[] args){
Thr1 th1 = new Thr1();
Thr1 th2 = new Thr1();
Thr1 th3 = new Thr1();
th1.start();
th2.start();
th3.start();
}
}
}
What class do you may use instead straight locking for increasing count?
What class do you may use instead straight locking for increasing count?
public class Concur1 {
public static int count;
private static Lock lock = new ReentrantLock();
public class Concur2 {
public static long count;
private static Lock lock = new ReentrantLock();
public void run() {
for (int i = 0; i < 10000000; i++) {
lock.lock();
count++;
lock.unlock();
}
System.out.println(count);
}
public void run() {
for (int i = 0; i < 10000000; i++) {
lock.lock();
count++;
lock.unlock();
}
System.out.println(count);
}
medium
34
________
When the application is run, thread th1 will be executed; threads th2 and th3 will
be never got the CPU.
When the application is run, thread th1 will be executed to completion, thread th2
will be executed to completion, then thread th3 will be executed to completion.
When the application is run, all three threads (th1, th2, and th3) will br executed
concurrently, taking time-sliced turns in the CPU.
None of the above scenarios can be guaranteed to happen in all cases.
________
When the application is run, thread th1 will be executed; threads th2 and th3 will be
never got the CPU.
When the application is run, thread th1 will be executed to completion, thread th2 will
be executed to completion, then thread th3 will be executed to completion.
When the application is run, all three threads (th1, th2, and th3) will be executed
concurrently, taking time-sliced turns in the CPU.
None of the above scenarios can be guaranteed to happen in all cases.
}
}
________
AtomicInteger
AtomicIntegerFieldUpdater
AtomicIntegerArray
It is impossible to block the increase operator without lock operator.
________
AtomicLong
AtomicLongFieldUpdater
AtomicLongArray
It is impossible to block the increase operator without lock operator.
Regular Expressions
Select a predefined class meta-characters which is similar to the
Select a predefined class meta-characters which is similar to the class
class [^0-9]
[a-zA-Z_0-9]
easy
35
36
________
\d
\i
\D
\s
None
________
\W
\I
\b
\s
\w
The code is given:
The code is given:
String reg1 = "^a|b|c$";
String reg2 = "(^a)|b|(c$)";
String text = "textc";
hard
String reg1 = "^a|b|c$";
String reg2 = "^(a|b|c)$";
String text = "textc";
System.out.print(Pattern.compile(reg1).matcher(text).find());
System.out.print(Pattern.compile(reg2).matcher(text).find());
System.out.println(Pattern.compile(reg1).matcher(text).find());
System.out.println(Pattern.compile(reg2).matcher(text).find());
What will be result of compiling and running?
What will be result of compiling and running?
________
truefalse
falsetrue
truetrue
falsefalse
________
truefalse
falsetrue
truetrue
falsefalse
JDBC
easy
37
medium
38
Which type of Statement can execute parameterized queries? (1 answer)
________
PreparedStatement
ParameterizedStatement
ParameterizedStatement and CallableStatement
All kinds of Statements (i.e. which implements a sub interface Statement)
Which packages contain the JDBC classes? (1 answer)
________
java.jdbc and javax.jdbc
java.jdbc and java.jdbc.sql
java.sql and javax.sql
java.rdb and javax.rdb
What is, in terms of JDBC, a DataSource? (1 answer)
________
A DataSource is the basic service for managing a set of JDBC drivers.
A DataSource is the Java representation of a physical data source
A DataSource is a registry point for JNDI-services.
A DataSource is a factory of connections to a physical data source.
Which Statements about JDBC are true? (2 answers)
________
JDBC is an API to connect to relational-, object-, and XML data sources
JDBC stands for Java DataBase Connectivity
JDBC is an API to access relational databases, spreadsheets and flat files.
JDBC as an API to bridge the object-relational mismatch between OO
programs and relational databases.
XML & XSD
39
easy
Which xml elements are correct? (2 answers)
hard
40
_______
<Calc>1 > 2</Calc>
<Calc>2 < 3</Calc>
<Calc>2 > 3</Calc>
<Calc><!CDATA[ 1 > 2 ]>
Which attribute for the root element xs:schema is necessary if you want to
place the elements in a namespace ?
Given the following xml document.
_________
elementFormDefault
targetNamespace
defaultNamespace
attributeFormDefault
Given the following xml document.
<name>
<firstname>John</firstname><lastname>Lennon</lastname>
</name>
<name>
<firstname>John</firstname><lastname>Lennon</lastname>
</name>
What is a correct schema structure for it?
What is a correct schema structure for it?
A)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="name">
<xs:complexType>
<xs:sequence>
<xs:element ref="FirstName"/>
<xs:element ref="LastName"/>
</xs:sequence>
</xs:cоmplexType>
</xs:element>
</xs:schema>
A)
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:element name="name">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="lastname" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
B)
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:element name="name">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="lastname" type="xsd:string"/>
</xsd:sequence>
</xsd:cоmpleхType>
</xsd:element>
</xsd:schema>
______
A
B
B)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="firstname" type="xs:String"/>
<xs:element name="lastname" type="xs:String"/>
<xs:element name="name" type="nametype"/>
<xs:complexType type="nametype">
<xs:sequence>
<xs:element ref="firstname"/>
<xs:element ref="lastname"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
________
A
B
medium
41
Choose the statements that are correct for DOM Parsers.
Choose the statements that are correct for SAX Parsers.
________
Parses entire document
Represents result as a tree
Lets you search tree
Lets you modify tree
Good for reading data/configuration files
Parses until you tell it to stop
Fires event handlers for each: start tag, tag body, end tag
Low level APIs
Good for very large documents, especially if you only care about very
small portions of the document.
________
Parses entire document
Represents result as a tree
Lets you search tree
Lets you modify tree
Good for reading data/configuration files
Parses until you tell it to stop
Fires event handlers for each: start tag, tag body, end tag
Low level APIs
Good for very large documents, especially if you only care about very small
portions of the document.
Java EE Architecture
medium
42
Java EE, the Java Enterprise Edition, is (1 answer)
________
An improved version of the Java Standard Edition for business
professionals
A development environment, designed for creating enterprise applications
A platform for enterprise class level, distributed applications
A replacement of the Java Virtual Machine for running internet
applications
Which elements are not part of the Java EE specification (2 answers)
_________
applets
Java Mail
portlets
Unified Expression Language
Servlets
easy
43
medium
44
easy
45
medium
46
Put the JSP’s lifecycle in the correct order
Put the servlet’s lifecycle in the correct order
a) loaded into memory
b) translation
c) call service ()
d) compilation
e) initialization
f) creating an object
g) destruction
a) initialization
b) loaded into memory
c) translation
d) call service ()
e) creating an object
f) destruction
g) compilation
________
bdafecg
abdfecg
abdefcg
dbafecg
The tasks – authentication-blocking of requests, data compression,
logging and auditing – are performed by:
________
cgbeadf
gcbeadf
beadf
gbeadf
The init parameter name and value pairs that are defined in web.xml file are
handled by:
________
server filter
server container
servlet config
servlet context
Servlet technology is used to create web application.
________
ServletConfig object
ServletRequest object
ServletResponse object
ServletContext object
In HTTP Request method Get request is secured because data is exposed in
URL bar?
________
false
true
The getSession() method with ‘true’ as its parameter [getSession(true)] it
will return the appropriate session object when:
________
false
true
An attribute in servlet is an object that can be set, get or removed from one of
the following scopes?
________
the session is completed
the session object is passed to another method
the session is existing
the session does not exists
________
request scope
application scope
session scope
all
JSPs
47
easy
In JSP Action tags which tags are used for bean development?
48
________
All
jsp:useBean
jsp:getProperty
jsp:setProperty
hard
In JSP how many ways are there to perform exception handling?
49
__________
2
5
3
4
medium
In which technology, we mix our business logic with the presentation
logic?
easy
50
__________
JSP
Servlet
None
JSP and Servlet
The JSP include directive is used to include the contents of any resource
it may be?
________
All
Text file
Html file
Jsp file
In JSP page directive which attribute defines the MIME type of the HTTP
response?
________
Extends
ContentType
Import
Info
In which attribute specifies a JSP page that should process any exceptions
thrown but not caught in the current page?
__________
The isErrorPage
None
The ErrorPage Attribute
The isErrorPage Attribute and the ErrorPage Attribute
In JSP action tags Which are used for developing web application with Java
Bean?
_____________
jsp:setProperty and jsp:getProperty
jsp:setProperty
jsp:getProperty
jsp:useBean
A JSP page consists of which tags?
________
HTML tags
JSP tags
HTML tags and JSP tags
None
Download