ExamVeda
Login
Home
Data Types and Variables
?

What is the maximum value that can be stored in a byte variable in Java?

Answer & Solution
Correct Answer: Option A
In Java, the byte data type is a signed 8-bit integer type. Being signed means that it can represent both positive and negative values. The maximum value that can be stored in a byte variable is 127.

The reason is that a byte variable uses 8 bits to represent numbers, and one of those bits is used to represent the sign (positive or negative). Therefore, the remaining 7 bits are available to represent the magnitude of the number.

In binary, with 7 bits, you can represent numbers from 0 to 127. The highest bit (leftmost bit) is used for sign, where 0 represents positive and 1 represents negative.

So, the maximum value for a byte variable in Java is 2^7 - 1, which equals 127.

Therefore, the correct answer is Option A: 127.
Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Dinesh Todani
Dinesh Todani 2 years ago
in the question, there wasn't mention about signed or unsigned so the maximum value should be 255
Test Mail
Test Mail 3 years ago
correct ans is A. Byte range is -128 to +127