I am also in the process of preparing for JCP. So please correct me if my understanding is incorrect
A byte is represented by 8 bits of which the leftmost bit is the sign bit. This is 1 for negative numbers and 0 for positive numbers. The range for a byte is -128(1000 0000) to 127(0111 1111).
When byte a =(byte)127 is evaluated, 127 is in the range for a byte, so the output is 127.
For byte b=(byte)128, this is represented in binary as 1000 0000 which is equivalent to -128.
For byte c=(byte)255, this is represented as 1111 1111. This is a negative number. A negative of a number is found by taking 2s complement.(taking 1's complement and adding 1). So if we reverse this process on this number(subtracting 1 and taking 1s complement), we get -1.
For byte d=(byte)256, this is represented in binary as 1 0000 0000. Since this has 9 bits and a byte is represented with 8 bits, the 9th bit is discarded and we get 0 as the result.