Хотите пройти тесты на Upwork на хороший результат?
Подавайте заявку и мы поможем Вам это сделать!

Do You want to pass tests on Upwork with good scores?
Leave the request and we will help You to do that!

Java Test 2017 (Top 10%)

Share on RedditPin on PinterestEmail this to someoneShare on TumblrShare on LinkedInShare on Google+Tweet about this on TwitterShare on FacebookShare on VK

Мы не гарантируем правильность всех предоставленных ответов.


199 Test Questions:

1. 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:

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

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

Answers:

• ActionAdapter
• MouseListener
• WindowAdapter
• FocusListener

3. 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:

• RMI
• CORBA
• COBRA
• DCOM
• COM

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

Answers:

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

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

Answers:

• 21
• 25
• 8080
• 80
• 137

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

Answers:

• getWarnings()
• getWarned()
• getWarning()
• getError()
• getErrors()

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

Answers:

• findByPrimaryKey()
• ejbGetByPrimaryKey()
• ejbFindPrimayKey()
• getPrimaryKey()
• getFinder()

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

Answers:

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

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

Answers:

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

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

Answers:

• File
• DataOutput
• Directory
• FileDescriptor
• FileOutputStream

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

Answers:

• Collection
• Set
• Map
• SortedSet

12. 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:

• String value=req.getInitParameter(10);
• String value=req.getInitParameter(«product»);
• String value=res.getParameter(«product»);
• String value=req.getParameter(«product»);

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

Answers:

• System.setGarbageCollection();
• System.out.gc();
• System.gc();
• System.free();

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

Answers:

• EJBPassivate()
• EJBActivate()
• EJBRemove()
• EJBOpen()
• EJBActivation()

15. 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:

• always XYZ
• always ZYX
• any of the following: XYZ, XZY, YXZ, YZX, ZXY, ZYX
• any of the following: XYZ, ZYX

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

Answers:

• Accessing a method in another class
• Attempting to open a network socket
• Attempting to open a file
• Traversing each member of an array

17. What protocol is used by the DatagramSocket class?

Answers:

• STCP
• UDP
• TCP
• FTP
• None of the above

18. 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:

• System.out.print(str);
• System.out.print(iOne);
• System.out.print(iTwo);
• System.out.print(iArgs);

19. 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:

• _STATIC_MAIN_INIT_CONST
• _STATIC_MAIN_CONST_INIT
• _INIT_STATIC_CONST_MAIN
• _STATIC_INIT_CONST_MAIN

20. 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:

• <yourLibrary=»whatColorlslt» color=»red»/>
• <yourLibrary:whatColorlslt color=»red»/>
• <yourLibrary color=»red»/>
• <yourLibrary.whatColorlslt color=»red»/>

21.Why would the following code snippet not compile successfully? 

if (mangoList instanceof List<Mango>) { System.out.println(«true»); }

Answers:

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

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

Answers:

• FileOutputStream( FileDescriptor fd )
• FileOutputStream( String n, boolean a )
• FileOutputStream( boolean a )
• FileOutputStream()
• FileOutputStream( File f )

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

Answers:

• java.lang.Math
• java.lang.Boolean
• java.lang.Long
• java.lang.Float

24. Which of the following illustrates correct synchronization syntax?

Answers:

• public synchronized void Process(void){}
• public void Process(){ synchronized(this){ } }
• public void synchronized Process(){}
• public synchronized void Process(){}

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

Note: There may be more than one right answer.

Answers:

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

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

Answers:

• TableModel
• TableColumnModel
• TableSelectionModel
• ListModel

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

Answers:

• HttpSession ses=request.getSession(true);
• HttpSession ses=getSession(true);
• HttpSession ses=request.getSession();
• HttpSession ses=request.getSessionObject(true);
HttpSession ses=response.getSession(true);

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

Answers:

• .
• \
• @
• #

29. 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:

• 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));

• 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));

• 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));

• 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));

