1. Which statements are true regarding ServletContext Init Parameters in the deployment descriptor?

Answers:

  1. They are set at deployment-time, but accessed at run-time.
  2. They are accessible from any session within that context.
  3. They are not set at deployment-time, but accessed at run-time.
  4. They are set at deployment-time and can be updated at run-time.

2. Which of the following symbols are metacharacters supported by the java.util.regex API?

Answers:

  1. .
  2. @
  3. #

3. SQLException has a feature of chaining – identify the right code to execute the same from the following options:

Answers:

  1. catch(SQLException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } }
  2. catch(SQLException e) { out.println(e.getNextException()); while((e=e.getMessage())!=null) { out.println(e.getMessage()); } }
  3. catch(SQLException e) { out.println(e.getMessage()); while((e=e.getEncapsulatedException())!=null) { out.println(e.getMessage()); } }
  4. catch(ClassNotFoundException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } }
  5. catch(ClassNotFoundException e){ { out.println(e.getMessage()); } }

4. What is the result of an attempt to compile and run the given program?

public class Test107 {
public static void main(String[] args) {
System.out.println(test());
}
private static int test() {
return (true ? null : 0);
}
}

Answers:

  1. It gets a compiler error, because of an attempt to return null from the method with return type “int”.
  2. It compiles, but throws NullPointerException at run-time.
  3. It compiles, runs, and prints “null” (without quotes).
  4. It compiles, runs, and prints “0” (without quotes).

5. Which of the following methods are members of the Vector class and allow you to input a new element?

Answers:

  1. addItem
  2. append
  3. insert
  4. addElement

6. In which class is the notify method defined?

Answers:

  1. Thread
  2. Applet
  3. Runnable
  4. Object

7. What is the output of the given program?

