Way2Java

byte to int Java

After knowing the Java rules of Data Type Casting (Type Conversion), let us cast byte to int. The byte takes 1 byte of memory and int takes 4 bytes of memory. Assignment 1 byte value to 4 bytes is done implicitly by the JVM.

byte –> short –> int –> long –> float –> double

The left-side value can be assigned to any right-side value and is done implicitly. The reverse requires explicit casting.

Example:

       short x = 10;
       int y = x;

       byte x = 10;
       short y = x;
Following program on byte to int explains the syntax of implicit casting in Java.
public class Conversions
{
  public static void main(String args[])
  {
    byte b1 = 10;              // 1 byte  
    int i1 = b1;               //  one byte to int 4 bytes

    System.out.println("byte value: " + b1);             //  prints 10
    System.out.println("Converted int value: " + i1);    //  prints 10
  }
}



Output screenshot of byte to int Java

1 byte value b1 is assigned to 4 bytes i1 and is type casted implicitly. This is known as implicit casting or widening conversion.

View all for 65 types of Conversions

Pass your comments and suggestions of how far this is helpful to you and also for the improvement of this tutorial "byte to int Java"