30. Select all true statements:

Note: There may be more than one right answer.

Answers:

• Threads exist within a process.
• Every process has at least one thread.
• Processes exist within a thread.
• A thread may belong to more than one process.

31. Which code snippet will check for the existence of the file «text.txt» in the current location?

Note: There may be more than one right answer.

Answers:

• File f = new File(«text.txt»);
System.out.println(f.exists());
• File f = new File(); f.setName(«text.txt»);
System.out.println(f.exists());
• File f = new File(«text.txt»);
System.out.println(f.equals(f));

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

Answers:

• Both can take time in milliseconds as a parameter and will execute when the time is expired.
• Both will wait for another thread’s notify() method before it can execute.
• 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.
• 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.

33. 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:

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

34. Given a method declared as:

public static <E extends Number> List<E> process(List<E> 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:

• ArrayList<Integer> input = null;
ArrayList<Integer> output = null;
• ArrayList<Integer> input = null;
List<Integer> output = null;
• List<Integer> input = null;
List<Integer> output = null;

35. 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; i<a; System.out.println(i++));
}
}

Answers:

@param a Description
@parameter int a Description
@param Description
@parameter a Description

36. 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:

• The code will fail to compile.
• 11 12
• 11 11
• 12 12

37. 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:

• super.printSgnt();
• this.printSgnt();
• printSgnt();
• printBase();

38. 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:

• public void main(String str[])
• static public void main(String str[])
• public static int main(String str[])
• public static void main(String str[])

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

Answers:

• The Servlet interface
• The GenericServlet
• The HttpServlet
• The Servlet package
• The Servlet object

40. 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 &lt; 10; i++)
l.add(i);

String s = «Hello»;

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

Answers:

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

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

Note: There may be more than one right answer.

Answers:

• A message is never partial.
• Messages order is guaranteed.
• Messages are not guaranteed to arrive at destination.
• UDP is MTU independent.
• None of these.

42.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:

• x = y;
• z = x;
• y = (B)x;
• y = (A)y;

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

Answers:

• throw new Exception();
• throws new Exception();
• throw Exception();
• It is not possible to throw an exception programmatically.

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

Answers:

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

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

Answers:

• getWarnings()
• getWarned()
• getWarning()
• getError()
• getErrors()

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

Answers:

• <%! String name=»Patricia» %>
• <%! String name=»Patricia»; %>
• <% String name=»Devyn» %>
• <% public String name=»Devyn»; %>

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

Answers:

• int
• float
• double
• Integer
• Double

48. 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:

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

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

Answers:

• They will get destroyed (They will be destroyed)
• They will keep on running
• Their execution will be halted temporarily
• None of the above

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

Answers:

• contextListenerEvent
• contextListenerInitialized
• contextInitialized
• contextListenerDestroyed

51. 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:

• <yourLibrary=»whatColorlslt» color=»red»/>
• <yourLibrary:whatColorlslt color=»red»/>
• <yourLibrary color=»red»/>
• <yourLibrary.whatColorlslt color=»red»/>

52. 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:

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

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

Answers:

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

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

Answers:

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

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

Answers:

• They are accessible by all servlets in a given web application.
• They are accessible by all servlets in a given session.
• They are accessible by all servlets in a given HTTP request.
• They are accessible by all servlets in a given container.

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

Answers:

• RMI
• CORBA
• DCOM
• COM
• JDBC

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

Answers:

• TX_NOT_SUPPORTED
• TX_BEAN_MANAGED
• TX_REQUIRED
• TX_MANDATORY
• All of the above

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

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

Answers:

• 0
• 1
• 2
• 3

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

Answers:

• put
• doPut
• httpPut
• putHttp

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

Answers:

• SESSIONID
• SERVLETID
• JSESSIONID
• CONTAINERID

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

Answers:

• Create a subclass of java.lang.Thread class
• Create a class that implements java.lang.Runnable
• Define method run() in a class
• Define method call() in a class

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