public class Test93 {
private int x = 0;

public static void main(String[] args) {
new Test93().test();
}

private int f(int x) { return ++x; }
private int g(int y) { return x++; }

private void test() {
System.out.print( f(x)==f(x) ? “f” : “#” );
System.out.print( g(x)==g(x) ? “g” : “#” );
}
}

Answers:

  1. ##
  2. #g
  3. f#
  4. fg

8. Which design pattern reduces network traffic by acting as a caching proxy of a remote object?

Answers:

  1. DataAccess Object
  2. Model-View-Controller
  3. Value Object
  4. Business Delegate

9. What is the output of the given program?

public class Test89 {
public static void main(String[] args) {
T x = new T(“X”, null); x.start();
T y = new T(“Y”, x); y.start();
T z = new T(“Z”, y); z.start();
}
}
class T extends Thread {
private Thread predecessor;
private String name;
public T(String name, Thread predecessor) {
this.predecessor = predecessor;
this.name = name;
}
public void run() {
try {
Thread.sleep((int)(Math.random()*89));
System.out.print(name);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}

Answers:

  1. always XYZ
  2. always ZYX
  3. any of the following: XYZ, XZY, YXZ, YZX, ZXY, ZYX
  4. any of the following: XYZ, ZYX

10. The principal finder method that must be implemented by every entity bean class is:

Answers:

  1. findByPrimaryKey()
  2. ejbGetByPrimaryKey()
  3. ejbFindPrimayKey()
  4. getPrimaryKey()
  5. getFinder()

11. Which option lists Java access modifiers in the right order from the most permissive to the most restrictive?

Answers:

  1. public, protected, <i>no modifier/default/package</i>, private
  2. public, <i>no modifier/default/package</i>, protected, private
  3. <i>no modifier/default/package</i>, public, protected, private
  4. public, protected, private, <i>no modifier/default/package</i>

12. What should be the replacement of “//ABC” in the following code?

class Krit
{
String str= new String(“OOPS !!! JAVA”);
public void KritMethod(final int iArgs)
{
int iOne;
class Bicycle
{
public void sayHello()
{
//ABC
}
}
}
public void Method2()
{
int iTwo;
}
}

Answers:

  1. System.out.print(str);
  2. System.out.print(iOne);
  3. System.out.print(iTwo);
  4. System.out.print(iArgs);

13. Assuming that val has been defined as an int for the code below, which values of val will result in “Test C” being printed?

if( val > 4 ) {

System.out.println(“Test A”);

} else if( val > 9 ) {

System.out.println(“Test B”);

} else

System.out.println(“Test C”);

Answers:

  1. val < 0
  2. val between 0 and 4
  3. val between 4 and 9
  4. val > 9
  5. val = 0
  6. No values for val will result in “Test C” being printed.

14. What is the output of the given program?

public class Test118 extends _Test118 {
{
System.out.print(“_INIT”);
}
static {
System.out.print(“_STATIC”);
}
Test118() {
System.out.print(“_CONST”);
}
public static void main(String[] args) {
System.out.print(“_MAIN”);
new Test118();
}
}
class _Test118 {
_Test118() {
System.out.print(“_BASE”);
}
}

Answers:

  1. _STATIC_MAIN_BASE_INIT_CONST
  2. _STATIC_MAIN_INIT_BASE_CONST
  3. _INIT_STATIC_MAIN_BASE_CONST
  4. _INIT_STATIC_MAIN_BASE_CONST

15. What will be the output, if the following program is run?public class Test8 {
public static void main(String[] args) {
System.out.println(Math.sqrt(-4));
}
}

Answers:

  1. null
  2. 2
  3. NaN
  4. -2.0

16. What will be the output of this program?

public class Test {

public static void main(String args[]) {

int a, b;
a = 2;
b = 0;
System.out.println(g(a, new int[] { b }));
}

public static int g(int a, int b[]) {

b[0] = 2 * a;
return b[0];
}
}

Answers:

  1. 0
  2. 1
  3. An exception will occur
  4. 4

17. There are three classes named A, B, and C. The class B is derived from class A and class C is derived from B. Which of the following relations are correct for the given classes?

Answers:

  1. Any instance of A is an instance of B.
  2. Any instance of B is an instance of A.
  3. Any instance of C is an instance of B.
  4. Any instance of B is an instance of C.

18. What is the output of the given console application?

public class Test19 {
public static void main(String[] args) {
final int X = 9;
int[][] a = {{5, 4, 3}, {9, 7, 2}, {1, 6, 8}};
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
if (a[i][j] == X) break;
System.out.print(a[i][j] + “” “”);
}
}
}
}

Answers:

  1. ‘5
  2. 5 4 3
  3. 5 4 3 1 6 8
  4. 5 4 3 7 2 1 6 8

19. Which of the following statements is true?

Answers:

  1. public interface RemoteTrain extends java.rmi.Remote
  2. public class RemoteTrain extends java.rmi.Remote
  3. public interface RemoteTrain extends java.net.Remote
  4. public class RemoteTrain extends java.net.Remote
  5. private class RemoteTrain extends java.net.Remote

20. The JDK comes with a special program that generates skeleton and stub objects that is known as:

Answers:

  1. java.rmi.Remote
  2. rmi
  3. rmic
  4. rmijava
  5. javac

21. How many objects are created by the following code?

Object a, b, c, d, e;

e = new Object ();

b = a = e;

e = new Object ();

Answers:

  1. 2
  2. 5
  3. 4
  4. That code is invalid.

22. Which of these interfaces is the most applicable when creating a class that associates a set of keys with a set of values?

Answers:

  1. Collection
  2. Set
  3. Map
  4. SortedSet

23. Which of the following is the correct syntax for creating a Session object?

Answers:

  1. HttpSession ses=request.getSession(true);
  2. HttpSession ses=getSession(true);
  3. HttpSession ses=request.getSession();
  4. HttpSession ses=request.getSessionObject(true);
  5. HttpSession ses=response.getSession(true);

24. Which statement is true about the given code?

public class Test78 {
public static void main(String[] args) throws Exception {
new JBean().setHeight(1).setWidth(2).setDepth(3).setDensity(9);
}
}
class JBean {
private int height, width, depth, density;
public JBean setHeight (int h) { this.height = h; return this; }
public JBean setWidth (int w) { this.width = w; return this; }
public JBean setDepth (int d) { this.depth = d; return this; }
public JBean setDensity (int d) { this.density = d; return this; }
}

Answers:

  1. The code does not compile, because two setters have a formal parameter with the same name.
  2. The setters of the JBean class are JavaBean-compliant.
  3. The code compiles, but throws a NullPointerException at run-time.
  4. The code compiles and runs.

25. Choose all valid forms of the argument list for the FileOutputStream constructor shown below:

Answers:

  1. FileOutputStream( FileDescriptor fd )
  2. FileOutputStream( String n, boolean a )
  3. FileOutputStream( boolean a )
  4. FileOutputStream()
  5. FileOutputStream( File f )

26. Which of the following methods should be invoked by the container to get a bean back to its working state?

Answers:

  1. EJBPassivate()
  2. EJBActivate()
  3. EJBRemove()
  4. EJBOpen()
  5. EJBActivation()

27. Select all true statements:

Answers:

  1. An abstract class can have non-abstract methods.
  2. A non-abstract class can have abstract methods.
  3. If a non-abstract class implements interface, it must implement all the methods of the interface.
  4. If a non-abstract class inherits abstract methods from its abstract superclass, it must implement the inherited abstract methods.

28. Which option could be used to see additional warnings about code that mixes legacy code with code that uses generics?

Answers:

  1. -Xlint:unchecked
  2. -Xlint:-unchecked
  3. -Xswitchcheck or -Xlint:fallthrough depending on the version of Java
  4. -classpath or -cp

29. Assuming the servlet method for handling HTTPGET requests is doGet(HttpServletRequest req, HTTPServletResponse res), how can the request parameter in that servlet be retrieved?

Answers:

  1. String value=req.getInitParameter(10);
  2. String value=req.getInitParameter(“product”);
  3. String value=res.getParameter(“product”);
  4. String value=req.getParameter(“product”);

30. Which of these is not an event listener adapter defined in the java.awt.event package?

Answers:

  1. ActionAdapter
  2. MouseListener
  3. WindowAdapter
  4. FocusListener

31. What would be the result of compiling and running the following code class?

public class Test {

public static void main(String args[]) {

Test t = new Test();
t.start();
}

public void start() {

int i = 2;
int j = 3;
int x = i & j;
System.out.println(x);
}
}

Answers:

  1. The code will not compile.
  2. The code will compile but will give a runtime error.
  3. The code will compile and print 2.
  4. The code will compile and print 1.

32. Which of the following are the methods of the Thread class?

Answers:

  1. stay()
  2. go()
  3. yield()
  4. sleep(long millis)

33. What protocol is used by the DatagramSocket class?

Answers:

  1. STCP
  2. UDP
  3. TCP
  4. FTP
  5. None of the above

34. Which statements are true? Select all true statements.

Answers:

  1. A member variable can be declared synchronized.
  2. A class can be declared transient.
  3. A class be declared synchronized.
  4. A method can be declared synchronized.

35. Which exception must a setter of a constrained JavaBean property throw to prevent the property value from changing?

Answers:

  1. PropertyVetoException
  2. IllegalArgumentException
  3. IllegalComponentStateException
  4. InvalidAttributeValueException

36. X.509 version 3 specifies which of the following?

Answers:

  1. A format and content for digital certificates.
  2. The IPSec standard.
  3. The Secure Socket Layer.
  4. The Data Encryption Standard.
  5. A file for digital certificates.

37. What will be the output when this code is compiled and run?
public class Test {

public Test() {

Bar b = new Bar();
Bar b1 = new Bar();
update(b);
update(b1);
b1 = b;
update(b);
update(b1);
}

private void update(Bar bar) {

bar.x = 20;
System.out.println(bar.x);
}

public static void main(String args[]) {

new Test();
}

private class Bar {

int x = 10;
}
}

Answers:

  1. The code will fail to compile.
  2. 10 10 10 10
  3. 20 20 20 20
  4. 10 20 10 20

38. Which of the following methods can be used for reporting a warning on a Connection object, Statement object & ResultSet object?

Answers:

  1. getWarnings()
  2. getWarned()
  3. getWarning()
  4. getError()
  5. getErrors()

39. Which of the following are valid ways to define a thread in Java?

Answers:

  1. Create a subclass of java.lang.Thread class
  2. Create a class that implements java.lang.Runnable
  3. Define method run() in a class
  4. Define method call() in a class

40. JDBC is based on:

Answers:

  1. X/Open CLI (Call Level Interface)
  2. JDBC/Open CLI
  3. Java/Open CLI
  4. V/OPEN CLI
  5. V/CLOSE CLI

41. Which of the following statements regarding abstract classes are true?

Answers:

  1. All methods declared in an abstract class must be abstract.
  2. Any subclass (abstract or concrete class) of an abstract class must implement all the methods declared in the parent abstract class.
  3. Any concrete class must implement all the methods of the parent abstract class which are not implemented in the super hierarchy tree.
  4. The abstract class may have method implementation.

42. Which of the following is the name of the cookie used by Servlet Containers to maintain session information?

Answers:

  1. SESSIONID
  2. SERVLETID
  3. JSESSIONID
  4. CONTAINERID

43. Which method is called by the servlet container just after the servlet is removed from service?

Answers:

  1. public void finalize() {// code…}
  2. public void destroy() {// code…}
  3. public void destroy()throws ServletException {// code…}
  4. public void finalize()throws ServletException {// code…}

44. Which method in the HttpServlet class corresponds to the HTTPPUT method?

Answers:

  1. put
  2. doPut
  3. httpPut
  4. putHttp

45. Which of the following illustrates correct synchronization syntax?

Answers:

  1. public synchronized void Process(void){}
  2. public void Process(){ synchronized(this){ } }
  3. public void synchronized Process(){}
  4. public synchronized void Process(){}

46. The transaction attribute of a bean is set to ‘TX_REQUIRES_NEW.’ What can be inferred about its behavior?

Answers:

  1. It initiates a new transaction only when the previous one is concluded.
  2. It initiates a new transaction without waiting for the previous one to conclude.
  3. It sends the request to the EJB container for initiating a new bean.
  4. The bean manages its own transaction.

47. How many objects are created in the given code?

Object x, y, z;
x = new Object();
y = new Object();

Answers:

  1. 0
  2. 1
  3. 2
  4. 3

48. How does the set collection deal with duplicate elements?

Answers:

  1. Duplicate values will cause an error at compile time.
  2. A set may contain elements that return duplicate values from a call to the equals method.
  3. An exception is thrown if you attempt to add an element with a duplicate value.
  4. The add method returns false if you attempt to add an element with a duplicate value.

49. What is the output of the given program?

public class Test106 {
public static void main(String[] args) {
Integer x = 0;
Integer y = 0;
Integer a = 1000;
Integer b = 1000;
System.out.println( (a==b) + “; ” + (x==y) );
}
}

Answers:

  1. The code will not compile, because Integer is a class, and an object must be created by calling its constructor: Integer a = new Integer(1); or, alternatively, a primitive type must be used: int a = 1;
  2. true; true
  3. false; false
  4. false; true

50. 1 <libraryPrefix:handlerName parameterNAme=”value”>
2 <%=23*counter %>
3 <b>Congratulations!</b>

Which of the following is the correct way to complete the code snippet above?

Answers:

  1. </libraryPrefix:handlerName>
  2. </libraryPrefix:handlerName paremeterName=”value”>
  3. </handlerName>
  4. <libraryPrefix>

51. Which of the following transaction modes are supported by Enterprise Java Beans?

Answers:

  1. TX_NOT_SUPPORTED
  2. TX_BEAN_MANAGED
  3. TX_REQUIRED
  4. TX_MANDATORY
  5. All of the above

52. What is the output of the given program?

public class Test120 extends _Test120 {
{
System.out.print(“_INIT”);
}
static {
System.out.print(“_STATIC”);
}
Test120() {
System.out.print(“_CONST”);
}
public static void main(String[] args) {
System.out.print(“_MAIN”);
new Test120();
}
}
class _Test120 {
{
System.out.print(“_BIN”);
}
static {
System.out.print(“_START”);
}
_Test120() {
System.out.print(“_BASE”);
}
}

Answers:

  1. _START_STATIC_MAIN_BIN_BASE_INIT_CONST
  2. _STATIC_START_MAIN_BIN_BASE_INIT_CONST
  3. _STATIC_MAIN_START_BIN_BASE_INIT_CONST
  4. _START_MAIN_STATIC_BIN_BASE_INIT_CONST

53. Which distributed object technology is most appropriate for systems that consist entirely of Java objects?

Answers:

  1. RMI
  2. CORBA
  3. DCOM
  4. COM
  5. JDBC

54. The following code was written to save a handle to an EJBObject named ‘bookEJBObject’ for an online book shop:

javax.ejb.Handle bookHandle = _____________;

ObjectOutputStream stream = new ObjectOutputStream(newFileOutputStream(fileName));
stream.writeObject(bookHandle);
stream.close();

Which of the following methods should be filled in the blank?

Answers:

  1. (Handle) bookEJBObject()
  2. bookEJBObject.getHandle()
  3. bookEJBObject.getEJBHandle()
  4. newHandleInstance()

55. Which sequence will be printed when the following program is run?

import java.util.*;

public class Test {

public static void main(String str[]) {

List l = new ArrayList();
l.add(”1”);
l.add(”2”);
l.add(1,”3”);
System.out.println(l);
}
}

Answers:

  1. [1, 3, 2]
  2. [1, 3, 1]
  3. [1, 1, 3]
  4. [1, 1, 2]
  5. This code will generate an error.

56. Conventionally, which directory do servlet class files get placed on?

Answers:

  1. WEB-INFservlets
  2. webappservlets
  3. WEB-INFclasses
  4. WEB-INF

57. Which is a proper way to declare and throw exception of class XYException?

Answers:

  1. class XYException extends Exception {} … throw new XYException();
  2. class XYException implements Exception {} … throw new XYException();
  3. class XYException extends Exception {} … throw new Exception(“”XYException””);
  4. class XYException implements Exception {} … throw new Exception(“”XYException){};

58. Which of the following JDBC methods is used to retrieve large binary objects?

Answers:

  1. getBinaryStream()
  2. getText()
  3. getAsciiStream
  4. getString()
  5. getUniStream()

59. What is the output of the given program?

public class Test129 {
public static void main(String[] args) {
A a = new A2();
B b = new B2();
System.out.println(a.a + “” + b.b);
}
}
class A { int a = 1; }
class A2 extends A { int a = 2; }
class B { public int b = 1; }
class B2 extends B { public int b = 2; }

Answers:

  1. 1
  2. 2
  3. 11
  4. 22

60. What exception is thrown by this code, if arr[j]>arr[j+1]:

public static void main(String[] args) {
int []arr={12,23,43,34,3,6,7,1,9,6};
{
int temp;
for (int i=0;i<arr.length;i++)
{
for (int j=0;j<arr.length-i;j++ )
{
if (arr[j]>arr[j+1])
{
temp=arr[j];
arr[j+1]=arr[j];
arr[j+1]=temp;
}
}
}
}
for(int i=0; i<arr.length; i++)
{
System.out.print(arr[i] + ” “);
}
}

Answers:

  1. NumberFormatException
  2. ArrayIndexOutOfBoundException
  3. IOException

61. Which of the following is a well-known HTTP port?

Answers:

  1. 21
  2. 25
  3. 8080
  4. 80
  5. 137

62. What is the output of the given console application?

public class Test31 {
public static void main(String[] args) {
test();
}
public static void test() {
try {
System.out.print(“-try”);
return;
} catch (Exception e) {
System.out.print(“-catch”);
} finally {
System.out.print(“-finally”);
}
}
}

Answers:

  1. -try
  2. -try-catch
  3. -try-finally
  4. -try-catch-finally

63. Which of these interfaces are used by implementations of models for JTable?

Answers:

  1. TableModel
  2. TableColumnModel
  3. TableSelectionModel
  4. ListModel

64. Which of the following require explicit try/catch exception handling by the programmer?

Answers:

  1. Accessing a method in another class
  2. Attempting to open a network socket
  3. Attempting to open a file
  4. Traversing each member of an array

65. What is the output of the given program?

public class Test89 {
public static void main(String[] args) {
T x = new T(“”X””, null); x.start();
T y = new T(“”Y””, x); y.start();
T z = new T(“”Z””, y); z.start();
}
}
class T extends Thread {
private Thread predecessor;
private String name;
public T(String name, Thread predecessor) {
this.predecessor = predecessor;
this.name = name;
}
public void run() {
try {
Thread.sleep((int)(Math.random()*89));
System.out.print(name);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}

Answers:

  1. Always XYZ
  2. Always ZYX
  3. Any of the following: XYZ, XZY, YXZ, YZX, ZXY, ZYX
  4. Any of the following: XYZ, ZYX

66. Which of the following code snippets will take transform input string “2012/06/05” to output string “05 – 06 – 2012”?

Answers:

  1. String dateString = “2012/06/05”; Date date = new SimpleDateFormat(“yyyy/MM/dd”).parse(dateString); SimpleDateFormat sdf = new SimpleDateFormat(“dd – MM – yyyy”); System.out.println(sdf.format(date));
  2. String dateString = “2012/06/05”; Date date = new SimpleDateFormat(“yyyy/MM/dd”).format(dateString); SimpleDateFormat sdf = new SimpleDateFormat(“dd – MM – yyyy”); System.out.println(sdf.parse(date));
  3. String dateString = “2012/06/05”; Date date = new SimpleDateFormat(“dd – MM – yyyy”).format(dateString); SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/dd”); System.out.println(sdf.parse(date));
  4. String dateString = “2012/06/05”; Date date = new SimpleDateFormat(“dd – MM – yyyy”).parse(dateString); SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/dd”); System.out.println(sdf.format(date));

67. Which statement is true regarding ServletContext Initialization Parameters in the deployment descriptor?

Answers:

  1. They are accessible by all servlets in a given web application.
  2. They are accessible by all servlets in a given session.
  3. They are accessible by all servlets in a given HTTP request.
  4. They are accessible by all servlets in a given container.

68. Which of the following statements is true of the HashMap class?

Answers:

  1. It stores information as key/value pairs.
  2. Elements are returned in the order they were added.
  3. It does not permit null keys.
  4. It does not permit null values.

69. Which distributed object technology is most appropriate for systems that consist of objects written in different languages and that execute on different operating system platforms?

Answers:

  1. RMI
  2. CORBA/li>
  3. COBRA
  4. DCOM
  5. COM

70. What is the output of the given code?

public class Test15 {
public static void main(String[] args) {
VO a = new VO(2);
VO b = new VO(3);
swapONE(a, b);
print(a, b);
swapTWO(a, b);
print(a, b);
}

private static void print(VO a, VO b) {
System.out.print(a.toString() + b.toString());
}

public static void swapONE(VO a, VO b) {
VO tmp = a;
a = b;
b = tmp;
}
public static void swapTWO(VO a, VO b) {
int tmp = a.x;
a.x = b.x;
b.x = tmp;
}
}

class VO {
public int x;
public VO(int x) {
this.x = x;
}
public String toString() {
return String.valueOf(x);
}
}

Answers:

  1. 2332
  2. 3232
  3. 3223
  4. 2323

71. What would happen on trying to compile and run the following code?

class House {

public final void MaintainMethod() {
System.out.println(“MaintainMethod”);
}
}

public class Building extends House {

public static void main(String argv[]) {
House h = new House();
h.MaintainMethod();
}
}

Answers:

  1. A runtime error will occur because class House is not defined as final.
  2. Successful compilation and output of “MaintainMethod” at run time.
  3. A compilation error indicating that a class with any final methods must be declared final itself.
  4. A compilation error indicating that you cannot inherit from a class with final methods.

72. Which of the following code snippets will generate five random numbers between 0 and 200?

Answers:

  1. Random r = new Random(); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt(0,200)); }
  2. Random r = new Random(200); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt()); }
  3. Random r = new Random(); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt(200)); }
  4. Random r = new Random(200); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt(0)); }

