Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

PCODE : 0500536 (JAVA PROGRAMMING)

01. 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
(A) 1, 2, 3, 4
(B) 1, 3, 4, 5
(C) 2, 4, 5, 6
(D) 3, 4, 5, 6

02. Which one of these lists contains only Java programming language keywords?
(A) class, if, void, long, Int, continue
(B) goto, instanceof, native, finally, default, throws
(C) try, virtual, throw, final, volatile, transient
(D) strictfp, constant, super, implements, do

03. Which will legally declare, construct, and initialize an array?


(A) int [] myList = {"1", "2", "3"};
(B) int [] myList = (5, 8, 2);
(C) int myList [] [] = {4,9,7,0};
(D) int myList [] = {4, 3, 7};

04. Which is a reserved word in the Java programming language?


(A) method
(B) native
(C) subclasses
(D) reference

05. Which is a valid keyword in java?


(A) interface
(B) string
(C) Float
(D) unsigned
PCODE : 0500536 (JAVA PROGRAMMING)
06. Which three are legal array declarations?
1 int [] myScores [];
2 char [] myChars;
3 int [6] myScores;
4 Dog myDogs [];
5 Dog myDogs [7];
(A) 1, 2, 4
(B) 2, 4, 5
(C) 2, 3, 4
(D) All are correct.

07. public interface Foo


{
int k = 4; /* Line 3 */
}
Which three piece of codes are equivalent to line 3?
1 final int k = 4;
2 public int k = 4;
3 static int k = 4;
4 abstract int k = 4;
5 volatile int k = 4;
6 protected int k = 4;
(A) 1, 2 and 3
(B) 2, 3 and 4
(C) 3, 4 and 5
(D) 4, 5 and 6

08. Which one of the following will declare an array and initialize it with five numbers?
(A) Array a = new Array(5);
(B) int [] a = {23,22,21,20,19};
(C) int a [] = new int[5];
(D) int [5] array;
PCODE : 0500536 (JAVA PROGRAMMING)
09. Which three are valid declarations of a char?
1 char c1 = 064770;
2 char c2 = 'face';
3 char c3 = 0xbeef;
4 char c4 = \u0022;
5 char c5 = '\iface';
6 char c6 = '\uface';
(A) 1, 2, 4
(B) 1, 3, 6
(C) 3, 5
(D) 5 only

10. Which is the valid declarations within an interface definition?


(A) public double methoda;
(B) public final double methoda;
(C) static void methoda(double d1);
(D) protected void methoda(double d1);

11. Which one is a valid declaration of a boolean?


(A) boolean b1 = 0;
(B) boolean b2 = 'false';
(C) boolean b3 = false;
(D) boolean b4 = Boolean.false;

12. Which three are valid declarations of a float?


1 float f1 = -343;
2 float f2 = 3.14;
3 float f3 = 0x12345;
4 float f4 = 42e7;
5 float f5 = 2001.0D;
6 float f6 = 2.81F;
(A) 1, 2, 4
(B) 2, 3, 5
(C) 1, 3, 6
(D) 2, 4, 6

13. Which is a valid declarations of a String?


(A) String s1 = null;
(B) String s2 = 'null';
(C) String s3 = (String) 'abc';
(D) String s4 = (String) '\ufeed';
PCODE : 0500536 (JAVA PROGRAMMING)
14. What is the numerical range of a char?
(A) -128 to 127
(B) -(215) to (215) - 1
(C) 0 to 32767
(D) 0 to 65535

15. You want subclasses in any package to have access to members of a superclass. Which is the most
restrictive access that accomplishes this objective?
(A) public
(B) private
(C) protected
(D) transient

16. public class Outer


{
public void someOuterMethod()
{
//Line 5
}
public class Inner { }
public static void main(String[] argv)
{
Outer ot = new Outer();
//Line 10
}
}
Which of the following code fragments inserted, will allow to compile?
(A) new Inner(); //At line 5
(B) new Inner(); //At line 10
(C) new ot.Inner(); //At line 10
(D) new Outer.Inner(); //At line 10
PCODE : 0500536 (JAVA PROGRAMMING)
17. interface Base
{
boolean m1 ();
byte m2(short s);
}
which two code fragments will compile?
1 interface Base2 implements Base {}
2 abstract class Class2 extends Base
{ public boolean m1(){ return true; }}
3 abstract class Class2 implements Base {}
4 abstract class Class2 implements Base
{ public boolean m1(){ return (7 > 4); }}
5 abstract class Class2 implements Base
{ protected boolean m1(){ return (5 > 7) }}
(A) 1 and 2
(B) 2 and 3
(C) 3 and 4
(D) 1 and 5

18. Which three form part of correct array declarations?


public int a [ ]
static int [ ] a
public [ ] int a
private int a [3]
private int [3] a [ ]
public final int [ ] a
(A) 1, 3, 4
(B) 2, 4, 5
(C) 1, 2, 6
(D) 2, 5, 6

19. public class Test { }


What is the prototype of the default constructor?
(A) Test
(B) Test(void)
(C) public Test
(D) public Test(void)
PCODE : 0500536 (JAVA PROGRAMMING)
20. What is the most restrictive access modifier that will allow members of one class to have access to
members of another class in the same package?
(A) public
(B) abstract
(C) protected
(D) default access

21. Which of the following is/are legal method declarations?


1 protected abstract void m1;
2 static final void m1{}
3 synchronized public final void m1 {}
4 private native void m1;
(A) 1 and 3
(B) 2 and 4
(C) 1 only
(D) All of them are legal declarations.

