Dan Chisholm's
Java Programmer Certification Mock Exam

Please Help Save a Tree!

The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer cartridge, save a loose-leaf binder, and save money. If you prefer to work my exams from printed pages, then give your printer a rest and buy my new book.

Today, you can find my book at amazon.com.

Answers: Java Programmer Certification Mock Exam
No.AnswerRemark
1Prints: -128,127   
2Prints: true,true  An int is a 32-bit signed integral value that is stored in two's complement format. The left most bit is the sign bit. The sign bit is set to one for negative numbers and is set to zero for positive numbers.  
3Prints: true,false  Long.equals overrides Object.equals. The Long.equals method compares the data values contained in the Long instances. The StringBuffer.equals method does not override Object.equals. The StringBuffer.equals method compares the reference values of the instances. Two distinct instances of StringBuffer will not have the same reference values; so the equals method returns false. The StringBuffer.hashCode method typically returns a value that is based on the internal address of the StringBuffer instance. Two instances of StringBuffer will not have the same hash code.  
4a  b  c  d  e  doubleValue  floatValue  intValue  longValue  parseDouble   
5Prints: ffF   
6Compile-time error  The Byte.parseByte method returns a primitive byte. A compile-time error is generated as a result of the attempt to assign a primitive byte to a Byte reference variable.  
7Prints: true,true,false  Integer.equals overrides Object.equals. The Integer.equals method compares the data values contained in the Integer instances. If the argument is of type Integer and if the value contained in the argument is the same as the value contained in the instance on which the method is invoked, then the result is true. The equality operator, ==, does not compare data values. Instead, the equality operator compares references. Distinct instances of any two objects can not have the same reference value; so the expression new Integer(i1) == new Integer(i1) is false.  
8b  d  e  Long.parseLong("1L")  Long.parseLong("0x10")  Long.parseLong("1.0")  Long.parseLong is overloaded: one version accepts a String argument that represents an integral value; the other accepts both a String argument and an argument of type int. The int argument represents the radix (i.e. base) of the String argument. The Long.parseLong method is not able to determine the type of the String value by examing a suffix such as L. Any such suffix results in a run-time error. The Long.parseLong method is not able to determine the radix of the String value by examing a prefix such as 0 or 0x. The 0 prefix used to identify octal values is accepted, but the String is parsed as a decimal value. The prefix 0x generates a run-time error. The Long.parseLong method generates a run-time error if the String argument is not formatted as a decimal integer. A floating-point format results in a run-time error.  
9valueOf   
10Prints: true,false,false  Integer.equals overrides Object.equals. The Integer.equals method compares the data values contained in the Integer instances. If the argument is of type Integer and if the value contained in the argument is the same as the value contained in the instance on which the method is invoked, then the result is true. If the argument is not of type Integer then the result is false.  
11b  d  e  Long.parseLong("+1")  Long.parseLong("1L")  Long.parseLong("1.0")  Long.parseLong is overloaded: one version accepts a String argument that represents an integral value; the other accepts both a String argument and an argument of type int. The int argument represents the radix (i.e. base) of the decimal integral value represented by the String argument. The Long.parseLong method is not able to determine the type of the String value by examing a suffix such as L. Any such suffix results in a run-time error. The Long.parseLong method is not able to determine the radix of the String value by examing a prefix such as 0 or 0x. The 0 prefix used to identify octal values is accepted, but the String is parsed as a decimal value. The prefix 0x generates a run-time error. A leading minus sign (-) can be added to indicate a negative value. A leading plus sign (+) results in a run-time error. The Long.parseLong method generates a run-time error if the String argument is not formatted as a decimal integer. A floating-point format results in a run-time error.  
12e  f  parseDouble  valueOf   
13a  b  intValue  parseInt  Integer.valueOf returns an instance of the Integer wrapper class.  
14e  g  parseDouble  valueOf   
15Prints: true,false  Integer.hashCode overrides Object.hashCode. The Integer.hashCode method calculates the hash code based on the value contained in the Integer instance. The StringBuffer.hashCode method does not override Object.hashCode. The StringBuffer.hashCode method typically returns a value that is based on the internal address of the StringBuffer instance. Two instances of StringBuffer will not have the same hash code.  
16Run-time error  An argument of type String must represent a floating-point value. The argument "0x10" represents a hexadecimal integer literal; so a NumberFormatException would be thrown at run-time.  
17Prints: false,true  Integer.equals overrides Object.equals. The Integer.equals method compares the data values contained in the Integer instances. The StringBuffer.equals method does not override Object.equals. The StringBuffer.equals method compares the reference values of the instances. Two distinct instances of StringBuffer will not have the same reference values; so the equals method will return false.  
18b  d  Compile-time error at 2.  Compile-time error at 4.  The Integer.parseInt method is overloaded: one version accepts one argument of type String; the other accepts one String and an int. Both versions of Integer.parseInt return a primitive int. The Integer.intValue method returns the value of the Integer instance as a primitive int. The Integer.valueOf method is overloaded: one version accepts one argument of type String; the other accepts one String and an int. Both versions of Integer.valueOf return an instance of Integer.  
 
Ask a Question
Send an email to me.
 
Java Question and Answer Forums
JavaRanch Big Moose Saloon
Marcus Green's Discussion Forum
java.sun.com Forums, Chat and User Groups
 
Other Resources
Java Language Specification
Java Virtual Machine Specification
Java 2 Platform, Standard Edition, v 1.4.0 API Specification
 
Tutorials
Learning the Java Language
Operator Precedence Chart, Expressions, Statements, Blocks
Programming with Assertions
 

Copyright © 2002-2004, Dan Chisholm
All rights reserved.