title: How to use the unsigned Integer in Java 8 and Java 9?
body: <p>In the Oracle &quot;Primitive data types&quot; <a href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html" rel="noreferrer">page</a>, it mentions that Java 8 adds support for unsigned ints and longs:</p>
  <blockquote>
  <p><code>int</code>: By default, the <code>int</code> data type is a 32-bit signed two's complement integer, which has a minimum value of −2<sup>31</sup> and a maximum value of 2<sup>31</sup>−1. <strong>In Java SE 8 and later, you can use the <code>int</code> data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 2<sup>32</sup>−1.</strong> Use the <code>Integer</code> class to use <code>int</code> data type as an unsigned integer. See the section The Number Classes for more information. Static methods like <code>compareUnsigned</code>, <code>divideUnsigned</code> etc have been added to the <code>Integer</code> class to support the arithmetic operations for unsigned integers.</p>
  <p><code>long</code>: The <code>long</code> data type is a 64-bit two's complement integer. The signed <code>long</code> has a minimum value of −2<sup>63</sup> and a maximum value of 2<sup>63</sup>−1. <strong>In Java SE 8 and later, you can use the <code>long</code> data type to represent an unsigned 64-bit <code>long</code>, which has a minimum value of 0 and a maximum value of 2<sup>64</sup>−1.</strong> Use this data type when you need a range of values wider than those provided by int. The <code>Long</code> class also contains methods like <code>compareUnsigned</code>, <code>divideUnsigned</code> etc to support arithmetic operations for unsigned <code>long</code>.</p>
  </blockquote>
  <p>However, I find no way to declare an unsigned long or integer. The following code, for example, gives a compiler error message of &quot;the literal is out of range&quot; (I'm using Java 8, of course), when it should be in range (the value assigned is precisely 2<sup>64</sup>−1):</p>
  <pre><code>public class Foo {
      static long values = 18446744073709551615L;
      
      public static void main(String[] args){
          System.out.println(values);
      }  
  }
  </code></pre>
  <p>So, is there any way to declare an unsigned int or long?</p>