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
 
Answers: Certified Java Programmer Mock Exam
No.AnswerRemark
1Prints: -128,127  A byte is an 8 bit signed value; so the minimum byte value is -(27) and the maximum value is (27 - 1).  
2Prints: -32768,32767  A short is a 16 bit signed value; so the minimum short value is -(215) and the maximum value is (215 - 1).  
3Prints: 1111111,177,127,7f  A byte is an 8 bit signed value. The left most bit is the sign bit. The sign bit is set to zero for positive numbers and is set to one for negative numbers. The most positive byte value is represented as a sign bit that is set to zero and all of the other bits set to one. The Integer.toBinaryString method does not print leading zeros; so only seven bits are printed. An eight bit binary value is represented as three octal digits. The first of the three digits represents the left most two bits of the binary value. In this case, the left most two bits are zero and one. The second octal digit represents the next three bits of the binary value. The last of the octal digits represents the right most three bits of binary value. Note that the Integer.toOctalString method does not print a leading zero as is required for an octal literal value. An eight bit binary value is represented as two hexadecimal digits. The left hex digit represents the left most four bits of the binary value. The right hex digit represents the right most four bits of the binary value.  
4Prints: 7f,ffff,7fff  A byte is an 8 bit signed value. A char is a 16 bit unsigned value. A short is a 16 bit signed value. The left most bit of a signed value is the sign bit. The sign bit is zero for positive numbers and one for negative numbers. The maximum byte value in hexadecimal format is 7f and in decimal format is 127. The minimum byte value in hexadecimal format is 80 and in decimal format is -128. The byte value of decimal -1 is ff in hexadecimal.  
5Prints: 80000000,7fffffff  An int is a 32 bit signed value. The left most bit is the sign bit. The sign bit is zero for positive numbers and one for negative numbers.  
6b  d  '\u0000' to '\uffff'  0 to 65535  A char is a 16 bit unsigned value; so none of the char values are negative and the minimum value is zero. The maximum value is 216 - 1.  
7b  d  f  0x0000 to 0xffff  0 to 0177777  0 to 65535  A char is a 16 bit unsigned value; so none of the char values are negative and the minimum value is zero. The maximum value is 216.  
8b  c  e  The maximum char value is 0xffff. The maximum byte value is 127 = 0x7f. The hex value 0xff is of type int, and the decimal value is 255. The maximum positive value of type byte is 127. The value 255 is beyond the range of type byte; so 255 can not be assigned to type byte without an explicit cast. The assignment expression b3 = (byte)0xff would assign the value -1 to variable b3.  

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