I am trying to understand how Java stores integer internally. I know all java primitive integers are signed, (except short?). That means one less bit available in a byte for the number.

My question is, are all integers (positive and negative) stored as two's complement or are only negative numbers in two's complement?

I see that the specs says x bit two's complement number. But I often get confused.

For instance:

  int x = 15; // Stored as binary as is?  00000000 00000000 00000000 00001111?
  int y = -22; // Stored as two complemented value? 11111111 11111111 11111111 11101010


Edit

To be clear, x = 15 

   In binary as is: `00000000 00000000 00000000 00001111'
  Two's complement: `11111111 11111111 11111111 11110001`


So if your answer is  all numbers are stored as two's complement then:

  int x = 15; // 11111111 11111111 11111111 11110001
  int y = -22 // 11111111 11111111 11111111 11101010


The confusion here again is the sign says, both are negative numbers. May be I am misreading / misunderstanding it?

Edit
Not sure my question is confusing. Forced to isolate the question:

My question precisely: Are positive numbers stored in binary as is while negative numbers are stored as two's complement?

Some said all are stored in two's complement and one answer says only negative numbers are stored as two's complement.


Question: Does Raspberry Pi 2 support RTOS?
Answer: Looks to me like Xenomai is meant to be source built.  So you should be able to do this.

Someone evidently has precompiled binaries for the regular pi.  The only issue with this will be the kernel: the old armv6 userland will work on the pi 2, but you still need a different kernel for it.

But while armv6 code will run on the pi 2, as noted here (see "How much faster is it?"), if you want to realize the full potential of the new cores, you need stuff that was compiled for armv7 (which will not run on the old pi).

You probably want to cross-compile, since the pi 2 is still really slow compared to a normal desktop.  Fortunately, ready made x86 -> armv7 tool chains are much easier to find than armv6 ones.

If the instructions on the Xenomai site aren't enough, here's a decent looking guide to building a Xenomai system with a raspbian userspace.  Note again though that this means using slower armv6 user land binaries (there is no armv7 raspbian currently, just the armv6 one with an armv7 kernel) -- however it might provide a simple starting point for you to get a kernel running, and then you can tackle building the userland properly as a second stage.