File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from marcus mock exam

 
Leandro Oliveira
Ranch Hand
Posts: 298
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!! looks clear now!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic