Sunday, November 6, 2016

Java Test v3 2016 – Upwork Test Answers

Java Test Answer v3 2016 <<<>>> 

90 Answered Test Questions:
1. Which statements are true regarding ServletContext Init Parameters in the deployment descriptor?
Answers:
a. They are set at deployment-time, but accessed at run-time. 
a. They are accessible from any session within that context.
a. They are not set at deployment-time, but accessed at run-time.
a. 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:
a. . 
a. \
a. @
a. #
3. SQLException has a feature of chaining – identify the right code to execute the same from the following options:
Answers:
a. catch(SQLException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } }
a. catch(SQLException e) { out.println(e.getNextException()); while((e=e.getMessage())!=null) { out.println(e.getMessage()); } }
a. catch(SQLException e) { out.println(e.getMessage()); while((e=e.getEncapsulatedException())!=null) { out.println(e.getMessage()); } }
a. catch(ClassNotFoundException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } }
a. 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:
a. It gets a compiler error, because of an attempt to return null from the method with return type “int”.
a. It compiles, but throws NullPointerException at run-time. 
a. It compiles, runs, and prints “null” (without quotes).
a. 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:
a. addItem
a. append
a. insert
a. addElement
6. In which class is the notify method defined?
Answers:
a. Thread
a. Applet
a. Runnable
a. 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:
a. ##
a. #g
a. f#
a. fg
8. Which design pattern reduces network traffic by acting as a caching proxy of a remote object?
Answers:
a. DataAccess Object
a. Model-View-Controller
a. Value Object
a. 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:
a. always XYZ
a. always ZYX
a. any of the following: XYZ, XZY, YXZ, YZX, ZXY, ZYX
a. any of the following: XYZ, ZYX
10. The principal finder method that must be implemented by every entity bean class is:
Answers:
a. findByPrimaryKey()
a. ejbGetByPrimaryKey()
a. ejbFindPrimayKey()
a. getPrimaryKey()
a. getFinder()
11. Which option lists Java access modifiers in the right order from the most permissive to the most restrictive?
Answers:
a. public, protected, no modifier/default/package, private
a. public, no modifier/default/package, protected, private
a. no modifier/default/package, public, protected, private
a. public, protected, private, no modifier/default/package
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:
a. System.out.print(str); 
a. System.out.print(iOne);
a. System.out.print(iTwo);
a. 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:
a. val < 0
a. val between 0 and 4
a. val between 4 and 9
a. val > 9
a. val = 0
a. 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:
a. _STATIC_MAIN_BASE_INIT_CONST
a. _STATIC_MAIN_INIT_BASE_CONST
a. _INIT_STATIC_MAIN_BASE_CONST
a. _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:
a. null
a. 2
a. NaN
a. -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:
a. 0
a. 1
a. An exception will occur
a. 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:
a. Any instance of A is an instance of B.
a. Any instance of B is an instance of A. 
a. Any instance of C is an instance of B.
a. 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:
a. ‘5
a. 5 4 3
a. 5 4 3 1 6 8
a. 5 4 3 7 2 1 6 8
19. Which of the following statements is true?
Answers:
a. public interface RemoteTrain extends java.rmi.Remote
a. public class RemoteTrain extends java.rmi.Remote
a. public interface RemoteTrain extends java.net.Remote
a. public class RemoteTrain extends java.net.Remote
a. 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:
a. java.rmi.Remote
a. rmi
a. rmic
a. rmijava
a. 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:
a. 2
a. 5
a. 4
a. 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:
a. Collection
a. Set
a. Map
a. SortedSet
23. Which of the following is the correct syntax for creating a Session object?
Answers:
a. HttpSession ses=request.getSession(true);
a. HttpSession ses=getSession(true);
a. HttpSession ses=request.getSession();
a. HttpSession ses=request.getSessionObject(true);
a. 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:
a. The code does not compile, because two setters have a formal parameter with the same name.
a. The setters of the JBean class are JavaBean-compliant.
a. The code compiles, but throws a NullPointerException at run-time.
a. The code compiles and runs. 
25. Choose all valid forms of the argument list for the FileOutputStream constructor shown below:
Answers:
a. FileOutputStream( FileDescriptor fd )
a. FileOutputStream( String n, boolean a )
a. FileOutputStream( boolean a )
a. FileOutputStream()
a. 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:
a. EJBPassivate()
a. EJBActivate()
a. EJBRemove()
a. EJBOpen()
a. EJBActivation()
27. Select all true statements:
Answers:
a. An abstract class can have non-abstract methods. 
a. A non-abstract class can have abstract methods.
a. If a non-abstract class implements interface, it must implement all the methods of the interface.
a. 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:
a. -Xlint:unchecked
a. -Xlint:-unchecked
a. -Xswitchcheck or -Xlint:fallthrough depending on the version of Java
a. -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:
a. String value=req.getInitParameter(10);
a. String value=req.getInitParameter(“product”);
a. String value=res.getParameter(“product”);
a. String value=req.getParameter(“product”);
30. Which of these is not an event listener adapter defined in the java.awt.event package?
Answers:
a. ActionAdapter
a. MouseListener
a. WindowAdapter
a. 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:
a. The code will not compile.
a. The code will compile but will give a runtime error.
a. The code will compile and print 2. 
a. The code will compile and print 1.
32. Which of the following are the methods of the Thread class?
Answers:
a. stay()
a. go()
a. yield()
a. sleep(long millis)
33. What protocol is used by the DatagramSocket class?
Answers:
a. STCP
a. UDP
a. TCP
a. FTP
a. None of the above
34. Which statements are true? Select all true statements.
Answers:
a. A member variable can be declared synchronized.
a. A class can be declared transient.
a. A class be declared synchronized.
a. 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:
a. PropertyVetoException
a. IllegalArgumentException
a. IllegalComponentStateException
a. InvalidAttributeValueException
36. X.509 version 3 specifies which of the following?
Answers:
a. A format and content for digital certificates. 
a. The IPSec standard.
a. The Secure Socket Layer.
a. The Data Encryption Standard.
a. 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:
a. The code will fail to compile.
a. 10 10 10 10
a. 20 20 20 20
a. 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:
a. getWarnings()
a. getWarned()
a. getWarning()
a. getError()
a. getErrors()
39. Which of the following are valid ways to define a thread in Java?
Answers:
a. Create a subclass of java.lang.Thread class
a. Create a class that implements java.lang.Runnable
a. Define method run() in a class
a. Define method call() in a class
40. JDBC is based on:
Answers:
a. X/Open CLI (Call Level Interface) 
a. JDBC/Open CLI
a. Java/Open CLI
a. V/OPEN CLI
a. V/CLOSE CLI
41. Which of the following statements regarding abstract classes are true?
Answers:
a. All methods declared in an abstract class must be abstract.
a. Any subclass (abstract or concrete class) of an abstract class must implement all the methods declared in the parent abstract class.
a. Any concrete class must implement all the methods of the parent abstract class which are not implemented in the super hierarchy tree.
a. 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:
a. SESSIONID
a. SERVLETID
a. JSESSIONID
a. CONTAINERID
43. Which method is called by the servlet container just after the servlet is removed from service?
Answers:
a. public void finalize() {// code…}
a. public void destroy() {// code…} 
a. public void destroy()throws ServletException {// code…}
a. public void finalize()throws ServletException {// code…}
44. Which method in the HttpServlet class corresponds to the HTTPPUT method?
Answers:
a. put
a. doPut
a. httpPut
a. putHttp
45. Which of the following illustrates correct synchronization syntax?
Answers:
a. public synchronized void Process(void){}
a. public void Process(){ synchronized(this){ } }
a. public void synchronized Process(){}
a. 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:
a. It initiates a new transaction only when the previous one is concluded.
a. It initiates a new transaction without waiting for the previous one to conclude.
a. It sends the request to the EJB container for initiating a new bean.
a. 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:
a. 0
a. 1
a. 2
a. 3
48. How does the set collection deal with duplicate elements?
Answers:
a. Duplicate values will cause an error at compile time.
a. A set may contain elements that return duplicate values from a call to the equals method.
a. An exception is thrown if you attempt to add an element with a duplicate value.
a. 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:
a. 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;
a. true; true
a. false; false
a. false; true
50. 1 2 <%=23*counter %>
Congratulations!
Which of the following is the correct way to complete the code snippet above?
Answers:
a. 
a. a.
a. 51. Which of the following transaction modes are supported by Enterprise Java Beans?
Answers:
a. TX_NOT_SUPPORTED
a. TX_BEAN_MANAGED
a. TX_REQUIRED
a. TX_MANDATORY
a. 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:
a. _START_STATIC_MAIN_BIN_BASE_INIT_CONST
a. _STATIC_START_MAIN_BIN_BASE_INIT_CONST
a. _STATIC_MAIN_START_BIN_BASE_INIT_CONST
a. _START_MAIN_STATIC_BIN_BASE_INIT_CONST
53. Which distributed object technology is most appropriate for systems that consist entirely of Java objects?
Answers:
a. RMI
a. CORBA
a. DCOM
a. COM
a. 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:
a. (Handle) bookEJBObject()
a. bookEJBObject.getHandle()
a. bookEJBObject.getEJBHandle()
a. 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:
a. [1, 3, 2] 
a. [1, 3, 1]
a. [1, 1, 3]
a. [1, 1, 2]
a. This code will generate an error.
56. Conventionally, which directory do servlet class files get placed on?
Answers:
a. WEB-INF\servlets
a. webapp\servlets
a. WEB-INF\classes
a. WEB-INF\
57. Which is a proper way to declare and throw exception of class XYException?
Answers:
a. class XYException extends Exception {} … throw new XYException();
a. class XYException implements Exception {} … throw new XYException();
a. class XYException extends Exception {} … throw new Exception(“”XYException””);
a. class XYException implements Exception {} … throw new Exception(“”XYException){};
58. Which of the following JDBC methods is used to retrieve large binary objects?
Answers:
a. getBinaryStream()
a. getText()
a. getAsciiStream
a. getString()
a. 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:
a. 1
a. 2
a. 11
a. 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:
a. NumberFormatException
a. ArrayIndexOutOfBoundException
a. IOException
61. Which of the following is a well-known HTTP port?
Answers:
a. 21
a. 25
a. 8080
a. 80
a. 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:
a. -try
a. -try-catch
a. -try-finally
a. -try-catch-finally
63. Which of these interfaces are used by implementations of models for JTable?
Answers:
a. TableModel
a. TableColumnModel
a. TableSelectionModel
a. ListModel
64. Which of the following require explicit try/catch exception handling by the programmer?
Answers:
a. Accessing a method in another class
a. Attempting to open a network socket
a. Attempting to open a file
a. 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:
a. Always XYZ
a. Always ZYX
a. Any of the following: XYZ, XZY, YXZ, YZX, ZXY, ZYX
a. 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:
a. 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)); 
a. 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));
a. 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));
a. 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:
a. They are accessible by all servlets in a given web application. 
a. They are accessible by all servlets in a given session.
a. They are accessible by all servlets in a given HTTP request.
a. They are accessible by all servlets in a given container.
68. Which of the following statements is true of the HashMap class?
Answers:
a. It stores information as key/value pairs. 
a. Elements are returned in the order they were added.
a. It does not permit null keys.
a. 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:
a. RMI
a. CORBA
a. COBRA
a. DCOM
a. 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:
a. 2332
a. 3232
a. 3223
a. 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:
a. A runtime error will occur because class House is not defined as final.
a. Successful compilation and output of “MaintainMethod” at run time. 
a. A compilation error indicating that a class with any final methods must be declared final itself.
a. 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:
a. Random r = new Random(); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt(0,200)); }
a. Random r = new Random(200); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt()); }
a. Random r = new Random(); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt(200)); }
a. 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:
a. The code will fail to compile.
a. 10 10 10 10
a. 20 20 20 20
a. 10 20 10 20
74. Which class contains a method to create a directory?
Answers:
a. File
a. DataOutput
a. Directory
a. FileDescriptor
a. 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:
a. 11
a. 12
a. 21
a. 22
76. Which of the following is the correct syntax for suggesting that the JVM perform garbage collection?
Answers:
a. System.setGarbageCollection();
a. System.out.gc();
a. System.gc();
a. System.free();
77. Why can’t a Graphics object be created using the following statement?
Graphics g = new Graphics();
Answers:
a. The Graphics class is a final class.
a. The Graphics class is an abstract class. 
a. 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:
a. Vector is synchronized, ArrayList is not synchronized
a. Hashtable is synchronized, HashMap is not synchronized
a. Vector is not synchronized, ArrayList is synchronized
a. 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:
a. 0
a. 2
a. 3
a. 4
80. Which of the following is false?
Answers:
a. A scrollable ResultSet can be created in JDBC 2.0 API.
a. The cursor is moved forward using next().
a. The cursor is moved backward using previous().
a. A while loop can be used because next() & previous() methods return false beyond the resultset.
a. 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:
a. public void apple(String s, int i) {}
a. public int apple(int i, String s) {}
a. public void apple(int i, String mystring) {}
a. public void Apple(int i, String s) {}
82. RMI allows remote communication between:
Answers:
a. C++ and Java
a. C and Java
a. Pascal and Java
a. Java and Java
a. 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:
a. java.io.Serialization
a. java.net.Serializable
a. java.net.Serialization
a. java.io.Serializable
a. 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:
a. 0
a. 1
a. 2
a. 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:
a. bridge method
a. helper method
a. stub method
a. 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:
a. one
a. two
a. TwoTyre
a. 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:
a. It gives the servlet an opportunity to clean up resources. 
a. Like try-catch, it is called upon an exception.
a. It is rarely used but can be called to remove a servlet from memory.
a. 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:
a. deadlock
a. starvation
a. livelock
a. 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:
a. Nothing will be printed. 
a. It will print the following output: 0 2 4 6 8
a. Compile time error
a. 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:
a. Name same as class name
a. Void return type
a. Can have parameters
a. Overloading

No comments:

Post a Comment

Earn for Free

http://hiredrmjru.trade/3670784521590/