This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question from marcus mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question from marcus mock exam" Watch "question from marcus mock exam" New topic
Author

question from marcus mock exam

Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
The question:
Question 4)
A byte can be of what size
1) -128 to 127
2) (-2 power 8 )-1 to 2 power 8
3) -255 to 256
4)depends on the particular implementation of the Java Virtual machine
answer:
1) A byte is a signed 8 bit integer.

In my opinion to the correct answer be 1, the question should be "A byte can be of what range?"
Do you agree, is it true to say that the size of a byte is implementation dependent, but the range must be unique???
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by leandro oliveira:
...is it true to say that the size of a byte is implementation dependent, but the range must be unique???

The size of a byte will always be 8 bits - the Java specifications say so. In some other languages (C++, for instance), various compilers might very well use different sizes for data types, but Java doesn't do that. All compilers must compile code so that it can be understood by any JVM. Therefore, a byte will always be 1 byte.
However, I agree that the question is worded poorly. The size of a byte will always be 8 bits, the range of a byte is -128 to 127.
I hope that helps,
Corey


SCJP Tipline, etc.
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
Thanks!!! looks clear now!
 
jQuery in Action, 2nd edition
 
subject: question from marcus mock exam
 
Similar Threads
Conversion of Primitives
Widening and narrowing conversion questions
float query
converting C++ type struct to Java class?
size of object