1 How
to invoke constructor in Servlets.
Using servlet Container
By Init() method
Can’t invoke
None of the above.
2 Which
method retrieves the body of the request as binary data.
None of the above
request.getInputStream()
response.getInputStream()
New InputStream()
3What
is the output of below program?
public class StringDemo {
public static void main(String args[]){
// The line below this gives an output
// \u000d System.out.println("comment executed");
}
}
public class StringDemo {
public static void main(String args[]){
// The line below this gives an output
// \u000d System.out.println("comment executed");
}
}
Compile Exception
comment executed
Empty
The line below this gives an output
4What
is the result of this program.
public class Demo {
public static void main(String args[]){
System.out.println(3*0.1 == 0.3);
}
}
public class Demo {
public static void main(String args[]){
System.out.println(3*0.1 == 0.3);
}
}
True
False
Compile time error
Runtime error
5Output
for below program
class A {
static int i = 1111;
static
{
i = i-- - --i;
}
{
i = i++ + ++i;
}
}
class B extends A
{
static
{
i = --i - i--;
}
{
i = ++i + i++;
}
}
class Demo
{
public static void main(String[] args)
{
B b = new B();
System.out.println(b.i);
}
}
class A {
static int i = 1111;
static
{
i = i-- - --i;
}
{
i = i++ + ++i;
}
}
class B extends A
{
static
{
i = --i - i--;
}
{
i = ++i + i++;
}
}
class Demo
{
public static void main(String[] args)
{
B b = new B();
System.out.println(b.i);
}
}
0
9
6
15
6What
is the output of below code
try {
File file = new File("path");
FileInputStream fis = new FileInputStream(file);
String s = "inside";
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println(s);
}
try {
File file = new File("path");
FileInputStream fis = new FileInputStream(file);
String s = "inside";
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println(s);
}
Inside
Path
File not found exception
Compilation error
7What
exception will be thrown by Double.parseDouble(null)
NumberFormatException
NullPointerException
ArithmeticException
DivisionByZero
8Select
a commonly used runtime exception
NumberFormatException
NullPointerException
ArrayIndexOutOfBoundException
FileNotFoundException
9The
regular expressions \d mean
Range of digits (0-9)
Range of digits (1-9)
A single digit
A Non digit
10Way
to split string by new lines without empty lines is
String.split("\\r?\\n")
String.split("[\\r\\n]+")
String.split("[\\r\\n] ")
String.split(System.getProperty("line.separator"))
11Which
of the below statement is true about LinkedList
to access an element in the middle, it has to search from the
beginning of the list
Its elements can be accessed directly by index
adding or removing an element needs to move existing elements
None of the above
12What
is the output of below code
String str = "abcd";
String repeated = StringUtils.repeat(str,3);
String str = "abcd";
String repeated = StringUtils.repeat(str,3);
abcdabcdabcd
abcdabcdabcdabcd
abcd
abc
13What
is the output of below code
String str = "Sep 17, 2013";
Date date = new SimpleDateFormat("MMMM d, yy", Locale.ENGLISH).parse(str);
System.out.println(date);
String str = "Sep 17, 2013";
Date date = new SimpleDateFormat("MMMM d, yy", Locale.ENGLISH).parse(str);
System.out.println(date);
Tue Sep 17, 13
Tue Sep 17, 2013
September 17 00:00:00 EDT 2013
Tue Sep 17 00:00:00 EDT 2013
14Predict
the output of following Java program?
class Test {
int i;
}
class Main {
public static void main(String args[]) {
Test t;
System.out.println(t.i);
}
class Test {
int i;
}
class Main {
public static void main(String args[]) {
Test t;
System.out.println(t.i);
}
Runtime error
Compile error
Garbage value
0
15What
is the output of the following program ?
Class Test {
public static void main(String[] args) {
Test obj = new Test();
obj.start();
}
void start() {
String stra = ”do”;
String strb = method(stra);
System.out.print(“: ”+stra + strb);
}
String method(String stra) {
stra = stra + ”good”;
System.out.print(stra);
return“ good”;
}
}
Class Test {
public static void main(String[] args) {
Test obj = new Test();
obj.start();
}
void start() {
String stra = ”do”;
String strb = method(stra);
System.out.print(“: ”+stra + strb);
}
String method(String stra) {
stra = stra + ”good”;
System.out.print(stra);
return“ good”;
}
}
dogood : dogood
dogood : dodogood
dogood : gooddogood
dogood : dogoodgood
16When
we implement an interface method, it must be declared as:
Friend
Public
Protected
Private
17Output
of following Java program?
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun()
{
return 20;
}
}
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun()
{
return 20;
}
}
Garbage value
0
Compile error
20
18What
is the output of below code
class Test {
public static void swap(Integer i, Integer j) {
Integer temp = new Integer(i);
i = j;
j = temp;
}
public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println("i = " + i + ", j = " + j);
}
}
class Test {
public static void swap(Integer i, Integer j) {
Integer temp = new Integer(i);
i = j;
j = temp;
}
public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println("i = " + i + ", j = " + j);
}
}
i = 10, j = 20
i = 20, j = 10
i = 20, j = 20
i = 10, j = 10
19Predict
the output
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
static int fun(int x = 0)
{
return x;
}
}
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
static int fun(int x = 0)
{
return x;
}
}
0
Garbage value
Compile error
Runtime error
20Predict
the output of the following program.
class Test
{
public static void main(String[] args)
{
StringBuffer a = new StringBuffer("geeks");
StringBuffer b = new StringBuffer("forgeeks");
a.delete(1,3);
a.append(b);
System.out.println(a);
}
}
class Test
{
public static void main(String[] args)
{
StringBuffer a = new StringBuffer("geeks");
StringBuffer b = new StringBuffer("forgeeks");
a.delete(1,3);
a.append(b);
System.out.println(a);
}
}
gsforgeeks
gksforgeeks
geksforgeeks
Compilation error