Upwork Java Test answers 2018
Which statements are true regarding ServletContext Init Parameters in the deployment descriptor? A. They are set at deployment-time, but accessed at run-time. B. They are accessible from any session within that context. C• They are not set at deployment-time, but accessed at run-time. D• They are set at deployment-time and can be updated at run-time.
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 option could be used to see additional warnings about code that mixes legacy code with code that uses generics? A• -Xlint:unchecked B• -Xlint:-unchecked C• -Xswitchcheck or -Xlint:fallthrough depending on the version of Java D• -classpath or -cp
A• -Xlint:unchecked
Which of the following symbols are metacharacters supported by the java.util.regex API? • . • \ • @ • #
A• . B• \
How many objects are created by the following code? Object a, b, c, d, e; e = new Object (); b = a = e; e = new Object (); ______________________________________________________________ A• 2 B• 5 C• 4 D• That code is invalid.
A• 2
X.509 version 3 specifies which of the following? A• A format and content for digital certificates. B• The IPSec standard. C• The Secure Socket Layer. D• The Data Encryption Standard. E• A file for digital certificates.
A• A format and content for digital certificates.
Which of these is not an event listener adapter defined in the java.awt.event package? A• ActionAdapter B• MouseListener C• WindowAdapter D• FocusListener
A• ActionAdapter
Select all true statements: A• An abstract class can have non-abstract methods. B• A non-abstract class can have 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.
A• An abstract class can have non-abstract methods.
Which of the following are valid ways to define a thread in Java? A• Create a subclass of java.lang.Thread class B• Create a class that implements java.lang.Runnable C• Define method run() in a class D• Define method call() in a class
A• Create a subclass of java.lang.Thread class
Which exception must a setter of a constrained JavaBean property throw to prevent the property value from changing? A• PropertyVetoException B• IllegalArgumentException C• IllegalComponentStateException D• InvalidAttributeValueException
A• PropertyVetoException
JDBC is based on: A• X/Open CLI (Call Level Interface) B• JDBC/Open CLI C• Java/Open CLI D• V/OPEN CLI E• V/CLOSE CLI
A• X/Open CLI (Call Level Interface)
SQLException has a feature of chaining - identify the right code to execute the same from the following options: A• catch(SQLException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } } B• catch(SQLException e) { out.println(e.getNextException()); while((e=e.getMessage())!=null) { out.println(e.getMessage()); } } C• catch(SQLException e) { out.println(e.getMessage()); while((e=e.getEncapsulatedException())!=null) { out.println(e.getMessage()); } } D• catch(ClassNotFoundException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } } • catch(ClassNotFoundException e){ { out.println(e.getMessage()); } }
A• catch(SQLException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } }
The principal finder method that must be implemented by every entity bean class is: A• findByPrimaryKey() B• ejbGetByPrimaryKey() C• ejbFindPrimayKey() D• getPrimaryKey() E• getFinder()
A• findByPrimaryKey()
Which of the following methods can be used for reporting a warning on a Connection object, Statement object & ResultSet object? A• getWarnings() B• getWarned() C• getWarning() D• getError() E• getErrors()
A• getWarnings()
Which of the following statements is true? A• public interface RemoteTrain extends java.rmi.Remote B• public class RemoteTrain extends java.rmi.Remote C• public interface RemoteTrain extends java.net.Remote D• public class RemoteTrain extends java.net.Remote E• private class RemoteTrain extends java.net.Remote
A• public interface RemoteTrain extends java.rmi.Remote
Which option lists Java access modifiers in the right order from the most permissive to the most restrictive? A• public, protected, <i>no modifier/default/package</i>, private B• public, <i>no modifier/default/package</i>, protected, private C• <i>no modifier/default/package</i>, public, protected, private D• public, protected, private, <i>no modifier/default/package</i>
A• public, protected, <i>no modifier/default/package</i>, private
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? A• Any instance of A is an instance of B. B• Any instance of B is an instance of A. C• Any instance of C is an instance of B. D• Any instance of B is an instance of C.
B• Any instance of B is an instance of A.
Which of the following methods should be invoked by the container to get a bean back to its working state? A• EJBPassivate() B• EJBActivate() C• EJBRemove() D• EJBOpen() E• EJBActivation()
B• EJBActivate()
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); } A• It gets a compiler error, because of an attempt to return null from the method with return type "int". B• It compiles, but throws NullPointerException at run-time. C• It compiles, runs, and prints "null" (without quotes). D• It compiles, runs, and prints "0" (without quotes).
B• It compiles, but throws NullPointerException at run-time.
What protocol is used by the DatagramSocket class? A• STCP B• UDP C• TCP D• FTP E• None of the above
B• UDP
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] + "" ""); } } } } A• '5 B• 5 4 3 C• 5 4 3 1 6 8 D• 5 4 3 7 2 1 6 8
C• 5 4 3 1 6 8
Which of the following is the correct syntax for creating a Session object? A• HttpSession ses=request.getSession(true); B• HttpSession ses=getSession(true); C• HttpSession ses=request.getSession(); D• HttpSession ses=request.getSessionObject(true); E• HttpSession ses=response.getSession(true);
C• HttpSession ses=request.getSession();
Which of the following is the name of the cookie used by Servlet Containers to maintain session information? •A SESSIONID B• SERVLETID C• JSESSIONID D• CONTAINERID
C• JSESSIONID
Which of these interfaces is the most applicable when creating a class that associates a set of keys with a set of values? A• Collection B• Set C• Map D• SortedSet
C• Map
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)); } } A• null B• 2 C• NaN D• -2.0
C• NaN
Which design pattern reduces network traffic by acting as a caching proxy of a remote object? A• DataAccess Object B• Model-View-Controller C• Value Object D• Business Delegate
C• Value Object
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" : "#" ); } } A• ## B• #g C• f# D• fg
C• f#
The JDK comes with a special program that generates skeleton and stub objects that is known as: A• java.rmi.Remote B• rmi C• rmic D• rmijava E• javac
C• rmic
Which of the following are the methods of the Thread class? A• stay() B• go() C• yield() D• sleep(long millis)
C• yield()
Which statements are true? Select all true statements. A• A member variable can be declared synchronized. B• A class can be declared transient. C• A class be declared synchronized. D• A method can be declared synchronized.
D• A method can be declared synchronized.
In which class is the notify method defined? A• Thread B• Applet C• Runnable D• Object
D• Object
Assuming the servlet method for handling HTTPGET requests is doGet(HttpServletRequest req, HTTPServletResponse res), how can the request parameter in that servlet be retrieved? A• String value=req.getInitParameter(10); B• String value=req.getInitParameter("product"); C• String value=res.getParameter("product"); D• String value=req.getParameter("product");
D• String value=req.getParameter("product");
Which of the following statements regarding abstract classes are true? A• All methods declared in an abstract class must be abstract. B• Any subclass (abstract or concrete class) of an abstract class must implement all the methods declared in the parent abstract class. 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.
D• The abstract class may have method implementation.
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; } } A• The code does not compile, because two setters have a formal parameter with the same name. B• The setters of the JBean class are JavaBean-compliant. C• The code compiles, but throws a NullPointerException at run-time. D• The code compiles and runs.
D• The code compiles and runs.
Which of the following methods are members of the Vector class and allow you to input a new element? A• addItem B• append C• insert D• addElement
D• addElement
Choose all valid forms of the argument list for the FileOutputStream constructor shown below: A• FileOutputStream( FileDescriptor fd ) B• FileOutputStream( String n, boolean a ) C• FileOutputStream( boolean a ) D• FileOutputStream() E• FileOutputStream( File f )
E• FileOutputStream( File f )