Javatpoint Logo
Javatpoint Logo

Java Number byteValue() Method

The byteValue() is a method of Java Number class which automatically converts the given number into a primitive byte type and returns the value of the specified number as a byte.

Syntax:

Following is the declaration of byteValue() method:

Parameter:

DataType Parameter Description
byte NA It returns the value of number object as byte.

Returns:

The byteValue() method returns the numeric value represented by this object after conversion to the primitive byte type.

Exceptions:

NA

Compatibility Version:

Java 1.1 and above

Example 1

Test it Now

Output:

Number as Byte: 64

Example 2

Test it Now

Output:

Integer Number as Byte: -64
Float Number as Byte: -77
Double Number as Byte: 76

Example 3

Output:

Enter the Number Value: ABCDEF
Exception in thread "main" java.util.InputMismatchException
	at java.base/java.util.Scanner.throwFor(Scanner.java:939)
	at java.base/java.util.Scanner.next(Scanner.java:1594)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
	at myPackage.NumberByteValueExample3.main(NumberByteValueExample3.java:9)

Next TopicJava Number Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA