Fnt software solutions placement paper

9
FNT Software Solutions Pvt Ltd, Bangalore Java Interview Questions Java Interview Questions (Core java, Servlets, JSP) Date:2012-10-19 Time:1:30 hrs 1) Which four options describe the correct default values for array elements of the types indicated? 1)int -> 0 2)String -> "null" 3)Dog -> null 4)char -> '\u0000' 5)float -> 0.0f 6)boolean -> true 2) Which will legally declare, construct, and initialize an array? 1. int [] myList = {"1", "2", "3"}; 2. int [] myList = (5, 8, 2); 3. int myList [] [] = {4,9,7,0}; 4. int myList [] = {4, 3, 7}; 3) Which is a reserved word in the Java programming language? A. method B. native C. subclasses D. reference E. array 4) public void foo( boolean a, boolean b) { if( a ) { System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ { System.out.println( "A && B"); } else /* Line 11 */ { if ( !b ) {

description

 

Transcript of Fnt software solutions placement paper

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

Java Interview Questions

(Core java, Servlets, JSP) Date:2012-10-19

Time:1:30 hrs

1) Which four options describe the correct default values for array elements of the types

indicated?

1)int -> 0 2)String -> "null" 3)Dog -> null

4)char -> '\u0000' 5)float -> 0.0f 6)boolean -> true

2) Which will legally declare, construct, and initialize an array?

1. int [] myList = {"1", "2", "3"};

2. int [] myList = (5, 8, 2);

3. int myList [] [] = {4,9,7,0};

4. int myList [] = {4, 3, 7};

3) Which is a reserved word in the Java programming language?

A. method B. native

C. subclasses D. reference

E. array

4) public void foo( boolean a, boolean b)

{

if( a )

{

System.out.println("A"); /* Line 5 */

}

else if(a && b) /* Line 7 */

{

System.out.println( "A && B");

}

else /* Line 11 */

{

if ( !b )

{

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

System.out.println( "notB") ;

}

else

{

System.out.println( "ELSE" ) ;

}

}

}

A. If a is true and b is true then the output is "A && B"

B. If a is true and b is false then the output is "notB"

C. If a is false and b is true then the output is "ELSE"

D. If a is false and b is false then the output is "ELSE"

5) public void test(int x)

{

int odd = 1;

if(odd) /* Line 4 */

{

System.out.println("odd");

}

else

{

System.out.println("even");

}

}

Which statement is true?

A. Compilation fails.

B. "odd" will always be output.

C. "even" will always be output.

D. "odd" will be output for odd values of x, and "even" for even values.

6) . What is the output when you execute the following code?

int i = 100;

switch (i) {

case 100:

System.out.println(i);

case 200:

System.out.println(i);

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

case 300:

System.out.println(i);

}

A) Nothing is printed B) Compile time error

C) The values 100,100,100 printed D) Only 100 is printed

7) . What is the result of compiling the following code?

public class Test {

public static void main ( String[] args) {

int value;

value = value + 1;

System.out.println(" The value is : " + value);

} }

A) Compile and runs with no output

B) Compiles and runs printing out "The value is 1"

C) Does not compile

D) Compiles but generates run time error

8) . What will happen when you attempt to compile and run the following code?

public class MyClass {

public static void main(String args[]) {

String s1 = new String("Test One");

String s2 = new String("Test One");

if ( s1== s2 ) {

System.out.println("Both are equal");

}

Boolean b = new Boolean(true);

Boolean b1 = new Boolean(false);

if ( b.equals(b1) ) {

System.out.println("These wrappers are equal");

} } }

A) Compile time error B)Runtime error.C)No output D)These wrappers are equal

9) . What is the result of the following code?

public class MyTest {

int x = 30;

public static void main(String args[]) {

int x = 20;

MyTest ta = new MyTest();

ta.Method(x);

System.out.println("The x value is " + x);

}

void Method(int y){

int x = y * y;

} }

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

A)The x value is 20. B)The x value is 30. C)The x value is 400. D)The x value is 600.

10) . Which of the following places no constraints on the type of elements, order

of elements, or repetition of elements with in the collection.?

A) Collection B) collection C) Map D) Set

11) What will be the output of the program?

class PassS

{

public static void main(String [] args)

{

PassS p = new PassS();

p.start();

}

void start()

{

String s1 = "slip";

String s2 = fix(s1);

System.out.println(s1 + " " + s2);

}

String fix(String s1)

{

s1 = s1 + "stream";

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

return "stream";

}

}

A. slip stream

B. slipstream stream

C. stream slip stream

D. slipstream slip stream

12) What will be the output of the program?

class Test