73. What will be the output when this code is compiled and run?

public class Test {

public Test() {

Bar b = new Bar();
Bar b1 = new Bar();
update(b);
update(b1);
b1 = b;
update(b);
update(b1);
}

private void update(Bar bar) {

bar.x = 20;
System.out.println(bar.x);
}

public static void main(String args[]) {

new Test();
}

private class Bar {

int x = 10;
}
}

Answers:

  1. The code will fail to compile.
  2. 10 10 10 10
  3. 20 20 20 20
  4. 10 20 10 20

74. Which class contains a method to create a directory?

Answers:

  1. File
  2. DataOutput
  3. Directory
  4. FileDescriptor
  5. FileOutputStream

75. What is the output of the given program?

public class Test130 {
public static void main(String[] args) {
A a = new A2();
B b = new B2();
System.out.println(a.a + “””” + b.b());
}
}
class A {
public int a = 1;
}
class A2 extends A {
public int a = 2;
}
class B {
public int b() { return 1; }
}
class B2 extends B {
public int b() { return 2; }
}

Answers:

  1. 11
  2. 12
  3. 21
  4. 22

76. Which of the following is the correct syntax for suggesting that the JVM perform garbage collection?

Answers:

  1. System.setGarbageCollection();
  2. System.out.gc();
  3. System.gc();
  4. System.free();

77. Why can’t a Graphics object be created using the following statement?

Graphics g = new Graphics();

Answers:

  1. The Graphics class is a final class.
  2. The Graphics class is an abstract class.
  3. The constructor of the Graphic class needs a color object to be passed as a parameter, e.g Graphics g = new Graphics(new Color());.

78. Select all correct statements:

Answers:

  1. Vector is synchronized, ArrayList is not synchronized
  2. Hashtable is synchronized, HashMap is not synchronized
  3. Vector is not synchronized, ArrayList is synchronized
  4. Hashtable is not synchronized, HashMap is synchronized

79. What is the output of the given program?

public class Test97 {
public static void main(String[] args) {
int[][] a = new int[2][2];
System.out.println(a.length);
}
}

Answers:

  1. 0
  2. 2
  3. 3
  4. 4

80. Which of the following is false?

Answers:

  1. A scrollable ResultSet can be created in JDBC 2.0 API.
  2. The cursor is moved forward using next().
  3. The cursor is moved backward using previous().
  4. A while loop can be used because next() & previous() methods return false beyond the resultset.
  5. A while loop can be used because next () & previous () methods return -1 beyond the resultset.

81. Consider the following code:

public class Jam {

public void apple(int i, String s) {
}

//ABC

}

Choose possible valid code replacements of “//ABC” among the choices:

Answers:

  1. public void apple(String s, int i) {}
  2. public int apple(int i, String s) {}
  3. public void apple(int i, String mystring) {}
  4. public void Apple(int i, String s) {}

82. RMI allows remote communication between:

Answers:

  1. C++ and Java
  2. C and Java
  3. Pascal and Java
  4. Java and Java
  5. Java and TCP/IP

83. Which of the following interfaces makes it possible for Java to save an object to a file and turn it into a data stream?

Answers:

  1. java.io.Serialization
  2. java.net.Serializable
  3. java.net.Serialization
  4. java.io.Serializable
  5. java.net.io.Serializable

84. How many objects are created in the given code?

Object x, y, z;
x = new Object();
y = new Object()

Answers:

  1. 0
  2. 1
  3. 2
  4. 3

85. As part of the type erasure process, when compiling a class or interface that extends a parameterized class or implements a parameterized interface, the compiler may need to create a synthetic method, called a _________.

Answers:

  1. bridge method
  2. helper method
  3. stub method
  4. raw method

86. Consider the following code:

public static void main(String bicycle[])
{
System.out.println(bicycle[0]);
}

What would be the result if “java TwoTyre one two” is entered in the command line?

Answers:

  1. one
  2. two
  3. TwoTyre
  4. None of the above

87. With regard to the destroy lifecycle method, identify the correct statements about its purpose or about how and when it is invoked.

Answers:

  1. It gives the servlet an opportunity to clean up resources.
  2. Like try-catch, it is called upon an exception.
  3. It is rarely used but can be called to remove a servlet from memory.
  4. It isn’t called if the server crashes.

88. What is the term to describe a situation where two or more threads are blocked forever, waiting for each other?

Answers:

  1. deadlock
  2. starvation
  3. livelock
  4. liveness

89. What will be the output of the following code?
public class MyTest {

public static void main(String[] args) {
for (int i=0; i > 10; i+=2) {
System.out.println(i);
}
}
}

Answers:

  1. Nothing will be printed.
  2. It will print the following output: 0 2 4 6 8
  3. Compile time error
  4. It will print the following output: 0 1 2 3 4 5 6 7 8 9

90. Which of the following cannot apply to constructors?

Answers:

  1. Name same as class name
  2. Void return type
  3. Can have parameters
  4. Overloading

91.The transaction attribute of a bean is set to ‘TX_REQUIRES_NEW’. What can be inferred about its behavior?

Answers:

  1. It initiates a new transaction only when the previous one is concluded.
  2. It initiates a new transaction without waiting for the previous one to conclude.
  3. It sends the request to the EJB container for initiating a new bean.
  4. The bean manages its own transaction.

