Java lang.Long.byteValue() method in Java with Examples Last Updated : 23 May, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report java.lang.Long.byteValue() is a built-in function in Java that returns the value of this Long as a byte. Syntax: public byte byteValue() Parameters: The function does not accept any parameter. Return : This method returns the numeric value represented by this object after conversion to byte type. Examples: Input : 12 Output : 12 Input : 1023 Output : -1 The program below illustrates the java.lang.Long.byteValue() function: Program 1 : java // Java program that demonstrates the use of // Long.byteValue() function // include lang package import java.lang.*; public class GFG { public static void main(String[] args) { Long value = 1023l; // returns the value of Long as a byte byte byteValue = value.byteValue(); System.out.println("Byte Value of num = " + byteValue); // 2nd example value = 12l; byteValue = value.byteValue(); System.out.println("Byte Value of num = " + byteValue); } } Output: Byte Value of num = -1 Byte Value of num = 12 Program 2 : Demonstrates the byte value of a negative number java // Java program that demonstrates the use of // Long.byteValue() function // negative number // include lang package import java.lang.*; public class GFG { public static void main(String[] args) { Long value = -1023l; // returns the value of Long as a byte byte byteValue = value.byteValue(); System.out.println("Byte Value of num = " + byteValue); // 2nd example value = -12l; byteValue = value.byteValue(); System.out.println("Byte Value of num = " + byteValue); } } Output: Byte Value of num = 1 Byte Value of num = -12 Program 3 : When a decimal value is passed in argument. java // Java program that demonstrates the use of // Long.byteValue() function // decimal number // include lang package import java.lang.*; public class GFG { public static void main(String[] args) { Long value = 11.24; // returns the value of Long as a byte byte byteValue = value.byteValue(); System.out.println("Byte Value of num = " + byteValue); } } Output: prog.java:13: error: incompatible types: double cannot be converted to Long Long value = 11.24; Program 4 : When a string value is passed in argument. java // Java program that demonstrates the use of // Long.byteValue() function // string number // include lang package import java.lang.*; public class GFG { public static void main(String[] args) { Long value = "24"; // returns the value of Long as a byte byte byteValue = value.byteValue(); System.out.println("Byte Value of num = " + byteValue); } } Output: prog.java:13: error: incompatible types: String cannot be converted to Long Long value = "24"; Comment More infoAdvertise with us Next Article Java lang.Long.builtcount() method in Java with Examples G gopaldave Follow Improve Article Tags : Misc Java Java-lang package Java-Functions java-Long +1 More Practice Tags : JavaMisc Similar Reads Java lang.Long.builtcount() method in Java with Examples java.lang.Long.bitCount() is a built in function in Java that returns the number of set bits in a binary representation of a number. It accepts a single mandatory parameter number whose number of set bits is returned. Syntax: public static long bitCount(long num) Parameters: num - the number passed 3 min read Byte longValue() method in Java with examples The longValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as long. Syntax ByteObject.longValue() Return Value: It return the value of ByteObject as long. Below is the implementation of longValue() method in Java: Example 1: Java // Java c 2 min read Byte byteValue() method in Java with examples The byteValue method of Byte class is a built in method in Java which is used to return the value of this Byte object as byte. Syntax ByteObject.byteValue() Return Value: It returns the value of ByteObject as byte. Below is the implementation of byteValue() method in Java: Example 1: Java // Java co 2 min read Java lang.Long.lowestOneBit() method in Java with Examples java.lang.Long.lowestOneBit() is a built-in method in Java which first convert the number to Binary, then it looks for first set bit present at the lowest position then it reset rest of the bits and then returns the value. In simple language, if the binary expression of a number contains a minimum o 3 min read Number.byteValue() Method in Java with Examples The Number class in Java is an abstract superclass for numeric wrapper classes like Integer, Float, Double, etc. One of the useful methods provided by this class is byteValue(). The Number.byteValue() method in Java is used when we want to extract the byte representation of a numeric object.The byte 3 min read Byte doubleValue() method in Java with examples The doubleValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as double. Syntax ByteObject.doubleValue() Return type: It returns the value of ByteObject as double. Below is the implementation of doubleValue() method in Java: Example 1: Java 2 min read Like