Monday, 15 July 2013

Wrapper class: Byte class example in java

// siddhu vydyabhushana // 1 comment

 The Byte class encapsulates a byte value. It defines the constants MAX_VALUE and MIN_VALUE and provides these constructors:

      Byte(byte b)
      Byte(String str)
Here, b is a byte value and str is the string equivalent of a byte value. 
EX :
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.*;
public class Byte_Demo
{
    public static void main(String args[])
    {
        Byte b1 = new Byte((byte)120);
        for(int i = 125; i<=135; i++)
        {
            Byte b2 = new Byte((byte)i);
            System.out.println("b2 = " + b2);
        }
        System.out.println("b1 Object = " + b1);
        System.out.println("Minimum Value of Byte = " + Byte.MIN_VALUE);
        System.out.println("Maximum Value of Byte = " + Byte.MAX_VALUE);
        System.out.println("b1* 2 = " + b1*2);
        System.out.println("b1* 2 = " + b1.byteValue()*2);
        Byte b3 = new Byte("120");
        System.out.println("b3 Object = " + b3);
        System.out.println("(b1==b3)? " + b1.equals(b3));
        System.out.println("(b1.compareTo(b3)? " + b1.compareTo(b3));
         /*Returns 0 if equal. Returns -1 if b1 is less than b3 and 1 if b1 is
        greater than 1*/
    }
}

 
Output :
 
b2 = 125
b2 = 126
b2 = 127
b2 = -128
b2 = -127
b2 = -126
b2 = -125
b2 = -124
b2 = -123
b2 = -122
b2 = -121
b1 Object = 120
Minimum Value of Byte = -128
Maximum Value of Byte = 127
b1* 2 = 240
b1* 2 = 240
b3 Object = 120
(b1==b3)? true
(b1.compareTo(b3)? 0

1 comment:

  1. Anotheг оption fοr streaming music in the hοme theater іѕ to setup a wireless music plаyer.

    The οthегs will heаr ωherе
    this happеned; the companу nаme
    and the magicianѕ nаmе get frеe promotion.

    "I hoped that people would buy the magazines and therefore I'd keep my job and be able to pay the rent every month," he ѕaіd.


    my pagе - andy gгiffith ѕhοw episodes (celsahershber.mywapblog.com)

    ReplyDelete