2 MILLIONS+ USERS, 14+ YEARS, 100+ COUNTRIES
Visit our Website
Whizlabs Learning Center HOME OCAJP 5/6 FREE TEST FULL TEST(S) FREE TEST
Friday, 26 June 2015, 1:58 AM Finished Friday, 26 June 2015, 1:58 AM 21 secs out of 15.00 ( %) FAIL
Question uestion
Which of the given given options is the result of compiling and running the given code?
Not answered Mark for Mark for Review
public class Test { int a; int[] b; public void f() { a = 0; b = new int[]{1,2}; change(b, a); System.out.println(a + " " + b[0] + " "); } public void change(int[] x, int y) { y = 10; x[0] = 10; }
public static void main(String[] args) { Test obj = new Test();
obj.f(); }
} Please select : a. Prints 0 10 b. Prints 10 10 c. Prints 0 0 d. Does not compile
Choice A is the correct answer.
In Java, method arguments are always passed by value. In the case of primitive type arguments, this means that the primitive variable's value is copied into the parameter received within the called method.
In the case of object reference arguments, a bitwise copy of the reference variable is passed to the method. Then both the reference variable in the calling method and its copy refer to the same object in memory. Here, the change method takes 2 arguments - one is an array object reference 'b' and the other is a primitive type 'a'. Modifying the copy of the int variable within the method does not affect the actual variable 'a', so the value of 'a' remains 0.
However, modifying the contents of the array within the method affects the same array object referred by the variable 'b'. So the value of b[0] changes to 10. Thus, choice A is correct.
Hence, choices B, C, and D are automatically incorrect.
Reference: http://java.sun.com/docs/books/tutorial/java/javaOO/arguments.html The correct answer is: Prints 0 10
Question
Which of the given options is the output produced by the code fragment given below?
Not answered Mark for Review
int i=0,j=0; boolean b=((i++==++j && i--==--j)); System.out.println(b+" "+i); Please select : a. false 0 b. true 0 c. false 1 d. true 1
Choice C is the correct answer.
First, 'i' and 'j' are 0. When we compare i++==++j, the value of 'j' is incremented to 1, while the value of 'i' remains 0. Only after the comparison, the value of 'i' is i ncremented by 1. Hence, comparing 0 to 1 gives false. The '&&' operator evaluates the right side expression, only if the left side expression is true. Hence, the false value is assigned to 'b' and the value of 'i' r emains 1.
Hence, choices A, B, and D are automatically incorrect. The correct answer is: false 1
Question
Which of the given options is a text-based document that describes how to process a request to create a response?
Not answered Mark for Review
Please select : a. Servlet b. JSP c. HTML page d. XML page
Choice B is the correct answer.
A JSP (Java Server Pages) is a text-based document that describes how to process a request to create a response. It provides a simplified and fast way to create dynamic web content by allowing Java code and certain pre-defined actions to be embedded into static content.
Both servlets and JSP pages describe how to process a request (from an HTTP client) to create a response. While servlets are expressed in the Java programming language, JSP pages are text-based documents that include a combination of HTML and JSP tags, Java code and other information. So choice A is incorrect.
Choices C and D are incorrect, because HTML and XML documents contain only static code.
Reference: http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/web_tier/dynamic_content/ The correct answer is: JSP
Question
Which of the given options contain the correct set of methods for getting and setting the value of a boolean property 'bright', according to JavaBeans
Not answered
naming standards? Select two choices.
Mark for Review
Please select : a. public void setBright(boolean bright)
public boolean getBright() b. public void setBright(boolean bright)
public boolean isBright() c. public void setbright(boolean bright)
public boolean getbright() d. public void setbright(boolean bright)
public boolean isbright()
Choices A and B are the correct answers.
According to the JavaBeans naming standards, if the property name is 'x' and the type is Type, the accessor method is of the form:
Type getX()
and the mutator method is of the form:
void setX(Type newValue)
However, boolean property also uses another convention:
boolean isX()
void setX(boolean newValue)
So choice C is i ncorrect, while choices A and B are correct.
The name of the property is capitalized in the accessor and mutator methods. So choice D is incorrect. The correct answer is: public void setBright(boolean bright)
public boolean getBright(), public void setBright(boolean bright)
public boolean isBright()
Question
Which of the given statements are true about interfaces? Select two choices.
Not answered Mark for Review
Please select : a. Their methods are implicitly abstract. b. Their methods must be marked public. c. Their variables must not be modified by implementing classes.
d. Their methods must be defined by all implementing classes.
Choices A and C are the correct answers.
Choice C is correct, because the variables in an interface are implicitly final, and hence must not be modified by the implementing classes. Interface methods are implicitly public and abstract, hence choice A is also correct.
They need not be marked public explicitly. Hence, choice B is incorrect.
Choice D is incorrect, because interface methods need not be defined by the implementing class, if it is abstract. This statement would be true only for concrete classes. The correct answer is: Their methods are implicitly abstract., Their variables must not be modified by implementing classes.
Question
Which of the given packages contains the interface(s) related to serialization?
Not answered Mark for Review
Please select : a. java.util b. java.net c. java.io d. java.serial
Choice C is the correct answer.
The Serializable interface is to be implemented by a class to allow its object state to be serialized. This interface belongs to the java.io package. The java.net package contains classes for networking. Hence, choice B is incorrect.
Choice A is incorrect, because the java.util package contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).
Choice D is incorrect, because there is no package called java.serial. The correct answer is: java.io
Question
You want to develop an applet, which has the permissions to write data to files on the local disk and also use socket communication. It must support a
Not answered
pluggable look and feel. Which of the given packages need to be imported? Select three choices.
Mark for Review
Please select : a. java.net b. java.io c. java.url d. java.awt e. javax.swing
Choices A, B, and E are the correct answers.
Choice A is correct, because the networking classes from the java.net package are useful for socket communication.
The input and output stream classes in the java.io package are used for reading and writing to files.Hence, choice B is correct.
Choice E is also correct, because pluggable look and feel for GUI components is supported by the Swing technology.
Choice C is incorrect, because java.url is an invalid package name.
Choice D is also incorrect, because AWT does not support pluggable look and feel. The correct answer is: java.net, java.io, javax.swing
Question Not answered
You want to print 'Yes' if a character primitive contains 0 or 1 and 'No' if it contains 2 or more. Which of the given code fragments correctly achieves this?
Mark for Review
Please select : a. if(c=='0' || c=='1')
System.out.println("Yes"); else if(c>='2') System.out.println("No");
b. if(c=='0' && c=='1') System.out.println("Yes"); else if(c>'2') System.out.println("No"); c. if(c='0' || c='1')
System.out.println("Yes"); else if(c>='2') System.out.println("No");
d. if(c=="0" || c=="1")
System.out.println("Yes"); else if(c>="2") System.out.println("No");
Choice A is the correct answer.
We need to print 'Yes' if a character primitive contains 0 or 1 and 'No' if it contains 2 or more. For this, we compare the value in the character to '0' and '1' using the 'if' statement and the '==' operator.
Choice B is incorrect, because it uses the '&&' operator instead of the '||' operator, the value cannot be equal to both '0' and '1'.
Choice C is incorrect, because it uses the '=' operator instead of the '==' operator.
Choice D is incorrect, because it uses double quotes instead of single quotes for representing character literals. The correct answer is: if(c=='0' || c=='1')
System.out.println("Yes"); else if(c>='2') System.out.println("No");
Question
Which of the given assignments are legal?(Choose two)
Not answered Mark for Review
Please select : a. String s=null; b. String s="null"; c. String s='null'; d. String s=new String(null);
Choices A and B are the correct answers.
A String is an Object and it is legal to assign a null to any object reference in Java. So choice A is correct. Anything within double quotes is a String literal, so "null" is a String literal and it is legal to assign it to a String object reference.
Choice C is incorrect, because only one character literal can be specified within single quotes.
Choice D is incorrect, because passing a null to the String class constructor causes compiler error. The correct answer is: String s=null;, String s="null";
Question
Which of the given options of the java tool display the version information? (Choose two)
Not answered Mark for Review
Please select : a. -ver b. -version c. -shower d. -showversion
Choices B and D are the correct answers.
Both the options -version and -showversion can be used with the java tool to display the product version information. The difference is that the -version switch displays the version information and exits, while the -showversion switch displays more information than just the version information.
Choices A and C are incorrect, because they are invalid options. The correct answer is: -version, -showversion
Question
Which of the given statements is not true about RMI technology?
Not answered Mark for Review
Please select : a. It uses object serialization. b. It is not supported in J2ME. c. It is defined i n the java.rmi package. d. It supports dyamic class loading.
Choice B is the correct answer.
RMI (Remote Method Invocation) allows the methods of remote Java objects to be invoked from other Java virtual machines, possibly on different hosts.
Java RMI is available for both Java 2 Platform, Standard Edition (J2SE) and Java 2 Platform, Micro Edition (J2ME), so choice B is correct.
Object serialization is the mechanism used by RMI to pass objects between JVMs, either as arguments or as return type in a method invocation from a client to a server. So choice A is true.
The RMI API is defined in the java.rmi package, so choice C is also true.
Choice D is true, because RMI also provides a facility for dynamically loading the class definitions for the actual types of objects passed as parameters and return values for remote method invocations from network locations specified by the transmitting endpoint.
Reference: http://java.sun.com/javase/technologies/core/basic/rmi/index.jsp [^] The correct answer is: It is not supported in J2ME.
Question
Which of the given technologies will you use to send e-mail with XML attachments using SMTP?
Not answered Mark for Review
Please select : a. JavaMail b. JMail c. JMS d. JXMail
Choice A is the correct answer.
The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications. It is possible to send an e-mail with XML attachments via SMTP using JavaMail. JMS is for asynchronous messaging, not for sending e-mail. So choice C is incorrect.
Choices B and D are invalid terminologies, hence are incorrect.
Reference: http://www.javaworld.com/javaworld/jw-10-2001/jw-1026-javamail.html The correct answer is: JavaMail
Question
Which of the given statements are true about message-driven beans? Select two choices.
Not answered Mark for Review
Please select : a. They support bean-managed transactions. b. They support bean-managed persistence.
d. They do not maintain client conversational state.
Choices A and D are the correct answers.
Message-Driven Beans (MDB) support both bean-managed transactions and container-managed transactions. Similar to stateless session beans, messagedriven beans are also stateless components. Hence, they do not maintain client state across multiple methods. Hence, choice D is correct.
However, they do not support persistence; bean-managed persistence is supported only by entity beans. So choice B is incorrect.
Choice C is incorrect, because methods of message-driven beans cannot be directly i nvoked by clients. Clients simply send messages to a destination, but the messages are delivered to the listening MDBs. The correct answer is: They support bean-managed transactions., They do not maintain client conversational state.
Question
Which of the following statements are true regarding the UML diagram? (Choose two)
Not answered Mark for Review
Please select : a. The diagram is invalid. b. The diagram is valid. c. The diagram would also be valid if the word <> is removed. d. The diagram would also be valid if the word <> is replaced by <>.
Choices B and C are the correct answers.
The diagram shows a valid way to represent an interface. In UML, interfaces are denoted in italics, with the word <> added above the name. Abstract classes are also represented in italics, so the diagram would indicate that Pet is an abstract class if the word <> is removed. The diagram would still be valid. Hence, choice C is correct.
Choice A is incorrect because the diagram is valid.
The diagram would not be valid if the word <> is replaced by <>. So choice D is also incorrect.
Reference: http://www.objectmentor.com/resources/articles/umlClassDiagrams.pdf The correct answer is: The diagram is valid., The diagram would also be valid if the word <> is removed.
Question
Which of the given options represents the UML notation 0..1?
Not answered Mark for Review
Please select : a. Multiplicity b. Navigability c. Roles d. Attributes
Choice A is the correct answer.
Multiplicity is the number of instances of a class that participates in a relationship. It determines the number of references required in the other class participating in an association relationship.
The UML notation 0..1 represents the multiplicity. It stands for "one or zero". Navigability refers to the direction, i n which it is possible to navigate an association relationship, so choice B is incorrect.
Choice C is incorrect, because a role is used to name the purpose of a particular class participating in an association relationship.
Choice D is incorrect, because attributes are represented by their names.
Reference: http://www.agilemodeling.com/artifacts/classDiagram.htm The correct answer is: Multiplicity
Finish review
QUIZ NAVIGATION
Show all incorrect Show all correct Show one page at a time Finish review
© 2015 Whizlabs Software Pvt. Ltd. | All Rights Reserved