Learn how to use Java int type

Description

When byte and short values are used in an expression they are promoted to int when the expression is evaluated.

Size and value

int is a signed 32-bit type that has a range from -2,147,483,648 to 2,147,483,647.

octal integer(base eight)

Octal values are denoted in Java by a leading zero. valid value 09 will produce an error from the compiler, since 9 is outside of octal's 0 to 7 range.


public class Main {
//from   w ww.  ja v a 2s. co m
  public static void main(String[] args) {
    int i = 010;

    System.out.println(i);
  }
}

The output:

hexadecimal integer(base 16)

hexadecimal matches with modulo 8 word sizes, such as 8, 16, 32, and 64 bits. You signify a hexadecimal constant with a leading zero-x, (0x or 0X).

The range of a hexadecimal digit is 0 to 15, so A through F (or a through f ) are substituted for 10 through 15.

An integer literal can always be assigned to a long variable. An integer can also be assigned to a char as long as it is within range.


public class Main{
  public static void main(String[] argv){
    int f = 0XFFFFF;
//ww w. j av a 2  s .com
    System.out.println(f);//1048575
    
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Language »




Java Data Type, Operator
Java Statement
Java Class
Java Array
Java Exception Handling
Java Annotations
Java Generics
Java Data Structures