BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Java Integer byteValue() Method

Last Updated: October 23, 2022 by Chaitanya Singh | Filed Under: java

The byteValue() method of Integer class returns the given integer value in bytes after narrowing primitive conversion (Integer -> byte) . This method is used when you want to convert the Integer to bytes.

Note: byte range is -128 to 127 and Integer range is -2,147,483,648 to 2,147,483,647 so it is clear that an Integer can hold large values than byte type. This means that this method should be used for smaller integer values else it may given undesired results.

Hierarchy:

java.lang Package 
    -> Integer Class
        -> byteValue() Method 

Syntax of byteValue() method

public byte byteValue()

byteValue() Parameters

  • It does not take any parameter.

byteValue() Return Value

  • It returns the value contained by Integer object in bytes.
  • Return type of byteValue() method is byte.

Supported Java versions: Java 1.5 and onwards

Example 1

class JavaExample {
  public static void main(String args[]) {
    // Integer object obj contains value 75
    Integer obj = new Integer(75);

    // converting this Integer value to bytes
    byte b = obj.byteValue();

    // Printing the integer value 75 in bytes
    System.out.println("Value in bytes: "+b);
  }
}

Output: