Java J2EE Portal
Enterprise Java Station
J2EE curve
Java News / Articles
Java News / Articles
Cryptographic Algorithms - Impact On Application Performance
Creating a new Google Web Toolkit (GWT) application
Implementing Document Management using the Alfresco Enterprise CMS
Processing...
Buy Java, Deals On Software Technology Store
Click here for great deals on computers, laptops, software and books
Test your Java language skills - Quiz 2 PDF Print
Written by Content Team   
Oct 12, 2006 at 08:50 AM
Answers:

Question 1 Correct Choice: C

Explanation
Choice C is the correct answer. For floating-point conversions using %f, the precision is the number of digits after the decimal separator. So 0.2f has 2 as the precision, i.e., there must be 2 digits after the decimal point, rounding off is done if necessary. Here the value is rounded to 222.46. So choices D, E, and F are incorrect.

There are no compiler errors or exceptions, so choices A and B are also incorrect.

You can get more information about the printf method at
http://java.sun.com/j2se/5.0/docs/api/java/io/PrintStream.html

Question 2 Correct Choice: D

Explanation:
Choice D is the correct answer. The FileWriter constructor does not throw FileNotFoundException, if the named file does not exist. In this case, a new file is created by the constructor, if the underlying platform allows this operation. If the named file exists, but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason, the constructor itself throws IOException. So choice D is correct, while choice C is incorrect. Choice A is incorrect because there are no compiler errors in the given code.

Refer to the FileWriter API at
http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileWriter.html

Question 3 Correct Choice: B & C

Explanation:
Choices B and C are the correct answers. The Object class does implement the hashCode method. This default implementation of the hashCode method is in accordance with the default implementation of the equals() method in the Object class. This is what the API says about it -
. Returns a hash code value for the object.
. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of the hashCode method is:

Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.

. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer as the result.

. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects might improve the performance of hashtables.

Also, as much as is reasonably practical, the hashCode method defined by the Object class does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java programming language.)

Choice D is incorrect because the returned number has no relation with the class of the object. Hence, choice E is also incorrect.

More information is available at
http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html

Related
Test your Java language skills - Quiz 1
Get your JSP / Servlet skills certified
A guide to the Sun Certified Java Programmer exam for J2SE 5.0
Learn J2EE programming with passion and for free
Recruiting like crazy


User Comments

Comment by GUEST on 2008-01-09 03:51:09
can add more questions

Comment by keerthiga.tsm@gmail.com on 2008-09-11 03:47:06
explanations are not clear for second question
Your Name / Email Address
Comment
Spam Protection - Please enter the code in the image -

Listen to code




Add This Feed Button

Enter your Email


Java Expert Interviews
Direct Web Remoting (DWR) Creator - Joe Walker
With Direct Web Remoting (DWR) unnecessary complexity is a bug
ChristopherDuncan
Programmers lose because they are unwilling to learn any skill beyond the technical
RichUngerNetBeans
NetBeans was the early bird but has Eclipse caught the worm?
Processing...
Go to top of page  Home |
SiteMap

Copyright 2004 to 2008 Rightrix Solutions. All rights reserved. All product names are trademarks of their respective companies. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Rightrix Solutions and IndicThreads.com are independent of Sun Microsystems, Inc.

Views expressed at IndicThreads.com reflect the views of the authors alone, and do not necessarily reflect those of IndicThreads.com. IndicThreads.com and it's authors are not responsible for reader comments and opinions.

Enterprise Java J2EE JEE Portal >> IndicThreads.com