See the Tutorial List

Byte Class


Below are the Methods of Byte class and their example.

1. toString()

Syntax:

	 
public String toString(byte b)
	 

Example:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        byte a = 65; 
System.out.println("toString(a) = " + Byte.toString(a));
	}
}
	

byte-class


2. valueOf()

	
public static Byte valueOf(byte b)
	

Example:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        byte a = 65; 
	String b = "25";
        Byte x = Byte.valueOf(a); 
	System.out.println("ValueOf(a) = " + x);
        x = Byte.valueOf(b, 6); 
System.out.println("ValueOf(a,6) = " + x);
	}
}
	

byte-class-example


3. parseByte()

	
public static byte parseByte(String val, int radix)
            throws NumberFormatException
	

Example:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        byte a = 65; 
	String b = "25";
        byte x = Byte.parseByte(b); 
System.out.println("parseByte(b) = " + x); 
        x = Byte.parseByte(b, 6); 
System.out.println("parseByte(b,6) = " + x); 
	}
}
	

byte-class-example


4. decode()

Syntax:

	
public static Byte decode(String s)
            throws NumberFormatException
	

Example:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        String a = "25"; 
        String b = "006"; 
        String c = "0x0f"; 
        Byte x =Byte.decode(a); 
System.out.println("decode(25) = " + x); 
        x =Byte.decode(b); 
System.out.println("decode(006) = " + x); 
        x=Byte.decode(c); 
System.out.println("decode(0x0f) = " + x); 
	}
}
	

byte-class-example


5. byteValue()

Syntax

	
public byte byteValue()
	

6. shortValue()

Syntax

	
public short shortValue()
	

7. intValue()

Syntax

	
public int intValue()
	

8. longValue()

Syntax

	
public long longValue()
	

9. doubleValue()

Syntax

	
public double doubleValue()
	

10. floatValue()

Syntax:

	
public float floatValue()
	

Example:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        Byte a = 45;
	Byte obj = new Byte(a);
	
	System.out.println("bytevalue(obj) = " + obj.byteValue()); 
System.out.println("shortvalue(obj) = " + obj.shortValue()); 
System.out.println("intvalue(obj) = " + obj.intValue()); 
System.out.println("longvalue(obj) = " + obj.longValue()); 
System.out.println("doublevalue(obj) = " + obj.doubleValue()); 
System.out.println("floatvalue(obj) = " + obj.floatValue());
	}
}
	

byte-class-example


11. hashCode()

Syntax:

	
public inthashCode()
	

Example:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        Byte a = 45;
	Byte obj = new Byte(a);
	
	int x =obj.hashCode(); 
System.out.println("hashcode(obj) = " + x); 
	}
}
	

byte-class-example


12. equals()

Syntax:

	
public boolean equals(Object obj) 
	

Example:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        Byte a = 45;
	String b ="25";
	Byte obj = new Byte(a);
	Byte obj1 = new Byte(b);
	
	boolean z = obj.equals(obj1); 
System.out.println("obj.equals(obj1) = " + z); 
	}
}
	

byte-class-example


13. compareTo()

Syntax:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        Byte a = 45;
	String b ="25";
	Byte obj = new Byte(a);
	Byte obj1 = new Byte(b);
	
	int z = obj.compareTo(obj1); 
System.out.println("obj.compareTo(obj1) = " + z); 
	}
}
	

byte-class-example


14. compare()

Syntax:

	
public static intcompare(byte x,byte y) 
	

Example:

	
public class ByteDemo1 
{ 
    public static void main(String[] args)  
	{ 
        Byte a = 45;
	String b ="25";
	Byte obj = new Byte(a);
	Byte obj1 = new Byte(b);
	
	int z = Byte.compare(obj, obj1); 
System.out.println("compare(obj, obj1) = " + z); 
	}
}
	

byte-class-example