22. Which cause a compiler error?


(A) int[ ] scores = {3, 5, 7};
(B) int [ ][ ] scores = {2,7,6}, {9,3,45};
(C) String cats[ ] = {"Fluffy", "Spot", "Zeus"};
(D) boolean results[ ] = new boolean [] {true, false, true};

23. Which three are valid method signatures in an interface?


1 private int getArea;
2 public float getVol(float x);
3 public void main(String [] args);
4 public static void main(String [] args);
5 boolean setFlag(Boolean [] test);
(A) 1 and 2
(B) 2, 3 and 5
(C) 3, 4, and 5
(D) 2 and 4

24. You want a class to have access to members of another class in the same package. Which is the most
restrictive access that accomplishes this objective?
(A) public
(B) private
(C) protected
(D) default access
PCODE : 0500536 (JAVA PROGRAMMING)
25. What is the widest valid returnType for methodA in line 3?
public class ReturnIt
{
returnType methodA(byte x, double y) /* Line 3 */
{
return (long)x / y * 2;
}
}
(A) int
(B) byte

26. Class A
{
protected int method1(int a, int b)
{
return 0;
}
}
Which is valid in a class that extends class A?
(A) public int method1(int a, int b) {return 0; }
(B) private int method1(int a, int b) { return 0; }
(C) public short method1(int a, int b) { return 0; }
(D) static protected int method1(int a, int b) { return 0; }

27. Which one creates an instance of an array?


(A) int[ ] ia = new int[15];
(B) float fa = new float[20];
(C) char[ ] ca = "Some String";
(D) int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };

28. Which two of the following are legal declarations for nonnested classes and interfaces?
1 final abstract class Test {}
2 public static interface Test {}
3 final public class Test {}
4 protected abstract class Test {}
5 protected interface Test {}
6 abstract public class Test {}
(A) 1 and 4
(B) 2 and 5
(C) 3 and 6
(D) 4 and 6
PCODE : 0500536 (JAVA PROGRAMMING)
29. Which of the following class level (nonlocal) variable declarations will not compile?
(A) protected int a;
(B) transient int b = 3;
(C) private synchronized int e;
(D) volatile int d;

30. Which two cause a compiler error?


1 float[ ] f = new float(3);
2 float f2[ ] = new float[ ];
3 float[ ]f1 = new float[3];
4 float f3[ ] = new float[3];
5 float f5[ ] = {1.0f, 2.0f, 2.0f};
(A) 2, 4
(B) 3, 5
(C) 4, 5
(D) 1, 2

31. 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 )
{
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"

32. Which is a valid declaration within an interface?


(A) public static short stop = 23;
(B) protected short stop = 23;
(C) transient short stop = 23;
(D) final void madness(short stop);
PCODE : 0500536 (JAVA PROGRAMMING)
33. 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.

34. switch(x)
{
default:
System.out.println("Hello");
}
Which two are acceptable types for x?
1 byte
2 long
3 char
4 float
5 Short
6 Long
(A) 1 and 3
(B) 2 and 4
(C) 3 and 5
(D) 4 and 6
PCODE : 0500536 (JAVA PROGRAMMING)
35. public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}
Which statement is true?
(A) There is a syntax error on line 1.
(B) There are syntax errors on lines 1 and 6.

36. class Boo


{
Boo(String s) { }
Boo() { }
}
class Bar extends Boo
{
Bar() { }
Bar(String s) {super(s);}
void zoo()
{
// insert code here
}
}
which one create an anonymous inner class from within class Bar?
(A) Boo f = new Boo(24) { };
PCODE : 0500536 (JAVA PROGRAMMING)
37. What will be the output of the program?

public class Foo


{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
(A) Finally

38. Which constructs an anonymous inner class instance?


(A) Runnable r = new Runnable() { };
(B) Runnable r = new Runnable(public void run() { });
(C) Runnable r = new Runnable { public void run(){}};
(D) System.out.println(new Runnable() {public void run() { }});

39. Which is true about a method-local inner class?


(A) It must be marked final.
(B) It can be marked abstract.
(C) It can be marked public.
(D) It can be marked static.

40. Which statement is true about a static nested class?


(A) You must have a reference to an instance of the enclosing class in order to
instantiate it.
(B) It does not have access to nonstatic members of the enclosing class.
(C) It's variables and methods must be static.
(D) It must extend the enclosing class.
PCODE : 0500536 (JAVA PROGRAMMING)
41. What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
(A) finished

42. What will be the output of the program?


public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}
(A) ABCD
(B) Compilation fails.
(C) C is printed before exiting with an error message.
(D) BC is printed before exiting with an error message.
PCODE : 0500536 (JAVA PROGRAMMING)
43. What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */
{
System.out.print("B");
}
catch (Exception ex1)
{
System.out.print("C");
}
finally
{
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod()
{
throw new RuntimeException();
}
}
(A) BD
(B) BCD
(C) BDE
(D) BCDE

44. What will be the output of the program?


public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}
(A) hello throwit caught
(B) Compilation fails
(C) hello throwit RuntimeException caught after
(D) hello throwit caught finally after
PCODE : 0500536 (JAVA PROGRAMMING)
45. What will be the output of the program?
public class Test
{
public static void aMethod() throws Exception
{
try /* Line 5 */
{
throw new Exception(); /* Line 7 */
}
finally /* Line 9 */
{
System.out.print("finally "); /* Line 11 */
}
}
public static void main(String args[])
{
try
{
aMethod();
}
catch (Exception e) /* Line 20 */
{
System.out.print("exception ");
}
System.out.print("finished"); /* Line 24 */
}
}
(A) finally
(B) exception finished
(C) finally exception finished
(D) Compilation fails