Answers:

• stay()
• go()
• yield()
• sleep(long millis)

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

Answers:

• -Xlint:unchecked
• -Xlint:-unchecked
• -Xswitchcheck or -Xlint:fallthrough depending on the version of Java
• -classpath or -cp

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

Answers:

• java.rmi.Remote
• rmi
• rmic
• rmijava
• javac

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

Answers:

• DataAccess Object
• Model-View-Controller
• Value Object
• Business Delegate

66. In which class is the notify method defined?

Answers:

• Thread
• Applet
• Runnable
• Object

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

Answers:

• addItem
• append
• insert
• addElement

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

Graphics g = new Graphics();

Answers:

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

69. Which of the following is false?

Answers:

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

70. 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:

• java.io.Serialization
• java.net.Serializable
• java.net.Serialization
• java.io.Serializable
• java.net.io.Serializable

71. 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:

• bridge method
• helper method
• stub method
• raw method

72. 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:

• -try
• -try-catch
• -try-finally
• -try-catch-finally

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

Answers:

• init()
• service()
• finalize()
• destroy()

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

Answers:

• ServletRequest
• HttpServletRequest
• ServletResponse
• HttpServletResponse

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

Answers:

• One
• One per request
• One per session
• None of the above

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

Answers:

• ServletException
• InitializationException
• UnavailableException
• ServletContextException

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

Answers:

• cookies
• hidden form fields
• HTTPS protocol information
• URL rewriting

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

Answers:

• HttpSessionBindingListener
• HttpSessionEventListener
• HttpSessionParameterListener
• HttpSessionAttributeListener

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

Answers:

• dispatch()
• include()
• redirect()
• forward()

80. 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:

• <TWONG:GLOOP/>
• <GLOOP:TWONG/>
• <GLOOP:TWONG></GLOOP:TWONG>
• <TWONG:GLOOP></TWONG:GLOOP>

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

Answers:

• stay()
• go()
• yield()
• sleep(long millis)

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

Answers:

• Client Interface
• Business Logic
• Security
• Data Storage

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

Answers:

• Skeleton object
• Stub object
• skeleton() method
• stub() method
• RMI object

84. 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:

• b
• bcd
• c
• cd

85. Distributed Computing in Java means:

Answers:

• Objects on different machines working together
• Methods on different machines working together
• Methods on same machines working together
• Objects on same machines working together
• Classes on different machines working together

86. 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:

1. <ejb-jar>
2. <enterprise-beans>
3. <session>
4. <ejb-name>Eshop</ejb-name>
5. <home>com.solution.EshopHome</home>
6. <remote>com.solution.Eshop</remote>
7. <local-home>com.solution.EshopLocalHome</local-home>
8. <local>com.solution.EshopLocal</local>
9. <ejb-class>com.solution.EshopBean</ejb-class>
10.
11.
12. </session>
13. </enterprise-beans>
14. </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:

• <session>Stateless</session>
<transaction>Container</transaction>
• <session>Stateful</session>
<transaction>Bean</transaction>
• <session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
• <session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
• <session-type>Stateless</session-type>
<transaction>Container</transaction>

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

Answers:

• Calling interrupt() method of the thread
• Calling sleep() method on thread
• Conclusion of execution of the run() method
• None of the above

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

Answers:

• SESSIONID
• SERVLETID
• JSESSIONID
• CONTAINERID

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

Answers:

• indexed properties
• bound properties
• constrained properties
• limited properties

90. 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:

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

91.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, 3, 2]
• [1, 3, 1]
• [1, 1, 3]
• [1, 1, 2]
• This code will generate an error.

92. 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:

• 10
• 9
• 11
• 13
• 121

93. 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:

• A, B and C
• A and C
• A and B

94. Select all of the following statements that are true?
Note: There may be more than one right answer.

Answers:

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

95. 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:

• A
• B
• Both A and B
• None of the above

96. 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:

