Page 43 - CA_Blue( J )_Class10
P. 43

31
                 •  int: The int data type is a 32-bit signed integer or equal to 4 bytes, which has a minimum value of -2  and the
                                     31
                   maximum value of 2 -1. The latest version of Java can use the int data type to represent an unsigned 32-bit integer,
                                                                          32
                   which has a minimum value of 0 and a maximum value of 2 -1. The default value of the int data type is 0. For
                   example:
                   int a = 100000;
                   int b = -200000;
                                                                                                                  63
                 •  long: The long data type is a 64-bit integer or equal to 8 bytes. The signed long has a minimum value of -2  and a
                                     63
                   maximum value of 2 -1. The latest version of Java can use the long data type to represent an unsigned 64-bit long,
                   which has a minimum value of 0 and a maximum value of 2 -1. The default value of int data type is 0L. For example:
                                                                       64
                   long a = 100000L;
                   long b = -200000L;
                          Type           Size       Default value  Range of values that can be stored    Format
                      byte          1 byte         0              −128 to 127                        byte b=10
                      short         2 bytes        0              −32768 to 32767                    short s=1234
                                                                         31
                                                                    31
                      int           4 bytes        0              -2  to 2 -1                        int i = 123456
                                                                    63
                                                                         63
                      long          8 bytes        0L             -2  to 2 -1                        long l=123456L
                 Floating-Point Type
                 Floating-point types represent numbers with a fractional part such as 3.4 or 56.2. There are two types of floating-point
                 data types which are:
                 •  float: The float data type is a single-precision 32-bit IEEE 754* floating-point or equal to 4 bytes. The float data type
                   can store fractional numbers from 3.4e−038 to 3.4e+038 i.e. values up to 7 decimal digits. Note that you should end
                   the value with an "f":

                   float a=4.64f;
                   float b=34.6789f;
                 •  double: The double data type is a double-precision 64-bit IEEE 754* floating-point or equal to 8 bytes. For decimal
                   values, this data type is generally the default choice. The double data type can store fractional numbers from
                   1.7e−308 to 1.7e+308 i.e. values up to 16 decimal digits:

                   double a = 24.23341;
                   double b = 434.211549261;
                      Type            Size       Default value  Range of values that can be stored        Format
                  float          4 bytes        0.0f           3.4e−038 to 3.4e+038               float a=10.67f
                  double         8 bytes        0.0 or 0.0d    1.7e−308 to 1.7e+308               double b=1234.87674

                       Note: The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-
                       point arithmetic established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE).


                 Character Type
                 The character data type is char. The char data type stores character constants in the memory. It is a single 16-bit
                 Unicode character. It assumes a size of 2 bytes, but basically, it can hold only a single character because char stores
                 Unicode character sets. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (65,535). The default
                 value of the char data type is '\u0000'.


                 Why the size of char is 2 bytes in Java?
                 Java uses Unicode system not ASCII code system and to represent Unicode system 8-bits is not enough to represent all
                 characters so Java uses 16-bits or 2 bytes for characters.

                      Type          Size       Default value   Range of values that can be stored       Format
                 char           2 bytes       \u0000          '\u0000' (or 0) to '\uffff' (or 65,535).  char c='a';
                                                                                                  char d= '\u0041';

                                                                                                                       41
                                                                                                 Values and Data Types  41
   38   39   40   41   42   43   44   45   46   47   48