In java , an integer is stored using 32 bits. and its maximum positive value is 2147483647.
This value when represent in binary returns 31 continuous sequence of 1’s. The 32 bit is set to 0 .

To find the binary representation of a negative integer , we take the absolute value of the integer & find its 2’s complement representation . This gives the binary representation of the negative value of that integer.

But what if we get only the binary representation. In these cases if the MSB(most significant bit) is set to 1 then it knows that we are dealing with a negative integer, otherwise its a positive integer.

Hence for negative integers , java just subtracts one from the binary representation an and takes a one’s complement to get the absolute value of the number and then later add a -ve sign.