1. ObjectInputStream stream =
2.new ObjectInputStream(new FileInputStream(fileName));
3.
4. Handle bookHandle = (Handle) stream.readObject();
5.
6. BookRemoteInterface bookEjbObject = (BookRemoteInterface) XX() ;

Which of the following should be substituted to Method XX() on line 6?

Answers:

• javax.rmi.PortableRemoteObject(bookHandle.getEJBObject(), BookRemoteInterface);
• javax.rmi.PortableRemoteObject(EJBObject, BookRemoteInterface);
• javax.rmi.PortableRemoteObject.narrow(bookHandle.getEJBObject(), BookRemoteInterface.class);
• javax.rmi.PortableRemoteObject.narrow(bookHandle, BookRemoteInterface);
• ookHandle.getEJBObject()

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

Answers:

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

98. 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:

• </libraryPrefix:handlerName>
• </libraryPrefix:handlerName paremeterName=»value»>
• </handlerName>
• <libraryPrefix>

99. 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<String>(3) {{add(«one»); add(«two»); add(«three»); }};
/* 6 */ }
/* 7 */ }

Answers:

• Compiler error regarding line 3 or 4
• Compiler error regarding line 4 or 5
• Code compiles with warnings and runs
• Code compiles without warnings and runs

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

Answers:

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

101. 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?
Note: There may be more than one right answer.

Answers:

• Any instance of A is an instance of B.
• Any instance of B is an instance of A.
• Any instance of C is an instance of B.
• Any instance of B is an instance of C.

102. 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:

• 0
• 1
• An exception will occur
• 4

103. Which of the following is false?

Answers:

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

104. 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:

• The code will fail to compile.
• 10 10 10 10
• 20 20 20 20
• 10 20 10 20

105. 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»);

Note: There may be more than one right answer.

Answers:

• val < 0
• val between 0 and 4
• val between 4 and 9
• val > 9
• val = 0
• No values for val will result in «Test C» being printed.

106. 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:

• one
• two
• TwoTyre
• None of the above

107. 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:

• -try
• -try-catch
• -try-finally
• -try-catch-finally

108. Which of the following is false?

Answers:

• CallableStatement is subclass of PreparedStatement.
• CallableStatement can take input parameters as PreparedStatement.
• CallableStatement can use executeUpdate() method.
• CallableStatement can use execute() method.
• CallableStatement cannot take INOUT parameters.

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

Answers:

• getAppletContext()
• getAppletInfo()
• getParameter()
• getParameters()

110. 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();
}
}
}

Note: There may be more than one right answer.

Answers:

• Polymorphism
• Inheritence
• Abstraction

111. 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:

• true true true true false true
• false true true true false false
• false true true true false true
• false false true true false true

112. 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:

• deadlock
• starvation
• livelock
• liveness

113. 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:

• -try-finally
• -try-clean-finally
• -try-catch-finally
• -try-catch-clean-finally

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

Answers:

• MessageDrivenBean and MessageDrivenContext interfaces
• MessageListener and MessageDrivenBean interfaces
• MessageProducer and MessageDrivenBean interfaces
• ObjectMessage and MessageDrivenBean interfaces

115. 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:

• Parent
• Child
• Class
• null

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

Answers:

