Home » openjdk-7 » java » lang » [javadoc | source]
java.lang
public final class: Byte [javadoc | source]
java.lang.Object
   java.lang.Number
      java.lang.Byte

All Implemented Interfaces:
    Comparable, Serializable

The {@code Byte} class wraps a value of primitive type {@code byte} in an object. An object of type {@code Byte} contains a single field whose type is {@code byte}.

In addition, this class provides several methods for converting a {@code byte} to a {@code String} and a {@code String} to a {@code byte}, as well as other constants and methods useful when dealing with a {@code byte}.

Field Summary
public static final  byte MIN_VALUE    A constant holding the minimum value a {@code byte} can have, -27
public static final  byte MAX_VALUE    A constant holding the maximum value a {@code byte} can have, 27-1. 
public static final  Class<Byte> TYPE    The {@code Class} instance representing the primitive type {@code byte}. 
public static final  int SIZE    The number of bits used to represent a {@code byte} value in two's complement binary form.
    since: 1.5 -
 
Constructor:
 public Byte(byte value) 
 public Byte(String s) throws NumberFormatException 
    Constructs a newly allocated {@code Byte} object that represents the {@code byte} value indicated by the {@code String} parameter. The string is converted to a {@code byte} value in exactly the manner used by the {@code parseByte} method for radix 10.
    Parameters:
    s - the {@code String} to be converted to a {@code Byte}
    Throws:
    NumberFormatException - If the {@code String} does not contain a parsable {@code byte}.
    Also see:
    java.lang.Byte#parseByte(java.lang.String, int)
Method from java.lang.Byte Summary:
byteValue,   compare,   compareTo,   decode,   doubleValue,   equals,   floatValue,   hashCode,   intValue,   longValue,   parseByte,   parseByte,   shortValue,   toString,   toString,   valueOf,   valueOf,   valueOf
Methods from java.lang.Number:
byteValue,   doubleValue,   floatValue,   intValue,   longValue,   shortValue
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.lang.Byte Detail:
 public byte byteValue() 
    Returns the value of this {@code Byte} as a {@code byte}.
 public static int compare(byte x,
    byte y) 
    Compares two {@code byte} values numerically. The value returned is identical to what would be returned by:
       Byte.valueOf(x).compareTo(Byte.valueOf(y))
    
 public int compareTo(Byte anotherByte) 
    Compares two {@code Byte} objects numerically.
 public static Byte decode(String nm) throws NumberFormatException 
    Decodes a {@code String} into a {@code Byte}. Accepts decimal, hexadecimal, and octal numbers given by the following grammar:
    DecodableString:
    Signopt DecimalNumeral
    Signopt {@code 0x} HexDigits
    Signopt {@code 0X} HexDigits
    Signopt {@code #} HexDigits
    Signopt {@code 0} OctalDigits

    Sign:
    {@code -}
    {@code +}
    DecimalNumeral, HexDigits, and OctalDigits are as defined in section 3.10.1 of The Java™ Language Specification, except that underscores are not accepted between digits.

    The sequence of characters following an optional sign and/or radix specifier ("{@code 0x}", "{@code 0X}", "{@code #}", or leading zero) is parsed as by the {@code Byte.parseByte} method with the indicated radix (10, 16, or 8). This sequence of characters must represent a positive value or a NumberFormatException will be thrown. The result is negated if first character of the specified {@code String} is the minus sign. No whitespace characters are permitted in the {@code String}.

 public double doubleValue() 
    Returns the value of this {@code Byte} as a {@code double}.
 public boolean equals(Object obj) 
    Compares this object to the specified object. The result is {@code true} if and only if the argument is not {@code null} and is a {@code Byte} object that contains the same {@code byte} value as this object.
 public float floatValue() 
    Returns the value of this {@code Byte} as a {@code float}.
 public int hashCode() 
    Returns a hash code for this {@code Byte}; equal to the result of invoking {@code intValue()}.
 public int intValue() 
    Returns the value of this {@code Byte} as an {@code int}.
 public long longValue() 
    Returns the value of this {@code Byte} as a {@code long}.
 public static byte parseByte(String s) throws NumberFormatException 
    Parses the string argument as a signed decimal {@code byte}. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign {@code '-'} ('\u002D') to indicate a negative value or an ASCII plus sign {@code '+'} ('\u002B') to indicate a positive value. The resulting {@code byte} value is returned, exactly as if the argument and the radix 10 were given as arguments to the #parseByte(java.lang.String, int) method.
 public static byte parseByte(String s,
    int radix) throws NumberFormatException 
    Parses the string argument as a signed {@code byte} in the radix specified by the second argument. The characters in the string must all be digits, of the specified radix (as determined by whether java.lang.Character#digit(char, int) returns a nonnegative value) except that the first character may be an ASCII minus sign {@code '-'} ('\u002D') to indicate a negative value or an ASCII plus sign {@code '+'} ('\u002B') to indicate a positive value. The resulting {@code byte} value is returned.

    An exception of type {@code NumberFormatException} is thrown if any of the following situations occurs:

    • The first argument is {@code null} or is a string of length zero.
    • The radix is either smaller than java.lang.Character#MIN_RADIX or larger than java.lang.Character#MAX_RADIX .
    • Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign {@code '-'} ('\u002D') or plus sign {@code '+'} ('\u002B') provided that the string is longer than length 1.
    • The value represented by the string is not a value of type {@code byte}.
 public short shortValue() 
    Returns the value of this {@code Byte} as a {@code short}.
 public String toString() 
    Returns a {@code String} object representing this {@code Byte}'s value. The value is converted to signed decimal representation and returned as a string, exactly as if the {@code byte} value were given as an argument to the java.lang.Byte#toString(byte) method.
 public static String toString(byte b) 
    Returns a new {@code String} object representing the specified {@code byte}. The radix is assumed to be 10.
 public static Byte valueOf(byte b) 
    Returns a {@code Byte} instance representing the specified {@code byte} value. If a new {@code Byte} instance is not required, this method should generally be used in preference to the constructor #Byte(byte) , as this method is likely to yield significantly better space and time performance since all byte values are cached.
 public static Byte valueOf(String s) throws NumberFormatException 
    Returns a {@code Byte} object holding the value given by the specified {@code String}. The argument is interpreted as representing a signed decimal {@code byte}, exactly as if the argument were given to the #parseByte(java.lang.String) method. The result is a {@code Byte} object that represents the {@code byte} value specified by the string.

    In other words, this method returns a {@code Byte} object equal to the value of:

    {@code new Byte(Byte.parseByte(s))}
 public static Byte valueOf(String s,
    int radix) throws NumberFormatException 
    Returns a {@code Byte} object holding the value extracted from the specified {@code String} when parsed with the radix given by the second argument. The first argument is interpreted as representing a signed {@code byte} in the radix specified by the second argument, exactly as if the argument were given to the #parseByte(java.lang.String, int) method. The result is a {@code Byte} object that represents the {@code byte} value specified by the string.

    In other words, this method returns a {@code Byte} object equal to the value of:

    {@code new Byte(Byte.parseByte(s, radix))}