KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > Number


1 /*
2  * @(#)Number.java 1.29 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.lang;
9
10 /**
11  * The abstract class <code>Number</code> is the superclass of classes
12  * <code>BigDecimal</code>, <code>BigInteger</code>,
13  * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
14  * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
15  * <p>
16  * Subclasses of <code>Number</code> must provide methods to convert
17  * the represented numeric value to <code>byte</code>, <code>double</code>,
18  * <code>float</code>, <code>int</code>, <code>long</code>, and
19  * <code>short</code>.
20  *
21  * @author Lee Boynton
22  * @author Arthur van Hoff
23  * @version 1.29, 12/19/03
24  * @see java.lang.Byte
25  * @see java.lang.Double
26  * @see java.lang.Float
27  * @see java.lang.Integer
28  * @see java.lang.Long
29  * @see java.lang.Short
30  * @since JDK1.0
31  */

32 public abstract class Number implements java.io.Serializable JavaDoc {
33     /**
34      * Returns the value of the specified number as an <code>int</code>.
35      * This may involve rounding or truncation.
36      *
37      * @return the numeric value represented by this object after conversion
38      * to type <code>int</code>.
39      */

40     public abstract int intValue();
41
42     /**
43      * Returns the value of the specified number as a <code>long</code>.
44      * This may involve rounding or truncation.
45      *
46      * @return the numeric value represented by this object after conversion
47      * to type <code>long</code>.
48      */

49     public abstract long longValue();
50
51     /**
52      * Returns the value of the specified number as a <code>float</code>.
53      * This may involve rounding.
54      *
55      * @return the numeric value represented by this object after conversion
56      * to type <code>float</code>.
57      */

58     public abstract float floatValue();
59
60     /**
61      * Returns the value of the specified number as a <code>double</code>.
62      * This may involve rounding.
63      *
64      * @return the numeric value represented by this object after conversion
65      * to type <code>double</code>.
66      */

67     public abstract double doubleValue();
68
69     /**
70      * Returns the value of the specified number as a <code>byte</code>.
71      * This may involve rounding or truncation.
72      *
73      * @return the numeric value represented by this object after conversion
74      * to type <code>byte</code>.
75      * @since JDK1.1
76      */

77     public byte byteValue() {
78     return (byte)intValue();
79     }
80
81     /**
82      * Returns the value of the specified number as a <code>short</code>.
83      * This may involve rounding or truncation.
84      *
85      * @return the numeric value represented by this object after conversion
86      * to type <code>short</code>.
87      * @since JDK1.1
88      */

89     public short shortValue() {
90     return (short)intValue();
91     }
92
93     /** use serialVersionUID from JDK 1.0.2 for interoperability */
94     private static final long serialVersionUID = -8742448824652078965L;
95 }
96
Popular Tags