• catch(SQLException e)
{
out.println(e.getMessage());
while((e=e.getNextException())!=null)
{
out.println(e.getMessage());
}
}
• catch(SQLException e)
{
out.println(e.getNextException());
while((e=e.getMessage())!=null)
{
out.println(e.getMessage());
}
}
• catch(SQLException e)
{
out.println(e.getMessage());
while((e=e.getEncapsulatedException())!=null)
{
out.println(e.getMessage());
}
}
• catch(ClassNotFoundException e)
{
out.println(e.getMessage());
while((e=e.getNextException())!=null)
{
out.println(e.getMessage());
}
}
• catch(ClassNotFoundException e){

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

117. 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:

• A a = new A2();
• A a = new A.A2();
• A a = new A().new A2();
• A.A2 a2 = new A().new A2();

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

Answers:

• PropertyVetoException
• IllegalArgumentException
• IllegalComponentStateException
• InvalidAttributeValueException

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

Answers:

• Wildcard
• Raw type
• Diamond
• Type parameter

120. Which of the following are “keywords” in Java?
Note: There may be more than one right answer.

Answers:

• default
• NULL
• String
• throws

121. Which of the following statements are true regarding the structure of a WebArchive file?
Note: There may be more than one right answer.

Answers:

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

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

Answers:

• Array.Sort(myString);
• Collections.Sort(myString);
• Arrays.Sort(myString);

123. Skeleton translates the return value or exception into:

Answers:

• Encrypted format
• Decrypted format
• Network format
• File format
• Data format

124. Which statements are true regarding ServletContext Init Parameters in the deployment descriptor?
Note: There may be more than one right answer.

Answers:

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

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

Answers:

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

126. 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:

• 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

• 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

• 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

• The output cannot be predicted.

127. Which of the following statements will not compile?

Answers:

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

128. Which of the following Java technologies support transaction processing?
Note: There may be more than one right answer.

Answers:

• RMI
• CORBA
• JTS
• JMAPI
• JDBC

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

Answers:

• Moving business objects to the client’s machine
• Moving business objects to another server machine
• Moving business objects to the client’s hard drive
• Moving business objects to the client’s RAM
• Moving business objects to another class

130. Choose the correct statements:
Note: There may be more than one right answer.

Answers:

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

131. RMI allows remote communication between:

Answers:

• C++ and Java
• C and Java
• Pascal and Java
• Java and Java
• Java and TCP/IP

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

Answers:

• jdbc:odbc:webx:dsn name
• odbc:jdbc:webx:dsn name
• jdbc:webx:dsn name
• thin:jdbc:odbc:dsn:dsn name
• thick:jdbc:odbc:dsn:dsn name

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

Answers:

• Runnable r = new Runnable();
r.start();
• Runnable r = new Runnable(new Thread({
public void run(){
}
}));
r.start();
• Runnable r = new Runnable(new Thread({
public void run(){
}
}));
r.run();
• Thread t = new Thread(new Runnable(){
public void run(){
}
});
t.start();

134. 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:

• The code will compile but will fail to run.
• The code will compile and on running, it will print »A»
• The code will fail to compile
• The code will compile and on running, it will print »B»

135. 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:

• 2332
• 3232
• 3223
• 2323

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

Answers:

• Two objects — ServletRequest & ServletResponse
• ServletRequest object
• ServletResponse object
• ServletRequest or ServletResponse
• ServletConfig object

137. 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:

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

138. 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:

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

139. What will be the output of the following 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:

• 5 doubled is 10
• 5 doubled is 5
• Compile Time Error
• Runtime Error

140. 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:

• Compilation error
• Hello World
• Good bye world

141. Which of the following is true regarding DDL statements?
Note: There may be more than one right answer.

Answers:

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

142. Which of the following are liveness problems of a concurrent application?
Note: There may be more than one right answer.

Answers:

• deadlock
• starvation
• livelock
• synchronization

143. Which statements are true regarding using wildcards in Java code that uses generics? Select all true statements.
Note: There may be more than one right answer.

Answers:

• A wildcard without a bound can be used.
• A wildcard with a lower bound can be used.
• A wildcard with an upper bound can be used.
• A wildcard with both a lower and an upper bound can be used.

144. 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:

• Enterprise Bean Provider
• EJB Developer
• EJB Server Provider
• Application Assembler
• Deployer
• System Administrator

145. Select all true statements:
Note: There may be more than one right answer.

Answers:

• A class cannot be declared final.
• Methods and variables can be declared final.
• A class can be declared as final abstract.
• Abstract methods can be overridden.

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

Answers:

• getBinaryStream()
• getText()
• getAsciiStream
• getString()
• getUnitStream()

147. Which statements are true about using generics? Select all true statements.
Note: There may be more than one right answer.

Answers:

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

148. 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:

• false-false
• false-true
• true-false
• true-true

149. 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 &amp; j;
System.out.println(x);
}
}