{

public static void main(String [] args)

{

int x=20;

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";

System.out.println(sup);

}

}

A. small B. tiny

C. huge D. Compilation fails

13) What will be the output of the program?

class Test

{

public static void main(String [] args)

{

int x= 0;

int y= 0;

for (int z = 0; z < 5; z++)

{

if (( ++x > 2 ) && (++y > 2))

{

x++;

}

}

System.out.println(x + " " + y);

}

}

A. 5 2 B. 5 3

C. 6 3 D. 6 4

14) What will be the output of the program?

class Bitwise

{

public static void main(String [] args)

{

int x = 11 & 9;

int y = x ^ 3;

System.out.println( y | 12 );

}

}

A. 0 B. 7

C. 8 D. 14

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

15) What will be the output of the program?

class SSBool

{

public static void main(String [] args)

{

boolean b1 = true;

boolean b2 = false;

boolean b3 = true;

if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */

System.out.print("ok ");

if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/

System.out.println("dokey");

}

}

A. ok

B. dokey

C. ok dokey

D. No output is produced

E. Compilation error

16) What will be the output of the program?

class SC2

{

public static void main(String [] args)

{

SC2 s = new SC2();

s.start();

}

void start()

{

int a = 3;

int b = 4;

System.out.print(" " + 7 + 2 + " ");

System.out.print(a + b);

System.out.print(" " + a + b + " ");

System.out.print(foo() + a + b + " ");

System.out.println(a + b + foo());

}

String foo()

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

{

return "foo";

}

}

A. 9 7 7 foo 7 7foo

B. 72 34 34 foo34 34foo

C. 9 7 7 foo34 34foo

D. 72 7 34 foo34 7foo

17) What will be the output of the program?

class Test

{

static int s;

public static void main(String [] args)

{

Test p = new Test();

p.start();

System.out.println(s);

}

void start()

{

int x = 7;

twice(x);

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

}

void twice(int x)

{

x = x*2;

s = x;

}

}

A. 7 7 B. 7 14

C. 14 0 D. 14 14

18) What are all the methods available in the Thread class?

1.isAlive() 2.join() 3.resume() 4.suspend() 5.stop() 6.start() 7.sleep() 8.destroy()

19) Which are keywords in Java?

a) NULL b) sizeof c) friend d) extends e) synchronized

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

20) The Java source code can be created in a Notepad editor.

a)True b) False

21) Choose correct ansewrs

1. Servlet is a Java technology based Web component.

2. Servlet servlets are platform-independent

3. Servlet has run on Web server which has a containers

4. Servlets interact with Web clients via a request/response using HTTP protocol.

A.1,2,3,4 B.1,2,3 C.1,3,4 D.None

22) Which of the following are interface?

1.ServletContext

2.Servlet

3.GenericServlet

4.HttpServlet

A.1,2,3,4 B,1,2 C.1,3,4 D.1,4

23) Which of the following are class?

1.ServletContext

2.Servlet

3.GenericServlet

4.HttpServlet

A.1,2,3,4 B,1,2 C.3,4 D.1,4

24) Which of the following methods are main methods in life cycle of servlet?

1.init()

2 .service()

3.destroy()

4.srop()

5.wait()

A.1,2,3,4,5 B,1,2,3 C.3,4,5 D.1,4,5

25) init(),service() and destroy()methods are define in

1.javax.servlet.Servlet interface

2.javax.servlet.ServletHttp class

3.javax.servlet.ServletRequest interface

4.javax.servlet.ServletResponse interface

A.1,2,3,4,5 B,1 C.3,4,5 D.1,4,5

26) Int init() ,.service() and destroy() methods which methods are call only once at life cycle

of servlets

1.init()

2.service()

3.destroy()

A.1,2,3 B,1,3 C.2 D.None

27) Which JDBC driver Type(s) is(are) the JDBC-ODBC bridge?

A. Type 1

B. Type 2

FNT Software Solutions Pvt Ltd, Bangalore

Java Interview Questions

C. Type 3

D. Type 4

28) JDBC stands for:

A. Java Database Connectivity

B. Java Database Components

C. Java Database Control

D. None of the above is correct

29) What are the scopes in Servelts?

1) Page 2) request 3) response 4) session 5) application

30) What are the scopes in JSP?

1) Page 2) request 3) response 4) session 5) application

31) What are the implicit objects in jsp?

32) What is the difference between Difference between doGet() and doPost()?

33) What is the difference between HttpServlet and GenericServlet?

34) Explain the directory structure of a web application.

35) What is a output comment?

36) What is a Hidden comment?

37) What is a Expression?

38) What is a Declaration?

39) What is a Scriptlet?

40) Explain the life-cycle mehtods in JSP?