46. What will be the output of the program?


public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() {}
}

(A) AC
(B) BC
(C) ACD
(D) ABCD
PCODE : 0500536 (JAVA PROGRAMMING)
47. What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod(); /* Line 7 */
System.out.print("A");
}
catch (Exception ex) /* Line 10 */
{
System.out.print("B"); /* Line 12 */
}
finally /* Line 14 */
{
System.out.print("C"); /* Line 16 */
}
System.out.print("D"); /* Line 18 */
}
public static void badMethod()
{
throw new RuntimeException();
}
}
(A) AB
(B) BC
(C) ABC
(D) BCD

48. What will be the output of the program?


class Exc0 extends Exception { }
class Exc1 extends Exc0 { } /* Line 2 */
public class Test
{
public static void main(String args[])
{
try
{
throw new Exc1(); /* Line 9 */
}
catch (Exc0 e0) /* Line 11 */
{
System.out.println("Ex0 caught");
}
catch (Exception e)
{
System.out.println("exception caught");
}
}
}
(A) Ex0 caught
(B) exception caught
(C) Compilation fails because of an error at line 2.
(D) Compilation fails because of an error at line 9.
PCODE : 0500536 (JAVA PROGRAMMING)
49. What will be the output of the program?
public class MyProgram
{
public static void main(String args[])
{
try
{
System.out.print("Hello world ");
}
finally
{
System.out.println("Finally executing ");
}
}
}
(A) Nothing. The program will not compile because no exceptions are specified.
(B) Nothing. The program will not compile because no catch clauses are specified.
(C) Hello world.
(D) Hello world Finally executing

50. Which three are methods of the Object class?


notify();
notifyAll();
isInterrupted();
synchronized();
interrupt();
wait(long msecs);
sleep(long msecs);
yield();
(A) 1, 2, 4
(B) 2, 4, 5
(C) 1, 2, 6
(D) 2, 3, 4

51. class X implements Runnable


{
public static void main(String args[])
{
/* Missing code? */
}
public void run() {}
}
Which of the following line of code is suitable to start a thread ?
(A) Thread t = new Thread(X);
(B) Thread t = new Thread(X); t.start();
(C) X run = new X(); Thread t = new Thread(run); t.start();
(D) Thread t = new Thread(); x.run();
PCODE : 0500536 (JAVA PROGRAMMING)
52. Which two are valid constructors for Thread?
Thread(Runnable r, String name)
Thread()
Thread(int priority)
Thread(Runnable r, ThreadGroup g)
Thread(Runnable r, int priority)
(A) 1 and 3
(B) 2 and 4
(C) 1 and 2
(D) 2 and 5

53. What is the name of the method used to start a thread execution?
(A) init();
(B) start();
(C) run();
(D) resume();

54. Which two of the following methods are defined in class Thread?
start()
wait()
notify()
run()
terminate()
(A) 1 and 4
(B) 2 and 3
(C) 3 and 4
(D) 2 and 4

55. Which three guarantee that a thread will leave the running state?
yield()
wait()
notify()
notifyAll()
sleep(1000)
aLiveThread.join()
Thread.killThread()
(A) 1, 2 and 4
(B) 2, 5 and 6
(C) 3, 4 and 7
(D) 4, 5 and 7
PCODE : 0500536 (JAVA PROGRAMMING)
56. Which of the following will directly stop the execution of a Thread?
(A) wait()
(B) notify()
(C) notifyall()
(D) exits synchronized code

57. Which method must be defined by a class implementing the java.lang.Runnable interface?
(A) void run()
(B) public void run()
(C) public void start()
(D) void run(int priority)

58. Which cannot directly cause a thread to stop executing?


(A) Calling the SetPriority() method on a Thread object.
(B) Calling the wait() method on an object.
(C) Calling notify() method on an object.
(D) Calling read() method on an InputStream object.

59. Assume the following method is properly synchronized and called from a thread A on an object B:
wait(2000); After calling this method, when will the thread A become a candidate to get another turn
at the CPU?
(A) After thread A is notified, or after two seconds.
(B) After the lock on B is released, or after two seconds.
(C) Two seconds after thread A is notified.
(D) Two seconds after lock B is released.

60. Which of the following will not directly cause a thread to stop?
(A) notify()
(B) wait()
(C) InputStream access
(D) sleep()

61. Which class or interface defines the wait(), notify(),and notifyAll() methods?
(A) Object
(B) Thread
(C) Runnable
(D) Class
PCODE : 0500536 (JAVA PROGRAMMING)
62. public class MyRunnable implements Runnable
{
public void run()
{
// some code here
}
}
which of these will create and start this thread?
(A) new Runnable(MyRunnable).start();
(B) new Thread(MyRunnable).run();
(C) new Thread(new MyRunnable()).start();
(D) new MyRunnable().start();

63. Which will contain the body of the thread?


(A) run();
(B) start();
(C) stop();
(D) main();

64. Which method registers a thread in a thread scheduler?


(A) run();
(B) construct();
(C) start();
(D) register();

65. Which of the following is not a tags of hibernate.cfg.xml?


(A) DTD
(B) JDBC connection
(C) SQL variant to generate
(D) Size of the database