Answers:

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

150. Which type(s) cannot be used as generics?
Note: There may be more than one right answer.

Answers:

• primitives
• enum types
• Inner classes

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

Answers:

• @QueryParam
• @PathParam
• @Param

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

Answers:

• @PathParam
• @FormParam
• @WebParam

153. Which of the following are ignored by serialization?
Note: There may be more than one right answer.

Answers:

• Static fields
• Transient fields
• Fields of the base class which are not serializable
• Member variables of a serializable class

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

Answers:

• liveness
• responsiveness
• robustness
• consistency

155. What is required for Message-Driven Bean?
Note: There may be more than one right answer.

Answers:

• @MessageDriven annotation must be used
• Class must be public
• Must contain any non-default constructor
• Must implement MessageListener interface

156. What is required for EJB asynchronous method?

Answers:

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

157. 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:

• [«jobs», «freelancers», «projects», «earnings»]
• [«freelancers», «projects»,»jobs», «earnings»]
• [«earnings», «jobs», «freelancers», «projects»]
• [«projects», «jobs», «freelancers», «earnings»]
• [«projects», «earnings», «jobs», «freelancers»]
• [«freelancers», «jobs», «projects»,»earnings»]

158. 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:

• Line 6 generates a compiler error.
• Line 7 generates a compiler error.
• There is no output.
• Busy = false, Freelancer = null
• Busy = false, Freelancer =
• Busy = null, Freelancer = null

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

Answers:

• @DbTable
• @Table
• @EntityTable

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

Answers:

• wait
• sleep
• pause

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

Answers:

• interrupt
• terminate
• stop

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

Answers:

• wait
• join
• waitComplete

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

Answers:

• «volatile» can be used with classes to make them thread-safe.
• «volatile» can be used with variables to make them thread-safe.
• «volatile» can be used with methods to make them thread-safe.
• «volatile» can be used with packages to make their classes thread-safe.

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

Answers:

• 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);
}
}
• 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);
}
}
• 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);
}
}
• 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);
}
}

165. Which tool has interface to trigger managed beans?

Answers:

• jmonitor.exe
• jconsole.exe
• java.exe

166. Which code snippet below generates random numbers between 0 and 0.5?
Note: There may be more than one right answer.

Answers:

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

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

Answers:

• Multiple applets cannot communicate with each other within one HTML page.
• getCodeBase()
• getDefaultContext()
• getAppletContext()

168. Is it possible to make entity as read only ?
Note: There may be more than one right answer.

Answers:

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

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

Answers:

• @Skip
• @Transient
• @Ignore

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

Answers:

• @Identifier
• @Id
• @Sequence

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

Answers:

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

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

Answers:

• Mark class or method as final in JPA.
• Only class can be marked as final but not method in JPA.
• Only method can be marked as final but not class in JPA.
• Neither entity class nor methods can be marked as final in JPA.

173. What is the purpose of EL(Expression Language) in Java Web Application?
Note: There may be more than one right answer.

Answers:

• Simplify calculation and writing logic in servlet
• Dynamically set/get JavaBean component data
• Invoke JavaBean methods

174. 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:

• true is printed out exactly once.
• true is printed out exactly twice.
• true is printed out exactly three times.
• true is printed out exactly four times.
• The code does not compile.

175. What is the purpose java.exe?

Answers:

• Execute compiled bytecode on jvm.
• Compile .java files into bytecode
• Compile .java files and run them

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

Answers:

• JSP page must contain both business logic and display logic.
• Servlet should contain business logic and JSP page should contain only display logic.
• Servlet must contain both display logic and business logic.

177. What is usually inside the WEB-INF folder of a typical Java Web Application?
Note: There may be more than one right answer.