92.Why can’t a string’s compareTo method be overridden?

Answers:

  1. The String class is final, therefore its methods can’t be overridden.
  2. The String class doesn’t have a compareTo method.
  3. A compareTo method isn’t built-in; it has to be manually implemented.

93.What should be the replacement of «//ABC» in the following code?
class Krit
{
String str= new String(«OOPS !!! JAVA»);
public void KritMethod(final int iArgs)
{
int iOne;
class Bicycle
{
public void sayHello()
{
//ABC
}
}
}
public void Method2()
{
int iTwo;
}
}

Answers:

  1. System.out.print(str);
  2. System.out.print(iOne);
  3. System.out.print(iTwo);
  4. System.out.print(iArgs);

94.What is the output of the given program?
public class Test117 {
{
System.out.print(«_INIT»);
}
static {
System.out.print(«_STATIC»);
}
Test117() {
System.out.print(«_CONST»);
}
public static void main(String[] args) {
System.out.print(«_MAIN»);
new Test117();
}
}

Answers:

  1. _STATIC_MAIN_INIT_CONST
  2. _STATIC_MAIN_CONST_INIT
  3. _INIT_STATIC_CONST_MAIN
  4. _STATIC_INIT_CONST_MAIN

95.Assuming the tag library is in place and the tag handler is correct, which of the following is the correct way to use a custom tag in a JSP page?

Answers:

  1. <yourLibrary=»whatColorlslt» color=»red»/>
  2. <yourLibrary:whatColorlslt color=»red»/>
  3. <yourLibrary color=»red»/>
  4. <yourLibrary.whatColorlslt color=»red»/>

96.Why would the following code snippet not compile successfully?
if (mangoList instanceof List) { System.out.println(«true»); }

Answers:

  1. It is unknown whether mangoList is a List type.
  2. Generic types are erased before runtime.
  3. The instanceof keyword only works on primitive types.

97. Which of the following are wrapper classes?
Note: There may be more than one right answer.

Answers:

  1. java.lang.Math
  2. java.lang.Boolean
  3. java.lang.Long
  4. java.lang.Float

98.Which of the following code snippets will correctly convert from one time zone to another time zone?
Note: There may be more than one right answer.

Answers:

  1. DateFormat formatter = new SimpleDateFormat(«dd/MM/yyyy HH:mm:ss»);
    formatter.setTimeZone(TimeZone.getTimeZone(«GMT-8»));
    Date date = formatter.parse(«01/01/2012 05:00:00»);
    System.out.println(formatter.format(date));
    formatter.setTimeZone(TimeZone.getTimeZone(«GMT+5»));
    System.out.println(formatter.format(date));
  2. DateFormat formatter = new SimpleDateFormat(«dd/MM/yyyy HH:mm:ss»);
    formatter.setTimeZone(TimeZone.getTimeZone(«PST»));
    Date date = formatter.parse(«01/01/2012 05:00:00»);
    System.out.println(formatter.format(date));
    formatter.setTimeZone(TimeZone.getTimeZone(«IST»));
    System.out.println(formatter.format(date));
  3. DateFormat formatter = new SimpleDateFormat(«dd/MM/yyyy HH:mm:ss»);
    formatter.setTimeZone(new TimeZone(«PST»));
    Date date = formatter.parse(«01/01/2012 05:00:00»);
    System.out.println(formatter.format(date));
    formatter.setTimeZone(new TimeZone(«IST»));
    System.out.println(formatter.format(date));
  4. DateFormat formatter = new SimpleDateFormat(«dd/MM/yyyy HH:mm:ss»);
    formatter.setTimeZone(new TimeZone(«GMT-8»));
    Date date = formatter.parse(«01/01/2012 05:00:00»);
    System.out.println(formatter.format(date));
    formatter.setTimeZone(new TimeZone(«GMT+5»));
    System.out.println(formatter.format(date));

99. Select all true statements:

Note: There may be more than one right answer.

Answers:

  1. Threads exist within a process.
  2. Every process has at least one thread.
  3. Processes exist within a thread.
  4. A thread may belong to more than one process.

100.Which of the following is true regarding sleep() and wait() in threaded environments?Which of the following is true regarding sleep() and wait() in threaded environments?

Answers:

  1. Both can take time in milliseconds as a parameter and will execute when the time is expired.
  2. Both will wait for another thread’s notify() method before it can execute.
  3. The wait() method will wait for a specific time (in milliseconds) and continue execution afterwards, while sleep() will wait for another thread’s notify() method before it will execute.
  4. The sleep() method will wait for a specific time (in milliseconds) and continue execution afterwards, while wait() will wait for another thread’s notify() method before it will execute.

101. Choose the right syntax for preparedStatement using ? as a placeholder for values, namely CUSTOMER_ID,PRICE, to be substituted while inserting values in the table ORDER:
PreparedStatement ps=con.prepareStatement(«INSERT INTO ORDER (CUSTOMER_ID ,PRICE) VALUES(?,?)»);


Answers:

  1. ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(sql);
  2. ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate();
  3. ps.clear(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(sql);
  4. ps.clearParameters(); ps.setInt(1,3.09); ps.setDouble(2,790.50); ps.execute(sql);
  5. ps.clearParameters(); ps.setInt(1,3.09); ps.set(2,790.50); ps.execute(sql);

102. Given a method declared as:

public static List process(List nums)

A programmer wants to use the method like this:

// INSERT DECLARATIONS HERE
output = process(input);

Which pair of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)

Note: There may be more than one right answer.


Answers:

  1. ArrayList input = null;
    ArrayList output = null;
  2. ArrayList input = null;
    List output = null;
  3. List input = null;
    List output = null;

103. Which is the right syntax of a javadoc comment for parameter of the method test(int)?