66. There are core interfaces are used in just about every Hibernate application. Using these interfaces,
you can store and retrieve persistent objects and control transactions. Select the interfaces that is not
core interface.
(A) Configuration interface
(B) Session interface
(C) Query and Criteria interfaces
(D) User interface
PCODE : 0500536 (JAVA PROGRAMMING)
67. Which of the following is NOT a step in the Hibernate communication with RDBMS?
(A) Create HQL Query
(B) Execute query to get list containing Java objects
(C) Create session from configuration object
(D) Load the Hibernate configuration file and create configuration object

68. Which of the following is not a Session method?


(A) Session.save()
(B) Session.remove()
(C) Session.saveorupdate()
(D) Session.persist()

69. Which of the following are most common configuration methods of Hibernate Configuation
(A) Mapping files and XML configuration
(B) http.conf
(C) XML Configuration only
(D) web.config

70. Which of the following is FALSE about Session in hibernate


(A) Session is a light weight non-threadsafe object
(B) You can share the session between threads
(C) Session represents a single unit-of-work with the database
(D) Session is the primary interface for the persistence service

71. __________ objects can be passed across layers all the way up to the presentation layer without
having to use any DTOs (Data Transfer Objects). You can later re-attach them to another session
Possible correct answers:
(A) Persistent
(B) Detached

72. Which of these class is used to read and write bytes in a file?
(A) FileReader
(B) FileWriter
(C) FileInputStream
(D) InputStreamReader
PCODE : 0500536 (JAVA PROGRAMMING)
73. Which of these method of InputStream is used to read integer representation of next available byte
input?
(A) read()
(B) scanf()
(C) get()
(D) getInteger()

74. Which of these data type is returned by every method of OutputStream?


(A) int
(B) float
(C) byte
(D) None of the mentioned

75. Which of these is a method to clear all the data present in output buffers?
(A) clear()
(B) flush()
(C) fflush()
(D) close()

76. Which of the following is NOT a best practice for defining your Hibernate persistent classes?
(A) You must have a default no-argument constructor for your persistent classes and there
should be getXXX() (i.e accessor/getter) and setXXX( i.e. mutator/setter) methods for
all your persistable instance variables.
(B) You should implement the equals() and hashCode() methods based on your business
key and it is important not to use the id field in your equals() and hashCode()
definition if the id field is a surrogate key (i.e. Hibernate managed identifier). This is
because the Hibernate only generates and sets the field when saving the object.
(C) It is recommended to implement the Serializable interface. This is potentially useful if
you want to migrate around a multi-processor cluster.
(D) The persistent class should be final because if it is final then lazy loading can be used
by creating proxy objects.

77. Which of these classes is used for input and output operation when working with bytes?
(A) InputStream
(B) Reader
(C) Writer
(D) All of the mentioned
PCODE : 0500536 (JAVA PROGRAMMING)
78. What is the output of this program?

import java.io.*;
public class filesinputoutput {
public static void main(String[] args) {
String obj = "abc";
byte b[] = obj.getBytes();
ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
for (int i = 0; i < 2; ++ i) {
int c;
while ((c = obj1.read()) != -1) {
if(i == 0) {
System.out.print((char)c);
}
}
}
}
}

79. Which of these is method is used for writing bytes to an outputstream?


(A) put()
(B) print()
(C) printf()
(D) write()

80. What is the output of this program?

import java.io.*;
class filesinputoutput {
public static void main(String args[]) {
InputStream obj = new FileInputStream("inputoutput.java");
System.out.print(obj.available());
}
}
Note: inputoutput.java is stored in the disk.
(A) true
(B) false
(C) prints number of bytes in file
(D) prints number of characters in the file
PCODE : 0500536 (JAVA PROGRAMMING)
81. What is the output of this program?
import java.io.*;
public class filesinputoutput {
public static void main(String[] args) {
String obj = "abc";
byte b[] = obj.getBytes();
ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
for (int i = 0; i < 2; ++ i) {
int c;
while ((c = obj1.read()) != -1) {
if (i == 0) {
System.out.print(Character.toUpperCase((char)c));
obj2.write(1);
}
}
System.out.print(obj2);
}
}
}

82. What is the output of this program?

import java.io.*;
public class filesinputoutput {
public static void main(String[] args) {
String obj = "abc";
byte b[] = obj.getBytes();
ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
for (int i = 0; i < 2; ++ i) {
int c;
while ((c = obj1.read()) != -1) {
if (i == 0) {
System.out.print(Character.toUpperCase((char)c));
}
}
}
}
}
(A) abc
(B) ABC
(C) ab
(D) AB
PCODE : 0500536 (JAVA PROGRAMMING)
83. Java supports input/output of data through the classes included in the _______ package:
(A) Java.oi
(B) Java.out
(C) Java.in
(D) Java.io

84. Input stream class is :


(A) An interface defined in the java.io package
(B) A byte stream class used to read bytes from a file
(C) An abstract class which contain method to read 8 bit-bytes
(D) A class used to read primitive data types

85. The ________ method help in clearing the contents of the buffer:
(A) Flush()
(B) Clear()
(C) Rub()
(D) Vanish()

86. Java Stream classes can be categorised into _______ groups:


(A) 1
(B) 2
(C) 3
(D) 4

87. Byte Stream Classes support input/output operations on _____ bytes:


(A) 8 bit byte
(B) 16 bit byte
(C) 32 bit byte
(D) 64 bit byte

88. Character Stream Classes support input/output operations on _______ characters:


(A) 8 bit Unicode
(B) 16 bit Unicode
(C) 32 bit Unicode
(D) 64 bit Unicode
PCODE : 0500536 (JAVA PROGRAMMING)
89. Java Stream classes can be categorised into two groups:
(A) Byte and Character Stream Classes
(B) Stream and String Classes
(C) String and Character Stream Classes
(D) Buffer and Character Stream Classes