Answers:

• Compiled classes
• Compiled and obfuscated javascript libraries
• Jar libraries
• Deployment descriptors
• HTML and JSP pages

178. Which of the following are valid ways to define a thread in Java?
Note: There may be more than one right answer.

Answers:

• Create a subclass of java.lang.Thread class
• Create a class that implements java.lang.Runnable
• Define method run() in a class
• Define method call() in a class

179. Consider the following:

String sub =»hello».substring(2, 3);

What is the value of sub?

Answers:

• »ll»
• »elo»
• »l»
• »llo»

180. Which JDK tool converts java file to bytecode?

Answers:

• bytecodemapper.exe
• javac.exe
• javaconvert.exe

181. 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:

• It is a class method.
• It is an instance variable.
• It is a class attribute.

182. 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:

• _default
• _default_ZERO_ONE
• _ZERO_ONE_default
• _ZERO_ONE_default_ZERO_ONE

183. Which of the following statements is false?

Answers:

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

184. Which of the following statements regarding abstract classes are true?
Note: There may be more than one right answer.

Answers:

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

185. Which of the following cannot apply to constructors?

Answers:

• Name same as class name
• Void return type
• Can have parameters
• Overloading

186. Which method is used in every Java program?

Answers:

• System.out.println()
• main()
• type()
• System.out.print()

187.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:

• 2
• 5
• 4
• That code is invalid.

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

Answers:

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

189. What is the output of the given program?

public class Test115 {
{
System.out.print(«_init»);
}
static {
System.out.print(«_static»);
}
public static void main(String[] args) {
System.out.print(«_main»);
}
}

Answers:

• _static_main
• _init_main
• _static_init_main
• _init_static_main

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

Answers:

• 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.
• try-catch contains code to execute whether an occurs or not, try-catch-finally contains code to execute only if an error occurs
• try-catch contains code to execute only if an error occurs, try-catch-finally contains code to execute whether an occurs or not
• Same thing, different names

191. 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:

• _START_STATIC_BIN_BASE_INIT_CONST_|_BIN_BASE_INIT_CONST
• _START_STATIC_BIN_BASE_INIT_CONST_|_INIT_CONST
• _STATIC_START_BIN_INIT_BASE_CONST_|_BIN_INIT_BASE_CONST
• _START_STATIC_BIN_INIT_BASE_CONST_|_BASE_CONST

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

Answers:

• boolean b1 = 0;
• boolean b2 = ‘false’;
• boolean b3 = false;
• boolean b4 = Boolean.false();
• boolean b5 = no;

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

Answers:

• int i = 5, j = 10, a;
double k = 15, l = 20, b;
a = (int) (k + l);
b = i + j;
• int i = 5, j = 10, a;
double k = 15, l = 20, b;
a = (int) k + l;
b = i + j;
• int i = 5, j = 10, a;
double k = 15, l = 20, b;
a = (int) (k + l);
b = (double) i + j;
• int i = 5, j = 10, a;
double k = 15, l = 20, b;
a = (int) k + l;
b = (double) i + j;

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

Answers:

• public double methoda();
• public final double methoda();
• static void methoda(double d1);
• protected void methoda(double d1);

195. Which of the following is a short circuit operator?
Note: There may be more than one right answer.

Answers:

• &&
• ||
• |
• &

196. 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:

• A compilation error occurs because constructors cannot be declared protected.
• Successful compilation with output 0 to 9
• A runtime error occurs because constructors cannot be declared protected.
• Successful compilation with output 0 to 10

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

Answers:

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

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

Answers:

• public String[] test(){
String i[] = new String[5];
return i;
}
• public String[] test(){
String i[] = new String[5];
return i[];
}
• public String test(){
String i[] = new String[5];
return i[] ;
}
• public String test(){
String i[] = new String[5];
return i;
}

199. 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:

• false-false
• true-false
• false-true
• true-true
• Error