public class Test125 {
public static void main(String[] args) {
new Test125().test(125);
}
public void test(int a) {
for (int i=0; iAnswers:

  1. @param a Description
  2. @parameter int a Description
  3. @param Description
  4. @parameter a Description

104.What will be the output when this code is compiled and run?

public class Test {

static int x = 10;

public Test() {

Bar b = new Bar();
Bar b1 = new Bar();
update(b);
update(b1);
}

private void update(Bar bar) {

bar.x = ++x;
System.out.println(bar.x);
}

public static void main(String args[]) {

new Test();
}

private class Bar {

public int x = 10;
}
}

Answers:

  1. The code will fail to compile.
  2. 11 12
  3. 11 11
  4. 12 12

105.What will be the output when this code is compiled and run?

public class Test {

static int x = 10;

public Test() {

Bar b = new Bar();
Bar b1 = new Bar();
update(b);
update(b1);
}

private void update(Bar bar) {

bar.x = ++x;
System.out.println(bar.x);
}

public static void main(String args[]) {

new Test();
}

private class Bar {

public int x = 10;
}
}

Answers:

  1. The code will fail to compile.
  2. 11 12
  3. 11 11
  4. 12 12

106. Which line of code will produce output «base», if inserted instead of the comment in the given code?

public class Test9 {
public static void main(String[] args) {
new Child9().printBase();
}
}
class Parent9 {
public void printSgnt() {
System.out.println(«base»);
}
}
class Child9 extends Parent9 {
public void printSgnt() {
System.out.println(«—-«);
}
public void printBase() {
// !!! INSERT A CODE LINE HERE !!!
}
}

Answers:

  1. super.printSgnt();
  2. this.printSgnt();
  3. printSgnt();
  4. printBase();

107. Choose the correct declarations for the main() method which will allow the class to be run as a standalone program:
Note: There may be more than one right answer.

Answers:

  1. public void main(String str[])
  2. static public void main(String str[])
  3. public static int main(String str[])
  4. public static void main(String str[])

108. What is the central abstraction of the Java Servlet API?

Answers:

  1. The Servlet interface
  2. The GenericServlet
  3. The HttpServlet
  4. The Servlet package
  5. The Servlet object

109. What will be the output of the following code?

import java.util.*;
public class Test {
public static void main(String args[]) throws Exception {
List l = new ArrayList();
int a = (int) (3 * 2.5);

for (int i = 0; i < 10; i++)
l.add(i);

String s = «Hello»;

l.add(a, s.getBytes(«UTF-8»)[2]);
System.out.println(l);
}
}

Answers:

  1. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  2. [0, 1, 2, 3, 4, 5, 6, 108, 7, 8, 9]
  3. [0, 1, 2, 3, 4, 5, 6, 108, 8, 9, 10]
  4. The code won’t compile.

110. What is true regarding the User Datagram Protocol (UDP)?

Note: There may be more than one right answer.

Answers:

  1. A message is never partial.
  2. Messages order is guaranteed.
  3. Messages are not guaranteed to arrive at destination.
  4. UDP is MTU independent.
  5. None of these.

111. Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?

class A {
}

class B extends A {
}

class C extends A {
}

public class X {

public static void main(String args[]) {

A x = new A();
B y = new B();
C z = new C();

// insert statement here
}
}

Note: There may be more than one right answer.

Answers:

  1. x = y;
  2. z = x;
  3. y = (B)x;
  4. y = (A)y;

112. Which of the following will programmatically throw an exception?

Answers:

  1. throw new Exception();
  2. throws new Exception();
  3. throw Exception();
  4. It is not possible to throw an exception programmatically.

113. Which of the following statements are true regarding declaring a servlet instance in a deployment descriptor?

Answers:

  1. The tags are nested within <web-app> tags
  2. The tags do not define parameters
  3. The tags are <servlet-instance></servlet-instance>
  4. It specifies the fully qualified class name of the servlet

114. Which of the following options is a valid declaration?

Answers:

  1. <%! String name=»Patricia» %>
  2. <%! String name=»Patricia»; %>
  3. <% String name=»Devyn» %>
  4. <% public String name=»Devyn»; %>

115. What is the return type of the method ceil(double) from the Math class

Answers:

  1. int
  2. float
  3. double
  4. Integer
  5. Double

116. What would happen on trying to compile and run the following code?

class ExThread extends Thread
{
public native String getTime();
}
public class ThMulti implements Runnable
{
boolean Stop;
public static void main(String argv[])
{
ThMulti m = new ThMulti();
m.go();
}
public void go()
{
ExThread ts = new ExThread(this);
ts.start();
Stop=true;
}
public void run()
{
if(Stop==true)
{
return;
}
System.out.println(«Thread is running»);
}
}

Answers:

  1. The code will not compile.
  2. The code will compile but will give a Runtime error.
  3. The code will compile and will print ‘Thread is running’.
  4. The code will compile and will print nothing on the screen.

117. What will happen to the running session beans if the EJB container crashes or restarts?

Answers:

  1. They will get destroyed (They will be destroyed)
  2. They will keep on running
  3. Their execution will be halted temporarily
  4. None of the above

118. With regard to the servlet context listener, which of the following methods is valid?

Answers:

  1. contextListenerEvent
  2. contextListenerInitialized
  3. contextInitialized
  4. contextListenerDestroyed

119. What would be the result of the following code?

public class Quest
{
int i=0;
public static void main(String argv[]) {
}
Quest()
{
top:
while(i <2) { System.out.println(i); i++; continue top; } } }

Answers:

  1. The code will compile but will not output anything at runtime
  2. The code will compile and output 0
  3. The code will compile and output 0 followed by 1
  4. The code will not compile as a target label cannot appear before the corresponding continue or break statement

120. Which of the following methods are defined in the Servlet interface?

Answers:

  1. init()
  2. service()
  3. finalize()
  4. destroy()

121. Which of the following objects are passed to a servlet’s service() method?

Answers:

  1. ServletRequest
  2. HttpServletRequest
  3. ServletResponse
  4. HttpServletResponse

122. By default, how many instances of a servlet are created by a Servlet Container?

Answers:

  1. One
  2. One per request
  3. One per session
  4. None of the above

123. Which of the following exceptions are defined by the Servlet API?

Answers:

  1. ServletException
  2. InitializationException
  3. UnavailableException
  4. ServletContextException

124. Which of the following are used by Servlet Containers to maintain session information?

Answers:

  1. cookies
  2. hidden form fields
  3. HTTPS protocol information
  4. URL rewriting

125. Which of the following event listeners are defined by the Servlet API?

Answers:

  1. HttpSessionBindingListener
  2. HttpSessionEventListener
  3. HttpSessionParameterListener
  4. HttpSessionAttributeListener

126. Which of the following methods are defined by the RequestDispatcher interface?

Answers:

  1. dispatch()
  2. include()
  3. redirect()
  4. forward()

127. Assume the custom tag is GLOOP and the prefix is TWONG. Which of the following is the JSP syntax for an empty custom tag?

Answers:

  1. <TWONG:GLOOP/>
  2. <GLOOP:TWONG/>
  3. <GLOOP:TWONG></GLOOP:TWONG>
  4. <TWONG:GLOOP></TWONG:GLOOP>

128. Which of the following is not a tier of three-tier architecture?

Answers:

  1. Client Interface
  2. Business Logic/li>
  3. Security
  4. Data Storage

129. Network data is translated into Java objects before calling the target method by an object known as:

Answers:

  1. Skeleton object
  2. Stub object
  3. skeleton() method
  4. stub() method
  5. RMI object

130. What is the output of the given program?
public class Test98 {
public static void main(String[] args) {
String s = «abcd»;
System.out.println(s.substring(2));
}
}

Answers:

  1. b
  2. bcd
  3. c
  4. cd
  5. RMI object

131. Distributed Computing in Java means:

Answers:

  1. Objects on different machines working together
  2. Methods on different machines working together
  3. Methods on same machines working together
  4. Objects on same machines working together
  5. Classes on different machines working together

132. An online shop employs a stateless session bean (named ‘Eshop’) to process the requests. ‘Eshop’ uses a declarative transaction management system. The following code is from the xml deployment descriptor file of the bean:
<ejb-jar>
<enterprise-beans>
<session> <ejb-name>Eshop</ejb-name>
<home>com.solution.EshopHome</home>
<remote>com.solution.Eshop</remote>
<local-home>com.solution.EshopLocalHome</local-home>
<local>com.solution.EshopLocal</local>
<ejb-class>com.solution.EshopBean</ejb-class>
</session>
</enterprise-beans>
</ejb-jar>
The session and transaction attributes are to be coded in the lines numbered 10 and 11. Which of the following options should be used to make the bean work as expected?

Answers:

  1. <session>Stateless</session>
    <transaction>Container</transaction>
  2. <session>Stateful</session>
    <transaction>Bean</transaction>
  3. <session-type>Stateless</session-type>
    <transaction-type>Container </transaction-type>
  4. <session-type>Stateful </session-type>
    <transaction-type>Bean</transaction-type>
  5. <session-type>Stateless</session-type>
    <transaction>Container</transaction>

133. Which of the following methods will cause a thread to stop?

Answers:

  1. Calling interrupt() method of the thread
  2. Calling sleep() method on thread
  3. Conclusion of execution of the run() method
  4. None of the above

134. What kinds of properties can a JavaBean have?
May be more than one right answer

Answers:

  1. indexed properties
  2. bound properties
  3. constrained properties
  4. limited properties

135. Select the correct option based upon the following sample code:
public class Test {
static int a;
int b;
public Test() {
int c;
c = a;
a++;
b += c;
System.out.println(«one»);
}
public void Test() {
int c;
c = a;
a++;
b += c;
System.out.println(«two»);
}
public static void main(String args[]) {

Test t = new Test();
}
}

Answers:

  1. The code will fail to compile because there is a method with the same name as the class name.
  2. The code will fail to compile because there are 2 constructors with the same names and parameters.
  3. The code will fail to compile because the constructor is trying to access a static variable.
  4. The code will compile but will fail when run.
  5. The code will compile and run successfully. It will print »one».
  6. The code will compile and run successfully. It will print »two».

136. What will be written to the standard output when the following program is run?
public class X {
public static void main(String args[]) {
System.out.println(11 ^ 2);
}
}

Answers:

  1. 10
  2. 9
  3. 11
  4. 13
  5. 121

137. Which of the following are true?
A. The maps collection is referred to a dictionary because of the way it works.
B. Each entry into a maps collection involves a pair of objects.
C. The key object in the maps collection can be duplicated.

Answers:

  1. A, B and C
  2. A and C
  3. A and B

138. Select all of the following statements that are true?

Answers:

  1. Import statements are checked for validity at compile time; import statements that point to unknown classes or packages will not compile.
  2. An application can have multiple classes with method: public static void main(String[] args)
  3. Import is recursive: importing a package imports its sub-packages as well.
  4. If one class from a package is imported by an import statement, all other classes from this package are considered imported as well.

139. With regard to the passivation of beans, which of the following statements is incorrect?
A. The process is possible in all the enterprise beans.
B. It is accompanied by some vendor specific methods, which are similar to java serialization.

Answers:

  1. A
  2. B
  3. Both A and B
  4. None of the above

140. A previously saved handle has to be retrieved from an EJBObject named ‘bookEJBObject’. The following remote interface has been written to restart the processing for that particular request:
ObjectInputStream stream =
new ObjectInputStream(new FileInputStream(fileName));
Handle bookHandle = (Handle) stream.readObject();
BookRemoteInterface bookEjbObject = (BookRemoteInterface) XX() ;
Which of the following should be substituted to Method XX() on line 6

Answers:

  1. javax.rmi.PortableRemoteObject(bookHandle.getEJBObject(), BookRemoteInterface);
  2. javax.rmi.PortableRemoteObject(EJBObject, BookRemoteInterface);
  3. javax.rmi.PortableRemoteObject.narrow(bookHandle.getEJBObject(), BookRemoteInterface.class);
  4. javax.rmi.PortableRemoteObject.narrow(bookHandle, BookRemoteInterface);
  5. ookHandle.getEJBObject()

141. Which of the following is true about the Java Cryptography Extension (JCE)?

Answers:

  1. It is included with the Java 2 platform.
  2. It is included with the Java 1 platform.
  3. It implements cryptographic algorithms.
  4. It contains the Java Security API.

142. Read the following JSP code snippet:
1 <libraryPrefix:handlerName parameterNAme=»value»>
2 <%=23*counter %>
3 <b>Congratulations!</b>
Which of the following is the correct way to complete the code snippet above?

Answers:

  1. </libraryPrefix:handlerName>
  2. </libraryPrefix:handlerName paremeterName=»value»>
  3. </libraryPrefix:handlerName paremeterName=»value»>
  4. <libraryPrefix>

143. What is the result of compiling and running the given code?
/* 1 */ import java.util.*;
/* 2 */ public class Test80 {
/* 3 */ public static void main(String… args) throws Exception {
/* 4 */ args = new String[] {«one», «two», «three»};
/* 5 */ new Vector(3) {{add(«one»); add(«two»); add(«three»); }};
/* 6 */ }
/* 7 */ }

Answers:

  1. Compiler error regarding line 3 or 4
  2. Compiler error regarding line 4 or 5
  3. Code compiles with warnings and runs
  4. Code compiles without warnings and runs

144. Which of the following statements is correct regarding the «synchronized» keyword?

Answers:

  1. The synchronized method allows only one thread to access any object of a class.
  2. The synchronized method allows only one thread to access the same object of a class.
  3. The synchronized method allows multiple threads to access any object of a class.
  4. The synchronized method allows only one thread to access different objects of a class.

145. Which of the following statements is correct regarding the «synchronized» keyword?

Answers:

  1. The synchronized method allows only one thread to access any object of a class.
  2. The synchronized method allows only one thread to access the same object of a class.
  3. The synchronized method allows multiple threads to access any object of a class.
  4. The synchronized method allows only one thread to access different objects of a class.

146.Assuming that val has been defined as an int for the code below, which values of val will result in «Test C» being printed?
if( val > 4 ) {
System.out.println(«Test A»);
} else if( val > 9 ) {
System.out.println(«Test B»);

} else
System.out.println(«Test C»);

Answers:

  1. val < 0
  2. val between 0 and 4
  3. val between 4 and 9
  4. val > 9
  5. No values for val will result in «Test C» being printed.

147. Consider the following code:
public static void main(String bicycle[])
{
System.out.println(bicycle[0]);
}
What would be the result if «java TwoTyre one two» is entered in the command line?
Answers:

  1. one < 0
  2. two
  3. TwoTyre
  4. None of the above

148. Which of the following is false?

Answers:

  1. CallableStatement is subclass of PreparedStatement.
  2. CallableStatement can take input parameters as PreparedStatement.
  3. CallableStatement can use executeUpdate() method.
  4. CallableStatement can use execute() method.
  5. CallableStatement cannot take INOUT parameters.

149. Which of the following methods is used to get the parameters of an applet?

Answers:

  1. getAppletContext()
  2. getAppletInfo()
  3. getParameter()
  4. getParameters()

150. What is/are the OOP concepts demonstrated by this code:
public class Test {
public static void main(String[] args){
Animal a = new Dog();
new Hospital().treatAnimal(a);
}
}
class Animal {
public void sayIt(){
}
}
class Dog extends Animal{
public void sayIt(){
System.out.println(«I am Dog»);
}
}
class Cat extends Animal{
public void sayIt(){
System.out.println(«I am Cat»);
}
}
class Hospital{
public void treatAnimal(Animal a){
if(a instanceof Dog){
a.sayIt();
} else {
a.sayIt();
}
}
}

Answers:

  1. Polymorphism
  2. Inheritence
  3. getParameter()
  4. Abstraction

151. What will be the output of this program?
public class Test {
public static void main (String args[]) {
String a, b, c, d;
a = »Hello1234»;
b = »Hello» + String.valueOf(1234);
c = »Hello» + »1234»;
d = new String (new char[]{‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘1’, ‘2’, ‘3’, ‘4’});
System.out.print (a == b);
System.out.print (» »);
System.out.print (a.equals(b));
System.out.print (» »);
System.out.print (a == c);
System.out.print (» »);
System.out.print (a.equals(c));
System.out.print (» »);
System.out.print (a == d);
System.out.print (» »);
System.out.print (a.equals(d));
System.out.print (» »);
}
}
Answers:

  1. true true true true false true
  2. false true true true false false
  3. false true true true false true
  4. false false true true false true

152. Which term describes a situation where a thread is unable to gain regular access to shared resources and thus is unable to make progress??

Answers:

  1. deadlock
  2. starvation
  3. livelock
  4. liveness

153. What is the output of the given console application?
public class Test32 {
public static void main(String[] args) {
try {
System.out.print(«-try»);
int[] a = {1, 2};
a[2] = 0;
} catch (ArrayIndexOutOfBoundsException aioobe) {
System.out.print(«-catch»);
} catch (Exception e) {
System.out.print(«-clean»);
} finally {
System.out.print(«-finally»);
}
}
}
Answers:

  1. -try-finally
  2. -try-clean-finally
  3. -try-catch-finally
  4. -try-catch-clean-finally

154. What is the output of the given program?
public class Test71{
public static void main(String[] args) {
System.out.println(new Child().toString());
}
}
class Parent {
public String toString() { return this.getClass().getName(); }
}
class Child extends Parent {}

Answers:

  1. Parent
  2. Child
  3. Class
  4. null

155. Which of the following must be implemented by a JMS message-driven bean?

Answers:

  1. MessageDrivenBean and MessageDrivenContext interfaces
  2. MessageListener and MessageDrivenBean interfaces
  3. MessageProducer and MessageDrivenBean interfaces
  4. ObjectMessage and MessageDrivenBean interfaces

156. SQLException has a feature of chaining — identify the right code to execute the same from the following options:

Answers:

  1. catch(SQLException e)
    {
    out.println(e.getMessage());
    while((e=e.getNextException())!=null)
    {
    out.println(e.getMessage());
    }
    }
  2. catch(SQLException e)
    {
    out.println(e.getNextException());
    while((e=e.getMessage())!=null)
    {
    out.println(e.getMessage());
    }
    }
  3. catch(SQLException e)
    {
    out.println(e.getMessage());
    while((e=e.getEncapsulatedException())!=null)
    {
    out.println(e.getMessage());
    }
    }
  4. catch(ClassNotFoundException e)
    {
    out.println(e.getMessage());
    while((e=e.getNextException())!=null)
    {
    out.println(e.getMessage());
    }
    }
  5. catch(ClassNotFoundException e){

    {
    out.println(e.getMessage());
    }
    }

157. Which assigment is valid, if put instead of /* [placeholder] */ in the given code?
public class Test112 {
public static void main(String[] args) {
class A { class A2{} }
/* [placeholder] */
}
}

Answers:

  1. A a = new A2();
  2. A a = new A.A2();
  3. A a = new A().new A2();
  4. A.A2 a2 = new A().new A2();

158. In generics code, the question mark (?) is called the?

Answers:

  1. Wildcard
  2. Raw type
  3. Diamond
  4. parameter

159. Which of the following are “keywords” in Java?

Answers:

  1. default
  2. NULL
  3. String
  4. throws

160. Which of the following statements are true regarding the structure of a WebArchive file?

Answers:

  1. It has a jar extension
  2. It is a JAR archive of the WebApplication structure
  3. It has a war extension
  4. It is extracted by the container upon the first call to any servlet it contains

161. What is the easiest and fastest way to sort the following string array?
String[] myString = {«cat»,»lion», «dog», «mouse»}
Answers:

  1. Array.Sort(myString);
  2. Collections.Sort(myString);
  3. Arrays.Sort(myString);

162. Skeleton translates the return value or exception into:

Answers:

  1. Encrypted format
  2. Decrypted format
  3. Network format
  4. File format
  5. Data format

163. Which of the following can be done to extend the transaction across multiple page requests & multiple servlets?

Answers:

  1. Synchronize doPost()
  2. Create a new connection for each transaction
  3. Implement session tracking and use the HttpSession object to hold onto the connection for each use
  4. Create a single connection object in the init() method and implement the SingleThreadModel
  5. Synchronize doGet()

164. What will be the output of the following code?
public class Test extends Thread{
private int value;
public Test(int value) {
this.value = value;
}
public static void main (String[] args) {
Test t1 = new Test(1);
Test t2 = new Test(2);
Test t3 = new Test(3);
t1.start();
t2.start();
t3.start();
}
@Override
public void run() {
for (int i = 0; i < 3; i++) {
System.out.println(“Thread” + value + “ with value ” + i + “ Started”);
try {
sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(“Thread” + value + “ with value ” + i + “ Completed”);
}
}
}

Answers:

  1. Thread 1 with value 1 Started
    Thread 2 with value 1 Started
    Thread 3 with value 1 Started
    Thread 1 with value 1 Completed
    Thread 2 with value 1 Completed
    Thread 3 with value 1 Completed
    Thread 1 with value 2 Started
    Thread 2 with value 2 Started
    Thread 3 with value 2 Started
    Thread 1 with value 2 Completed
    Thread 2 with value 2 Completed
    Thread 3 with value 2 Completed
    Thread 1 with value 3 Started
    Thread 2 with value 3 Started
    Thread 3 with value 3 Started
    Thread 1 with value 3 Completed
    Thread 2 with value 3 Completed
    Thread 3 with value 3 Completed
  2. Thread 1 with value 1 Started
    Thread 1 with value 1 Competed
    Thread 2 with value 1 Started
    Thread 2 with value 1 Competed
    Thread 3 with value 1 Started
    Thread 3 with value 1 Competed
    Thread 1 with value 2 Started
    Thread 1 with value 2 Competed
    Thread 2 with value 2 Started
    Thread 2 with value 2 Competed
    Thread 3 with value 2 Started
    Thread 3 with value 2 Competed
    Thread 1 with value 3 Started
    Thread 1 with value 3 Competed
  3. Thread 1 with value 1 Started
    Thread 2 with value 1 Started
    Thread 3 with value 1 Started
    Thread 1 with value 2 Started
    Thread 2 with value 2 Started
    Thread 3 with value 2 Started
    Thread 1 with value 3 Started
    Thread 2 with value 3 Started
    Thread 3 with value 3 Started
    Thread 1 with value 1 Completed
    Thread 2 with value 1 Completed
    Thread 3 with value 1 Completed
    Thread 1 with value 2 Completed
    Thread 2 with value 2 Completed
    Thread 3 with value 2 Completed
    Thread 1 with value 3 Completed
    Thread 2 with value 3 Completed
    Thread 3 with value 3 Completed
  4. The output cannot be predicted.

165. Which of the following statements will not compile?

Answers:

  1. File f = new File(«/»,»autoexec.bat»);
  2. DataInputStream d = new DataInputStream(System.in);
  3. RandomAccessFile r = new RandomAccessFile(«OutFile»);
  4. OutputStreamWriter o = new OutputStreamWriter(System.out);

166. Which of the following is the best option for scaling existing an application due to resource requirements, without changing its code?

Answers:

  1. Moving business objects to the client’s machine
  2. Moving business objects to another server machine
  3. Moving business objects to the client’s hard drive
  4. Moving business objects to the client’s RAM
  5. Moving business objects to another class

167. Choose the correct statements:

Answers:

  1. An inner class may extend another class.
  2. There are no circumstances where an inner class may be defined as private.
  3. A programmer may only provide one constructor for an anonymous class
  4. An inner class may be defined as static.

168. What would be the URL syntax for using third party drivers for establishing a connection with a DBMS having a subprotocol named «webx»?

Answers:

  1. jdbc:odbc:webx:dsn name
  2. odbc:jdbc:webx:dsn name
  3. jdbc:webx:dsn name
  4. thin:jdbc:odbc:dsn:dsn name
  5. thick:jdbc:odbc:dsn:dsn name

169. Which of the following correctly creates a thread using Runnable()?

Answers:

  1. Runnable r = new Runnable();
    r.start();
  2. Runnable r = new Runnable(new Thread({
    public void run(){
    }
    }));
    r.start();
  3. Runnable r = new Runnable(new Thread({
    public void run(){
    }
    }));
    r.run();
  4. Thread t = new Thread(new Runnable(){
    public void run(){
    }
    });
    t.start();

170. What will be the output of the following program?
public class Test
{
public static void main (String args[])
{
B o = new A ();
System.out.println (o.content ());
}
public String content () throws Exception
{
throw new Exception («This is an exception on this.content ()»);
}
private static class B
{
public String content ()
{
return »B»;
}
}
private static class A extends B
{
public String content ()
{
return »A»;
}
}
}

Answers:

  1. The code will compile but will fail to run.
  2. The code will compile and on running, it will print »A»
  3. The code will fail to compile
  4. The code will compile and on running, it will print »B»

171. When a servlet call from a client, it receives:

Answers:

  1. Two objects — ServletRequest & ServletResponse
  2. ServletRequest object
  3. ServletResponse object
  4. ServletRequest or ServletResponse
  5. ServletConfig object

172. An ArrayList can be shuffled using the Knuth shuffle method by calling Collections.shuffle() mentod and passing the ArrayList object to it. What is the best way to do a Knuth shuffle on a stack data structure?

Answers:

  1. By using Collection.shuffle() and passing the Stack object to it, similar to ArrayList Knuth shuffle.
  2. Stacks don’t have a shuffle method, so java.util.List has to be implemented, and its shuffle method overridden.
  3. Stacks don’t have a shuffle method, so java.util.Collections has to be implemented, and its shuffle method overridden.

173. What is the result of compiling and running the given code?
public class Test75 {
public static void main (String[] args) {
System.out.println(new A() {{}}.toString());
}
}
class A {
public String toString() { return getClass().getName(); }
}

Answers:

  1. It gets a compiler error.
  2. It compiles, but throws NullPointerException at run-time.
  3. It compiles, runs, and prints “Test75” (without quotation marks)
  4. It compiles, runs, and prints “Test75$1” (without quotation marks).

174. What is the result of compiling and running the given code?
public static void main (String[] args) {
int a = 5;
doubleNumbers (a);
System.out.println (“ 5 doubled is:” + a);
}
private static void doubleNumbers (int a) {
a = 5 * 2;
}
Answers:

  1. 5 doubled is 10
  2. 5 doubled is 5
  3. Compile Time Error
  4. Runtime Error

175. What is the output of the following program?
public class TestClass {
static String str = “Hello World”;
public static void changeIt (String s) {
s = “Good bye world”;
}
public static void main (String[] args) {
changeIt (str);
System.out.println(str);
}
}
Answers:

  1. Compilation error
  2. Hello World
  3. Good bye world

176. Which of the following is true regarding DDL statements?
Answers:

  1. DDL statements are a portion of the SQL standard that is concerned with the creation, deletion and modification of database object like tables.
  2. DDL statements are a portion of the SQL standard is concerned with manipulating the data in a database.
  3. DDL statements can be rolled back.
  4. DDL statements cannot be rolled back.

177. Which of the following are liveness problems of a concurrent application?
Answers:

  1. deadlock
  2. starvation
  3. livelock
  4. synchronization

178. Which statements are true regarding using wildcards in Java code that uses generics? Select all true statements.
Answers:

  1. A wildcard without a bound can be used.
  2. A wildcard with a lower bound can be used.
  3. A wildcard with an upper bound can be used.
  4. A wildcard with both a lower and an upper bound can be used.

179.The EJB specification defines six distinct roles in the application development and deployment life cycle. Which of the following roles is not mentioned in it?
Answers:

  1. Enterprise Bean Provider
  2. EJB Developer
  3. EJB Server Provider
  4. Application Assembler
  5. Deployer
  6. System Administrator

180. Select all true statements:
Answers:

  1. A class cannot be declared final.
  2. Methods and variables can be declared final.
  3. A class can be declared as final abstract.
  4. Application Assembler
  5. Abstract methods can be overridden.

181. Which statements are true about using generics? Select all true statements.
Answers:

  1. Generic types cannot be instantiated with primitive types.
  2. Instances of type parameters cannot be created directly.
  3. Static fields whose types are type parameters cannot be declared.
  4. Casts or instanceof with parameterized types cannot be used.

182. What is the output of the given program?
public class Test102 {
public static void main(String[] args) {
String s = “string102”;
String t = “string” + (9 * s.length() + 3);
String u = “string” + 102;
System.out.println( (s==t) + “-” + (s==u) );
}
}
Answers:

  1. false-false
  2. false-true.
  3. true-false.
  4. true-true

183. Which type(s) cannot be used as generics?

Answers:

  1. primitives
  2. enum types
  3. Inner classes

184. Which of the following can be used to inject URI query parameters into a Java method?

Answers:

  1. @QueryParam
  2. @PathParam
  3. @Param

185. Which of the following can be used to bind HTML form parameters into Java EE web service method?

Answers:

  1. @PathParam
  2. @FormParam
  3. @WebParam

186. Which of the following are ignored by serialization?

Answers:

  1. Static fields
  2. Transient fields
  3. Fields of the base class which are not serializable
  4. Member variables of a serializable class

187. Which term refers to an application’s ability to execute concurrent processes in a timely manner?

Answers:

  1. liveness
  2. responsiveness
  3. robustness
  4. consistency

188. What is required for Message-Driven Bean?

Answers:

  1. @MessageDriven annotation must be used
  2. Class must be public
  3. Must contain any non-default constructor
  4. Must implement MessageListener interface

189. What is required for EJB asynchronous method?

Answers:

  1. Method must return void or implementation of Future interface.
  2. Async method may not throw exceptions.
  3. Async method must have timeout parameter.

190. What will be the output of following code:
List upWork = new ArrayList<>();
upWork.add(«jobs»);
upWork.add(1, «freelancers»);
upWork.add(0, «projects»);
upWork.add(1, «earnings»);
System.out.println(upWork);

Answers:

  1. [«jobs», «freelancers», «projects», «earnings»]
  2. [«freelancers», «projects»,»jobs», «earnings»]
  3. [«earnings», «jobs», «freelancers», «projects»]
  4. [«projects», «jobs», «freelancers», «earnings»]
  5. [«projects», «earnings», «jobs», «freelancers»]
  6. [«freelancers», «jobs», «projects»,»earnings»]

191. What will be the output of following program?
public class UpWork {
private String freelancer;
private boolean busy:
public static void main(String[] args) {
UpWork upw = new UpWork();
System.out.print(«Busy= » + upw.busy);
System.out.print(«, Freelancer = » + upw.freelancer);
}
}
Answers:

  1. Line 6 generates a compiler error.
  2. Line 7 generates a compiler error.
  3. There is no output.
  4. Busy = false, Freelancer = null
  5. Busy = false, Freelancer =
  6. Busy = null, Freelancer = null

192. Which annotation helps to define the table where entity will be stored?

Answers:

  1. @DbTable
  2. @Table
  3. @EntityTable

193. Which method is used to pause thread execution for X seconds, so it might resume its execution after that?

Answers:

  1. wait
  2. sleep
  3. pause

194. We have a thread defined and running, which method is used to terminate its execution?

Answers:

  1. interrupt
  2. terminate
  3. stop

195. Which method is used to wait for thread to fully complete its execution?

Answers:

  1. wait
  2. join
  3. waitComplete

196. What is the correct use of «volatile» in Java?

Answers:

  1. «volatile» can be used with classes to make them thread-safe.
  2. «volatile» can be used with variables to make them thread-safe.
  3. «volatile» can be used with methods to make them thread-safe.
  4. «volatile» can be used with packages to make their classes thread-safe..

197. What is the best way to access a HashMap of SortedSet entries?

Answers:

  1. Map <String, SortedSet> makeSetMap = new HashMap<String, SortedSet>();
    for (String key : makeSetMap.keySet()) { // loop through all manufacturers
    SortedSet cars = makeSetMap.get(key);
    for (String c : cars) { // loop through all cars of that key
    System.out.println(key + » » + c);
    }
    }
  2. Map<String, SortedSet> makeSetMap = new HashMap<String, SortedSet>();
    for (String key : makeSetMap.keySet()) { // loop through all manufacturers
    SortedSet cars = makeSetMap.getValue(key);
    for (String c : cars) { // loop through all cars of that key
    System.out.println(key + » » + c);
    }
    }
  3. HashMap<String, SortedSet> makeSetMap = new HashMap<String, SortedSet>();
    for (String key : makeSetMap.keySet()) { // loop through all manufacturers
    SortedSet cars = makeSetMap.get(key);
    for (String c : cars) { // loop through all cars of that key
    System.out.println(key + » » + c);
    }
    }
  4. HashMap<String, SortedSet> makeSetMap = new HashMap<String, SortedSet>();
    for (String key : makeSetMap.getKeys()) { // loop through all manufacturers
    SortedSet cars = makeSetMap.get(key);
    for (String c : cars) { // loop through all cars of that key
    System.out.println(key + » » + c);
    }
    }

198. Which tool has interface to trigger managed beans?

Answers:

  1. jmonitor.exe
  2. jconsole.exe
  3. java.exe.

199. Which code snippet below generates random numbers between 0 and 0.5?

Answers:

  1. Random generator = new Random();
    double num = generator.nextDouble();
  2. Random generator = new Random();
    double num = generator.nextDouble() * 0.5;
  3. Random generator = new Random();
    double num = generator.nextDouble()/2;

200. What is the method by which two or more applets can communicate with each other within one HTML page?

Answers:

  1. Multiple applets cannot communicate with each other within one HTML page.
  2. getCodeBase()
  3. getDefaultContext()
  4. getAppletContext()

201. Is it possible to make entity as read only?

Answers:

  1. It is not possible to make entity as read only.
  2. By making @org.hibernate.annotations.Entity(mutable = false).
  3. Declare your fields as «protected» and provide only public getter.
  4. By @ReadOnly annotation at the entity level.

202. Which annotation is used to prevent entity field from being saved into the database?

Answers:

  1. @Skip
  2. @Transient
  3. @Ignore.

203. Which annotation defines unique identifier for a JPA entity?

Answers:

  1. @Identifier
  2. @Id
  3. @Sequence

204. Is it possible to ignore a field or fields during persistence ?

Answers:

  1. It is not possible to ignore field or fields during persisence in JPA.
  2. By marking field or field @Transient it will ignore at the time of persistence.
  3. By marking field or field @ReadOnly it will ignore at the time of persistence.
  4. By marking field or field @Volatile it will ignore at the time of persistence.

205. How we can make entity class or method final in JPA ?

Answers:

  1. Mark class or method as final in JPA.
  2. Only class can be marked as final but not method in JPA.
  3. Only method can be marked as final but not class in JPA.
  4. Neither entity class nor methods can be marked as final in JPA.

206. What is the purpose of EL(Expression Language) in Java Web Application?

Answers:

  1. Simplify calculation and writing logic in servlet
  2. Dynamically set/get JavaBean component data
  3. Invoke JavaBean methods.

207. Which statement is true for below code:
String s1 = «UpWork»;
String s2 = «UpWork»;
StringBuilder sb1 = new StringBuilder();
sb1.append(«Up»).append(«Work»);
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
System.out.println(sb1.toString() == s1);
System.out.println(sb1.toString().equals(s1));
Answers:

  1. true is printed out exactly once.
  2. true is printed out exactly twice.
  3. true is printed out exactly three times.
  4. true is printed out exactly four times.
  5. The code does not compile.

208.What is the purpose java.exe?

Answers:

  1. Execute compiled bytecode on jvm.
  2. Compile .java files into bytecode
  3. Compile .java files and run them.

209. Which is the best place to store business logic and look of the page?

Answers:

  1. JSP page must contain both business logic and display logic.
  2. Servlet should contain business logic and JSP page should contain only display logic.
  3. Servlet must contain both display logic and business logic.

210. What is usually inside the WEB-INF folder of a typical Java Web Application?

Answers:

  1. Compiled classes
  2. Compiled and obfuscated javascript libraries
  3. Jar libraries
  4. Deployment descriptors
  5. HTML and JSP pages

211. Which of the following are valid ways to define a thread in Java?

Answers:

  1. Create a subclass of java.lang.Thread class
  2. Create a class that implements java.lang.Runnable
  3. Define method run() in a class
  4. Define method call() in a class

212. Consider the following:
String sub =»hello».substring(2, 3);

Answers:

  1. »ll»
  2. »elo»
  3. »l»
  4. »llo»

213. Which JDK tool converts java file to bytecode?
String sub =»hello».substring(2, 3);

Answers:

  1. bytecodemapper.exe
  2. javac.exe
  3. javaconvert.exe

214. The method foo() defined in the class Quiz has the following signature:
public static double foo(double f)
What can be said about foo()?

Answers:

  1. It is a class method.
  2. It is an instance variable.
  3. It is a class attribute.

215. What is the output of the given console application?
public class Test34 {
public static void main(String[] args) {
int a = 2;
switch(a) {
default: System.out.print(«_default»);
case 0: System.out.print(«_ZERO»);
case 1: System.out.print(«_ONE»);
}
}
}

Answers:

  1. _default
  2. _default_ZERO_ONE
  3. _ZERO_ONE_default.
  4. _ZERO_ONE_default_ZERO_ONE

216. Which of the following statements is false?

Answers:

  1. When a subclass method with the same name and argument as on in its superclass is called, the superclass method is automatically called.
  2. The «super» keyword cannot be used to call an abstract method.
  3. An abstract class can have method implementation.

217. Which method is used in every Java program?

Answers:

  1. System.out.println()
  2. main()
  3. type()
  4. type()
  5. System.out.print()

218. What is the internal implementation of ArrayList in Java?

Answers:

  1. ArrayList consists of nodes connected to each other.
  2. ArrayList internally uses array object to add the elements.
  3. ArrayList has dictionary inside which keys are numbers.

219. What is the internal implementation of ArrayList in Java?
public class Test115 {
{
System.out.print(«_init»);
}
static {
System.out.print(«_static»);
}
public static void main(String[] args) {
System.out.print(«_main»);
}
}

Answers:

  1. _static_main
  2. _init_main
  3. _static_init_main
  4. _init_static_main

220. What is the difference between a try-catch block and a try-catch-finally block?

Answers:

  1. try-catch contains code to execute if an error occurs or not, while try-catch-finally works the same way as try-catch block with the addition of a set of code that will execute whether an error occurs or not.
  2. try-catch contains code to execute whether an occurs or not, try-catch-finally contains code to execute only if an error occurs
  3. try-catch contains code to execute only if an error occurs, try-catch-finally contains code to execute whether an occurs or not
  4. Same thing, different names

221. What is the output of the given program?
public class Test121 extends _Test121 {
{
System.out.print(«_INIT»);
}
static {
System.out.print(«_STATIC»);
}
Test121() {
System.out.print(«_CONST»);
}
public static void main(String[] args) {
new Test121();
System.out.print(«_|»);
new Test121();
}
}
class _Test121 {
{
System.out.print(«_BIN»);
}
static {
System.out.print(«_START»);
}
_Test121() {
System.out.print(«_BASE»);
}
}

Answers:

  1. _START_STATIC_BIN_BASE_INIT_CONST_|_BIN_BASE_INIT_CONST
  2. _START_STATIC_BIN_BASE_INIT_CONST_|_INIT_CONST
  3. _STATIC_START_BIN_INIT_BASE_CONST_|_BIN_INIT_BASE_CONST
  4. _START_STATIC_BIN_INIT_BASE_CONST_|_BASE_CONST

222. Which one is a valid declaration of a boolean?
public class Test121 extends _Test121 {
{
System.out.print(«_INIT»);
}
static {
System.out.print(«_STATIC»);
}
Test121() {
System.out.print(«_CONST»);
}
public static void main(String[] args) {
new Test121();
System.out.print(«_|»);
new Test121();
}
}
class _Test121 {
{
System.out.print(«_BIN»);
}
static {
System.out.print(«_START»);
}
_Test121() {
System.out.print(«_BASE»);
}
}

Answers:

  1. boolean b1 = 0;
  2. boolean b2 = ‘false’;
  3. boolean b3 = false;
  4. boolean b4 = Boolean.false();
  5. boolean b5 = no;

223. Which of the following code snippets will convert variables from long to int and int to long?

Answers:

  1. int i = 5, j = 10, a;
    double k = 15, l = 20, b;
    a = (int) (k + l);
    b = i + j;
  2. int i = 5, j = 10, a;
    double k = 15, l = 20, b;
    a = (int) k + l;
    b = i + j;
  3. int i = 5, j = 10, a;
    double k = 15, l = 20, b;
    a = (int) (k + l);
    b = (double) i + j;
  4. int i = 5, j = 10, a;
    double k = 15, l = 20, b;
    a = (int) k + l;
    b = (double) i + j;

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

Answers:

  1. public double methoda();
  2. public final double methoda();
  3. static void methoda(double d1);
  4. protected void methoda(double d1);

225. Which of the following is a short circuit operator?

Answers:

  1. &&
  2. ||
  3. |
  4. &

226. What will happen when the code below is compiled?
public class Graft {
public static void main(String args[]) {
Graft g = new Graft();
}
protected Graft() {
for(int i =0; i <10; i ++) {
System.out.println(i);
}
}
}
Answers:

  1. A compilation error occurs because constructors cannot be declared protected.
  2. Successful compilation with output 0 to 9
  3. A runtime error occurs because constructors cannot be declared protected.
  4. Successful compilation with output 0 to 10

227. Choose the best way to print “Good bye” to the console, given that string x has character d in it.

Answers:

  1. if(x.contains(“d”)) {
    System.out.println(“Goodbye!”);
    }
  2. if(x.indexOf(“d”) >= 0) {
    System.out.println(“Goodbye!”);
    }
  3. if(x.compareTo(“d”) == 0) {
    System.out.println(“Goodbye!”);
    }

228. What is the best way to return an array from a function?

Answers:

  1. public String[] test(){
    String i[] = new String[5];
    return i;
    }
  2. public String[] test(){
    String i[] = new String[5];
    return i[];
    }
  3. public String test(){
    String i[] = new String[5];
    return i[] ;
    }
  4. public String test(){
    String i[] = new String[5];
    return i;
    }

229. What is the output of the given program?
public class Test103 {
public static void main(String[] args) {
String s = “string103”;
String t = “string” + “103”;
String u = new String(s);
System.out.print( (s==t) + “-” + (s==u) );

Answers:

  1. false-false
  2. true-false
  3. false-true
  4. true-true
  5. Error

5,903 total views, 7 views today