90. Which refers to a channel through which data flow from the source to the destination:
(A) String
(B) Character
(C) Stream
(D) Buffer

91. _______ is a string of characters, categorized according to the rules as a symbol.


(A) Delimiters
(B) Token
(C) Boolean
(D) Parsing

92. The _______class distinguish among numbers, identifiers, quoted strings and different common styles.
(A) Stringtokenizer
(B) Streamtokenizer
(C) Inputstream
(D) Buffer

93. The ______ class is used to display the result on an output device:
(A) Read Stream
(B) Write Stream
(C) Display Stream
(D) Print Stream

94. The _______ class is used to read characters from the file:
(A) Stream Reader
(B) Character Reader
(C) Input Reader
(D) File Reader
PCODE : 0500536 (JAVA PROGRAMMING)
95. Data Input Stream class contains methods to read________
(A) Non primitive data type
(B) Primitive data type

96. Input data type what is the characters and sequence of characters marking the begging or end of a unit
of data.
(A) Parsing
(B) Boolean
(C) Token
(D) Delimiters

97. The _______ class is used to write bytes to a file:


(A) File Input Stream
(B) File Output Stream
(C) File Buffer Stream
(D) File String Stream

98. The_____ class is used to read input from the console input device:
(A) Input Stream Reader
(B) Output Stream Reader
(C) Byte Stream Reader
(D) Buffer Stream Reader

99. When we invoke repaint() for a java.awt. Component object, the AWT invokes the method:
(A) update()
(B) draw()
(C) show()
(D) paint()

100. Which of the following is a correct signature for the paint() method?
(A) static void paint(Graphics[] g)
(B) public paint(Graphics g)
(C) public void paint(Graphics g)
(D) public static void paint(Graphics g)
PCODE : 0500536 (JAVA PROGRAMMING)
101. To import all the classes in the package java.awt, you write
(A) import java.awt;
(B) import java.*;
(C) import java.awt.*;
(D) You don't need to import the package; it is implicitly imported by the Java runtime

102. Which of the following is a correct signature for the main() method?
(A) static void main(String[] args[])
(B) public static void main(String[] args)
(C) public void main(String[] args)
(D) public static void main(strings[] args)

103. Which specifies that all the character within the range between low & high are white space
characters:
(A) Void wordChars
(B) Void whitespaceChars
(C) Void resetSyntax()
(D) Void Chars

104. _________ method returns the current line number:


(A) int next()
(B) int line()
(C) int lineon()
(D) int lineno()

105. Java provides _______ to convert byte-oriented data into character-oriented data:
(A) InputStreamReader
(B) OutputStreamReader
(C) StringStreamReader
(D) PrintStreamReader

106. What does the following line of code do?


Textfield text = new Textfield(10);
(A) Creates text object that can hold 10 rows of text.
(B) Creates the object text and initializes it with the value 10.
(C) Creates text object that can hold 10 columns of text.
(D) The code is illegal.
PCODE : 0500536 (JAVA PROGRAMMING)
107. Which of the following applet tags is legal to embed an applet class named Test into a Web page?
(A) < applet class = Test width = 200 height = 100>
(B) < applet> code = Test.class width = 200 height = 100>
(C) < applet code = Test.class width = 200 height = 100
(D) < applet param = Test.class width = 200 height = 100>

108. Which of the following methods can be used to draw the outline of a square within a java.awt.
Component object?
(1) fillRect()
(2) drawLine()
(3) drawRect()
(4) drawString()
(5) drawPolygon()
(A) (2), (3) & (5)
(B) (1), (2), (3) & (5)
(C) (1), (2) & (3)
(D) (3), (4) & (5)

109. Which of the following methods can be used to remove a java.awt.Component object from the
display?
(A) delete()
(B) remove()
(C) disappear()
(D) hide()

110. The setBackground() method is part of the following class in java.awt package:
(A) Graphics
(B) Component
(C) Applet
(D) Container

111. From a MVC perspective, Struts provides the


(A) Model
(B) View
(C) Controller
PCODE : 0500536 (JAVA PROGRAMMING)
112. What are not the important ApplicationContext implementations in spring framework ?
(A) XmlWebApplicationContext
(B) FileSystemXmlApplicationContext
(C) ClassPathXmlApplicationContext
(D) URLPathXmlApplicationContext

113. Look at the code below .


<bean id = "helloWorldSample"´ depends-on = "setuphelloClassId">
<property name="myString"> Hello World Program </property>
<property name="dependentClassId"> <ref bean = "firstDependentClass"/>
</property>
</bean>
<bean id = "dependentClass" class = "com.helloworld.dependent.DependentClass" destroy-
method="cleanupMethod">
<property name="dependentString">
</property>
</bean>
<bean id = "setuphelloClassId" class = "com.helloworld.config.setupHelloClass"/>

Which of the following answers is correct ?


(A) The bean for helloWorldSample class depends on the setuphelloClassId class and the
property "dependentClassId" is not a field for the Helloworld bean with a reference to
the dependentClass class.
(B) The bean definition for HelloWorld depends on the setupHelloClass and the property
"dependentClassId" is a field for the Helloworld bean with a reference to the
firstDependentClass bean.
(C) The bean for HelloWorld class depends on the setupHelloClass property and the
property class "dependentClassId" is a field for the Helloworld bean with a reference
to the DependentClass property.
(D) The bean definition for HelloWorld depends on the setuphelloClassId and the
property "firstDependentClass" is a field for the Helloworld bean with a reference to

114. What do you understood by Inversion of Control(IOC) ?


(A) The object define their dependencies and the container injects the dependencies when
it creates the bean
(B) A property available in the Spring Framework in which caller methods control the
creation of parent

115. I want to add the MessageSource functionality to application, providing access to messages in i18
n-style in my application. Which one should I use ?
(A) ApplicationContext
(B) Properties File
(C) Servlet Context
PCODE : 0500536 (JAVA PROGRAMMING)
116. Can you instantiate a static inner class in Spring ?
(A) No. Static classes are not supported
(B) Yes. They are instantiated by default with the class
(C) Yes. But you will have to use the binary name of the class

117. Spring requires all your class to have default constructors. Failure to do so will result an exception at
startup.
(A) False
(B) True

118. How many JDBC driver types does Sun define?


(A) One
(B) Two
(C) Three
(D) Four

119. Where is metadata stored in MySQL?


(A) In the MySQL database metadata
(B) In the MySQL database metasql
(C) In the MySQL database mysql
(D) None of the above is correct.

120. Who invented Java?


(A) Netscape
(B) Microsoft
(C) Sun
(D) None of the above is correct.

121. To run a compiled Java program, the machine must have what loaded and running?
(A) Java virtual machine
(B) Java compiler
(C) Java bytecode
(D) A Web browser
PCODE : 0500536 (JAVA PROGRAMMING)
122. Which JDBC driver Type(s) can be used in either applet or servlet code?
(A) Both Type 1 and Type 2
(B) Both Type 1 and Type 3
(C) Both Type 3 and Type 4
(D) Type 4 only

123. ________ is an open source DBMS product that runs on UNIX, Linux and Windows.
(A) MySQL
(B) JSP/SQL
(C) JDBC/SQL
(D) Sun ACCESS

124. What is sent to the user via HTTP, invoked using the HTTP protocol on the user's computer, and run
on the user's computer as an application?
(A) A Java application
(B) A Java applet
(C) A Java servlet

125. What is not true of a Java bean?


(A) There are no public instance variables.
(B) All persistent values are accessed using getxxx and setxxx methods.
(C) It may have many constructors as necessary.
(D) All of the above are true of a Java bean.

126. A JSP is transformed into a(n):


(A) Java applet.
(B) Java servlet.
(C) Either 1 or 2 above.
(D) Neither 1 nor 2 above.

127. Which JDBC driver Type(s) can you use in three-tier architecture and if the Web server and the
DBMS are running on the same machine?
(A) Type 1 only
(B) Type 2 only
(C) Both Type 3 and Type 4
(D) All of Type 1, Type 2, Type 3 and Type 4
PCODE : 0500536 (JAVA PROGRAMMING)
128. What programming language(s) or scripting language(s) does Java Server Pages (JSP) support?
(A) VBScript only
(B) Jscript only
(C) Java only
(D) All of the above are supported

129. What servlet processor was developed by Apache Foundation and Sun?
(A) Apache Tomcat
(B) Apache Web server
(C) Sun servlet processor
(D) None of the above is correct.

130. What is bytecode?


(A) Machine-specific code
(B) Java code
(C) Machine-independent code
(D) None of the above is correct.

131. What is invoked via HTTP on the Web server computer when it responds to requests from a user's
Web browser?
(A) A Java application
(B) A Java applet
(C) A Java servlet
(D) None of the above is correct.

132. Your application supports multiple client types including HTTP clients. Your business layer is
implemented using Enterprise Java Beans. Which of the following is best suited for maintaining
client state?
(A) Stateful session beans
(B) Entity Beans
(C) HttpSession attributes

133. Which enterprise bean type is defined without any client view interfaces?
(A) BMP Entity bean
(B) CMP Entity bean
(C) Stateful Session bean
(D) Message Driven Bean
PCODE : 0500536 (JAVA PROGRAMMING)
134. Which technology provides the flexibility to swap between XML processors with no application code
changes?
(A) JAXP
(B) SAX
(C) XSLT
(D) JAAS

135. You want to locate an existing bean object but do not want to create a new instance, if an existing in-
stance is not available. Which of the following bean attributes will you use in the jsp:useBean
action?
(A) class
(B) type
(C) beanName
(D) class and type

136. Which of the following should NOT be used to share data between servlets in a distributed web
application?
(A) Attributes of ServletContext
` (B) Enterprise Java Beans
(C) Attributes of HttpSession
(D) Database

137. A JMS message producer is created by a ______.


(A) session
(B) connection
(C) destination
(D) factory

138. If the HTTP error 500 is generated by your servlet, you do not want to show the "Internal Server
Error" page to the client. Instead, you want a custom error page to be displayed. What is the best way
to accomplish this?
(A) Forward the user to the error page using HttpServletResponse.sendRedirect method.
(B) Forward the user to the error page using RequestDispatcher.forward method.
(C) Specify the mapping of the error-code 500 and the error page in the deployment
descriptor.
(D) It is not possible to accomplish this.
PCODE : 0500536 (JAVA PROGRAMMING)
139. A web application is located in a directory named 'school'. Its deployment descriptor will be located in
which of the following?
(A) school
(B) school/WEB-INF
(C) school/META-INF
(D) WEB-INF/school

140. An EJB is required to perform credit card verification. All necessary information such as card number
and amount will be supplied as parameters to a single business method invocation that processes the
verification. Assuming that performance is critical, which bean type BEST suits the requirement?
(A) Stateful Session Bean
(B) Stateless Session Bean
(C) Message Driven Bean
(D) Entity Bean

141. Which of these packaging options of enterprise beans are recommended for most J2EE applications?
(A) Package each enterprise bean for an application in its own EJB module
(B) Package all enterprise beans for an application in one EJB module
(C) Package all related enterprise beans for an application in one EJB module
(D) None of These

142. __________are great when your application requires a lot of real programming to accomplish its task.
(A) HTML
(B) Apache
(C) Servlets
(D) None of the Above

143. MVC Stands for _____________


(A) Mobile View Control
(B) Model Vast control
(C) Model View Controller
(D) None of the Above

144. The most important point about MVC is the idea of separating the business logic and data access
layers from the presentation layer.
(A) True
(B) False
PCODE : 0500536 (JAVA PROGRAMMING)
145. To Extract the data from the beans which property is used.
(A) jsp:getProperty
(B) jsp:writeProperty
(C) jsp:setProperty
(D) All of the Above

146. Which method/class is used to Forward the request to a JSP page.


(A) RequestSend
(B) RequestDispatcher
(C) ResponseDispatcher
(D) None of the Above

147. Where to save your .java and .class file of Beans.


(A) Inside WEB-INF Directory
(B) Inside Website Root Directory
(C) Inside Lib Directory
(D) Inside package Directory

148. You are using session-based data sharing, Which method is preferable to use to transfer control from
the servlet to the JSP page
(A) response.write
(B) request.sendRedirect
(C) response.sendRedirect
(D) out.print

149. If are the website developer and want to display counter on home page regarding Number of Live user
which scope will you use for Beans ?
(A) Page
(B) Request
(C) Session
(D) Application

150. If you would like to store user type (like admin or user) in the beans object which kind of sharing is
used?
(A) Page
(B) Request
(C) Session
(D) Application
PCODE : 0500536 (JAVA PROGRAMMING)
151. Persistent values should be accessed through methods called _____________________
(A) getvalue and setvalue
(B) getXX and setXX.
(C) Both of the Above
(D) None of the Above

152. Which of the following is legal JSP syntax to print the value of i.
(A) <%int i = 1;%>
<%= i; %>
(B) <%int i = 1;
i; %>
(c) <%int i = 1%>
<%= i %>
(D) <%int i = 1;%>
<%= i %>

153. A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/test.jsp?
name="John". The test.jsp contains the following code.
<%! String myName=request.getParameter();%>
<% String test= "welcome" + myName; %>
<%= test%>
(A) The program prints "Welcome John"
(B) The program gives a syntax error because of the statement
<%! String myName=request.getParameter();%>
(C) The program gives a syntax error because of the statement
<% String test= "welcome" + myName; %>
(D) The program gives a syntax error because of the statement
<%= test%>

154. Which of the following correctly represents the following JSP statement. Select the one correct
answer.
<%=x%>
(A) <jsp:expression=x/>
(B) <jsp:expression>x</jsp:expression>
(C) <jsp:statement>x</jsp:statement>
(D) <jsp:declaration>x</jsp:declaration>
PCODE : 0500536 (JAVA PROGRAMMING)
155. What gets printed when the following JSP code is invoked in a browser. Select the one correct an-
swer.
<%= if(Math.random() < 0.5) %>
hello
<%= } else { %>
hi
<%= } %>
(A) The browser will print either hello or hi based upon the return value of random.
(B) The string hello will always get printed.
(C) The string hi will always get printed.
(D) The JSP file will not compile.

156. Which of the following correctly represents the following JSP statement. Select the one correct
answer.
<%x=1;%>
(A) <jsp:expression x=1;/>
(B) <jsp:expression>x=1;</jsp:expression>
(C) <jsp:statement>x=1;</jsp:statement>
(D) <jsp:scriptlet>x=1;</jsp:scriptlet>

157. Which of the following are correct. Select the one correct answer.
(A) JSP scriptlets and declarations result in code that is inserted inside the _jspService
method.
(B) The JSP statement <%! int x; %> is equivalent to the statement
<jsp:scriptlet>intx;</jsp:scriptlet%>.
(C) The following are some of the predefined variables that maybe used in JSP expression
- httpSession, context.
(D) To use the character %> inside a scriptlet, you may use %\> instead.

158. What gets printed when the following is compiled. Select the one correct answer.
<% int y = 0; %>
<% int z = 0; %>

<% for(int x=0;x<3;x++) { %>


<% z++;++y;%>
<% }%>

<% if(z<y) {%>


<%= z%>
<% } else {%>
<%= z - 1%>
<% }%>
(A) 0 (B) 1
(C) 2 (D) 3
PCODE : 0500536 (JAVA PROGRAMMING)
159. Which of the following JSP variables are not available within a JSP expression. Select the one correct
answer.
(A) session
(B) httpsession
(C) request
(D) response

160. A bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
Which of the following statements may be used to print the value of color property of the bean. Select
the one correct answer.
(A) <jsp:getColor bean="fruit"/>
(B) <jsp:getProperty id="fruit" property="color"/>
(C) <jsp:getProperty bean="fruit" property="color"/>
(D) <jsp:getProperty name="fruit" property="color"/>

161. A bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
Which of the following statements may be used to set the of color property of the bean. Select the one
correct answer.
(A) <jsp:setColor id="fruit" property="color" value="white"/>
(B) <jsp:setProperty name="fruit" property="color" value="white"/>
(C) <jsp:setValue name="fruit" property="color" value="white"/>
(D) <jsp:setProperty name="fruit" property="color" value="white">

162. A bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
What happens when the following statement is executed. Select the one correct answer.
<jsp:setProperty name="fruit" property="*"/>
(A) This is incorrect syntax of <jsp:setProperty/> and will generate a compilation error.
Either value or param must be defined.
(B) All the properties of the fruit bean are initialized to a value of null.
(C) All the properties of the fruit bean are assigned the values of input parameters of the
JSP page that have the same name.
(D) All the properties of the fruit bean are initialized to a value of *.

163. Is the following statement true or false. If the isThreadSafe attribute of the page directive is false, then
the generated servlet implements the SingleThreadModel interface.
(A) True
(B) False
PCODE : 0500536 (JAVA PROGRAMMING)
164. Which of the following represents a correct syntax for usebean.
(A) <jsp:usebean id="fruit scope ="page"/>
(B) <jsp:usebean id="fruit type ="String"/>
(C) <jsp:usebean id="fruit type ="String" beanName="?"/>
(D) <jsp:usebean id="fruit class="Fruit" beanName="Fruit"/>

165. Name the default value of the scope atribute of <jsp:usebean>.


(A) page
(B) application
(C) session
(D) request

166. Which of the following statements are true for <jsp:usebean>. Select the two correct answers.
(A) The id attribute must be defined for <jsp:usebean>.
(B) The scope attribute must be defined for <jsp:usebean>.
(C) The class attribute must be defined for <jsp:usebean>.
(D) The <jsp:usebean> must include either type or class attribute or both.

167. Which of these are legal attributes of page directive. Select the two correct answers.
(A) include
(B) scope
(C) errorPage
(D) debug

168. Which of the following represents the XML equivalent of this statement <%@ include
file="a.jsp"%> . Select the one correct statement
(A) <jsp:include file="a.jsp"/>
(B) <jsp:include page="a.jsp"/>
(C) <jsp:directive.include file="a.jsp"/>
(D) There is no XML equivalent of include directive.
PCODE : 0500536 (JAVA PROGRAMMING)
169. Assume that you need to write a JSP page that adds numbers from one to ten, and then print the
output.
<% int sum = 0;
for(j = 0; j < 10; j++) { %>
// XXX --- Add j to sum
<% } %>
// YYY --- Display ths sum

Which statement when placed at the location XXX can be used to compute the sum. Select the one
correct statement
(A) <% sum = sum + j %>
(B) <% sum = sum + j; %>
(C) <%= sum = sum + j %>
(D) <%= sum = sum + j; %>

170. Now consider the same JSP example as last question. What must be added at the location YYY to
print the sum of ten numbers.
(A) <% sum %>
(B) <% sum; %>
(C) <%= sum %>
(D) <%= sum; %>

171. JSP pages have access to implicit objects that are exposed automatically. One such object that is
available is request. The request object is an instance of which class?
(A) HttpRequest
(B) ServletRequest
(C) Request
(D) HttpServletRequest

172. JSP pages have access to implicit objects that are exposed automatically. Name the implicit object that
is of type HttpSession.
(A) session
(B) application
(C) httpSession
(D) httpsession
PCODE : 0500536 (JAVA PROGRAMMING)
173. A Java bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
What is the effect of the following statement.
<jsp:setproperty name="fruit" property="color"/>
Select the one correct answer.
(A) An error gets generated because the value attribute of setAttribute is not defined.
(B) The color attribute is assigned a value null.
(C) The color attribute is assigned a value "".
(D) If there is a non-null request parameter with name color, then its value gets assigned
to color property of Java Bean fruit.

174. The page directive is used to convey information about the page to JSP container. Which of these are
legal syntax of page directive. Select the two correct statement
(A) <% page info="test page" %>
(B) <%@ page info="test page" session="false"%>
(C) <%@ page isThreadSafe=true %>
(D) <%@ page isErrorPage="errorPage.jsp" %>

175. Is the following JSP code legal? Select the one correct statement.
<%@page info="test page" session="false"%>
<%@page session="false"%>
(A) Yes. This is legal JSP syntax.
(B) No. This code will generate syntax errors.

176. A JSP page needs to generate an XML file. Which attribute of page directive may be used to specify
that the JSP page is generating an XML file.
(A) contentType
(B) generateXML
(C) type
(D) outputXML

177. A JSP page uses the java.util.ArrayList class many times. Instead of referring the class by its
complete package name each time, we want to just use ArrayList. Which attribute of page directive
must be specified to achieve this. Select the one correct answer.
(A) extends
(B) import
(C) include
(D) package
PCODE : 0500536 (JAVA PROGRAMMING)
178. Which of these are true.
(A) The default value of isThreadSafe attribute of page directive is true.
(B) If isThreadSafe attribute of page directive is set to true, then JSP container dispatches
request for the page sequentially.
(C) When isThreadSafe attribute of page directive is set to false, a thread is created for
each request for the page.
(D) Setting isThreadSage attribute to true for JSP pages, can lead to poor performance.

179. Which of the following are examples of JSP directive. Select the two correct answers.
(A) include
(B) exclude
(C) import
(D) taglibrary

180. Which of these is true about include directive. Select the one correct answer.
(A) The included file must have jspf extension.
(B) The XML syntax of include directive in <jsp:include file="fileName"/> .
(C) The content of file included using include directive, cannot refer to variables local to
the original page.
(D) When using the include directive, the JSP container treats the file to be included as if
it was part of the original file.

181. Name the implicit variable available to JSP pages that may be used to access all the other implicit
objects.
(A) page
(B) pageContext
(C) context
(D) object

You might also like