All integer literals are of type int (if not the suffix L or L ). Thus, in the first case, you save the int in byte . Narrowing such a transformation is not allowed without casting, except that if the right side is a constant, it allows, if the value is in the range, from -128 to 127 . 0b11111111 is 255 but is not in the range.
As for why int i = 0b11111111111111111111111111111111 allowed: it is pretty much "because JLS says that." In fact, this particular example appears in JLS 3.10.1 . There is a rule that decimal literals of type int cannot exceed 214743647 (except for the specific case of -2147483648 ), but there is no rule about binary literals, except that they must fit in 32 bits.
As I mentioned in the commentary, the second question is really a question about the style preference of the programmers who wrote the code, and it is impossible to answer.
source share