
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Byte Class Fields in Java with Example
The Byte class wraps a value of primitive type byte in an object.
Following are the fields for Byte class−
- static byte MAX_VALUE − This is constant holding the maximum value a byte can have, 27-1.
- static byte MIN_VALUE − This is constant holding the minimum value a byte can have, -27.
- static int SIZE − This is the number of bits used to represent a byte value in two's complement binary form.
- static Class<Byte> TYPE − This is the Class instance representing the primitive type byte.
Example
Let us now see an example −
import java.lang.*; public class Demo { public static void main(String[] args){ Byte b1, b2; int i1, i2; b1 = new Byte("1"); b2 = Byte.MIN_VALUE; i1 = b1.intValue(); i2 = b2.intValue(); String str1 = "int value of Byte " + b1 + " is " + i1; String str2 = "int value of Byte " + b2 + " is " + i2; System.out.println( str1 ); System.out.println( str2 ); } }
Output
This will produce the following output -
int value of Byte 1 is 1 int value of Byte -128 is -128
Example
Let us now see another example −
import java.lang.*; public class Demo { public static void main(String[] args){ Byte b1, b2; String s1, s2; b1 = new Byte("-10"); b2 = Byte.MIN_VALUE; System.out.println("Number of bits in b1 = "+b1.SIZE ); System.out.println("Number of bits in b2 = "+b2.SIZE ); s1 = b1.toString(); s2 = b2.toString(); String str1 = "String value of Byte " + b1 + " is " + s1; String str2 = "String value of Byte " + b2 + " is " + s2; System.out.println( str1 ); System.out.println( str2 ); } }
Output
This will produce the following output -
Number of bits in b1 = 8 Number of bits in b2 = 8 String value of Byte -10 is -10 String value of Byte -128 is -128
Advertisements