oDesk Java v3 Test Answers 2015



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?
Ans: a) </libraryPrefix:handlerName>

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 _________.
Ans: a) bridge method

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" );
Ans: a) val<o
b) val between o and 4
e) val=0


Assuming the servlet method for handling HTTPGET requests is doGet(HttpServletRequest req, HTTPServletResponse res), how can the request parameter in that servlet be retrieved?
Ans: d) String value=req.getParameter(“product”);

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

Ans: a) FileOutputStream(FileDescriptor fd)
b) FileOutputStream(String n, Boolean a)
e) FileOutputStream(File f)


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:
Ans: a) public void apple(String s, int i) {}
d) public void Apple(int I, String s) {}


Conventionally, which directory do servlet class files get placed on?
Ans: c) WEB-INF/classes

How does the set collection deal with duplicate elements?

Ans: d) The add method returns false if you attempt to add an element with a duplicate value.

How many objects are created by the following code?
Object a, b, c, d, e;
e = new Object ();
b = a = e;
e = new Object ();
Ans: a) 2

How many objects are created in the given code?

Object x, y, z;
x = new Object();
y = new Object()
Ans: c) 2

How many objects are created in the given code?
Object x, y, z;
x = new Object();
y = new Object();
Ans: c) 2

In which class is the notify method defined?

Ans: d) Object

JDBC is based on:

Ans: a) X/Open CLI (Call Level Interface)

RMI allows remote communication between:

Ans: d) Java and Java

Select all correct statements:
Ans: a) Vector is synchronized, ArrayList is not synchronized
b) Hashtable is synchronized, HashMap is not synchronized


Select all true statements:
Ans: a) An abstract class can have non-abstract methods
c) If a non-abstract class implements interface, it must implement all the methods of the interface.
d) If a non-abstract class inherits abstract methods from its abstract superclass, it must implement the inherited abstract methods.


SQLException has a feature of chaining - identify the right code to execute the same from the following options:
Ans: a) catch(SQLException e)
{
Out.printIn(e.getMessage());
While((e=e.getNextException())!=null)
{
Out.printIn(e.getMessage());
}
}


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?
Ans: b) bookEJBObject.getHandle()

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

Ans: c) rmic

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

Ans: a) findByPrimaryKey()

The transaction attribute of a bean is set to 'TX_REQUIRES_NEW.' What can be inferred about its behavior?
Ans: d) The bean manages its own transaction

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?

Ans: b) Any instance of B is an instance of A
c) Any instance of C is an instance of B.


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] + " " );
}
 }
Ans: b) ArrayIndexOutOfBoundException

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);
          }
}
Ans: a) 2332

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] + "" "" );
}
}      
}      
}
Ans: c) 5 4 3 1 6 8

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" );
}
}
}
Ans: c) -try-finally

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) );
}
}
Ans: d) false; true

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" );
}
}
Ans: a) _STATIC_MAIN_BASE_INIT_CONST

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" );
}
}
Ans: a) _START_STATIC_MAIN_BIN_BASE_INIT_CONST

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; }
Ans: c)11

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; }
}
Ans: b) 12

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();
}
}
}
Ans: c) Any of the following : XYZ, XYZ, XYZ, XYZ, XYZ, XYZ

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();
}
}
}
Ans: c) any of the following: XYZ, XYZ, XYZ, XYZ, XYZ, XYZ

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" : "#" );
}
}
Ans: c) f#

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);
}
}
Ans: b) 2

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);
}
}
Ans: b) it complies, but throws NullPointerException at run-time.

What protocol is used by the DatagramSocket class?

Ans: b) UDP

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;
}
 }
Ans: a) System.out.print(str);
d) System.out.print(Args);

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];
}
}
Ans: d) 4

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;
}
}
Ans: c) 20 20 20 20

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;
}
}
Ans: c) 20 20 20 20

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));
}
 }
Ans: c) NaN

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);
}
}
Ans: c) The code will compile and print 2.

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();
}
}
Ans: b) Successful compilation and output of “MaintainMethod” at run time.

Which class contains a method to create a directory?
Ans: a) File

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

Ans: c) Value Object

Which distributed object technology is most appropriate for systems that consist entirely of Java objects?
Ans: a) RMI

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?

Ans: b) CORBA

Which exception must a setter of a constrained JavaBean property throw to prevent the property value from changing?
Ans: a) PropertyVetoException

Which is a proper way to declare and throw exception of class XYException?
Ans: a) class XYException extends Exception {}

Throw new XYExceptoin();

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

Ans: b) doPut

Which method is called by the servlet container just after the servlet is removed from service?
Ans: b) public void destroy() {// code…}

Which of the following are the methods of the Thread class?
Ans: c) yield()
d) sleep(long millis)

Which of the following are valid ways to define a thread in Java?
Ans: a) Create a subclass of java.lang.Thread class
b) Create a class that implements java.lang.Runnable

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

Ans: c) Random r = new Random();
for (int i = 0; i< 5; i++) {
System.out printIn(r.nextInt(200));
}

Which of the following code snippets will take transform input string "2012/06/05" to output string "05 - 06 - 2012" ?
Ans: a) String dateString = “2012/06/05”;
          
Date date = new SimpleDateFormat(“yyyy/MM/dd”).parse(dateString);
SimpleDateFormat sdf = new SimpleDateFormat(“dd-MM-yyyy”);
System.out.printIn(sdf.format(date));
Which of the following illustrates correct synchronization syntax?
Ans: b) public void Process(){
          Synchronized(this){
}
}
d) public synchronized void Process(){}

Which of the following interfaces makes it possible for Java to save an object to a file and turn it into a data stream?
Ans: d) java.io.Serializable

Which of the following is a well-known HTTP port?
Ans: d) 80

Which of the following is false?

Ans: c) A while loop can be used because next() & previous() methods return false beyond the resultset
d) A while loop can be used because next() & previous() methods return -1 beyond the resultset

Which of the following is the correct syntax for creating a Session object?
Ans: a) HttpSession ses=request.getSession(true);
c) HttpSession ses=request.getSession();

Which of the following is the correct syntax for suggesting that the JVM perform garbage collection?
Ans: c) System.gc();

Which of the following is the name of the cookie used by Servlet Containers to maintain session information?
Ans: c) JSESSIONID

Which of the following JDBC methods is used to retrieve large binary objects?
Ans: a) getBinaryStream()

Which of the following methods are members of the Vector class and allow you to input a new element?
Ans: d) addElement

Which of the following methods can be used for reporting a warning on a Connection object, Statement object & ResultSet object?
Ans: a) getWarnings()

Which of the following methods should be invoked by the container to get a bean back to its working state?
Ans: b) EJBActivate()

Which of the following require explicit try/catch exception handling by the programmer?
Ans: b) Attempting to open a network socket
c) Attempting to open a file


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

Ans: a) It stores information as key/value pairs

Which of the following statements is true?
Ans: a) public interface Remote Train extends java.rmi.Remote

Which of the following statements regarding abstract classes are true?
Ans: c) any concrete class must implement all the methods of the parent abstract class which are not implemented in the super hierarchy tree.
d) The abstract class may have method implementation.

Which of the following transaction modes are supported by Enterprise Java Beans?
Ans: e) All of the above

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

Ans: a) TableModel
b) TableColumnModel

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

Ans: c) Map

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

Ans: a) ActionAdapter

Which option could be used to see additional warnings about code that mixes legacy code with code that uses generics?
Ans: a) –Xlint:unchecked

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

Ans: a) public, protected, <i>no modifier/default/package</i>, private

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);
 }
 }
Ans: a) [1, 3, 2]

Which statement is true about the given code?
public class Test78 {
public static void main(String[] args) throws Exception {
new JBean().setHeight(1).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 set Density (int d) { this.density = d; return this; }
}
Ans: d) The code compiles, but throws a NullPointer-compliant


Which statement is true regarding ServletContext Initialization Parameters in the deployment descriptor?
Ans: a) They are accessible by all servlets in a given web application

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

Ans: a) They are set at deployment-time, but accessed at run-time.
d) They are set at deployment-time and can be updated at run-time.


Which statements are true? Select all true statements.
Ans: d) A method can be declared synchronized.

Why can't a Graphics object be created using the following statement?
Graphics g = new Graphics();
Ans: b) The Graphics class is an abstract class.

X.509 version 3 specifies which of the following?

Ans: a) A format and content for digital certificates.


 
Share on Google Plus

About Unknown

I'm a professional web designer and wordpress theme developer. I also like to write blog post.
    Blogger Comment
    Facebook Comment

3 comments:

  1. Het gebied van de computerwetenschappen dat bekend staat als kunstmatige intelligentie (AI) heeft geleid tot een technologische revolutie die de manier verandert waarop mensen omgaan met technologie en het milieu.

    ReplyDelete