Page 108 - computer science (868) class 11
P. 108

\f         Inserts a form feed.
                                             \’         Inserts a single quote character.
                                             \”         Inserts a double quote character.
                                             \\         Inserts a backslash character.
                                             \0         Assigns a null to a String variable.
                                             \v         Inserts a vertical tab.

                   5.3 DATA TYPES
              A data type is an attribute that tells the compiler or interpreter how the programmer intends to use the data or value.
              It specifies the size and type of values that can be stored in a variable. Different data types allow you to select the type
              appropriate for the needs of the application.

              5.3.1 Different Data Types in Java
              There are two types of data that can be handled by the codes written in Java which are as follows:

                                                                      Data Types




                                            Primitive                                          Non-Primitive




                 byte    short    int     long    float   double  boolean   char      Class   Array  Interface  string


              Primitive Data Types
              Primitive data types are also known as built-in data types. They can store only values which are of predefined types.
              There are eight different types of primitive data types. They are byte, short, int, long, float, double, boolean and char.

                                                              Primitive




                                   byte    short    int     long    float   double  boolean   char

              Now we will discuss the primitive data types in detail.

              •  byte: This data type stores values from -128 up to 127 and takes 0 as the default value. For example, byte a=111,
                 byte b=-120, etc.
              •  short: The range of the data type is from -32,768 up to 32,767 and takes the default value as 0. The total size is 2
                 bytes or 16 bits. For example, short s=12987, t=-23176;
              •  int: This data type is mostly used to write the code of the program. The size is 4 bytes or 32 bits and can hold data
                                31
                       31
                 from -2  up to 2 -1. For example, int a=102948586, b=-29384.
                                                                                            63
                                                                                      63
              •  long: The size of this data type is 8 bytes or 64 bits. The signed range is from -2  to 2 -1 and the unsigned range is
                      63
                 0 to 2 -1. For example, long a=19283746L, long b=-12384738L.
              •  float: The size of this data type is 4 bytes. It can store fractional numbers. The range of this data type is from
                 3.4e-038 to 3.4e+038 up to values 16 decimals digits.
              •  double: The size of this data type is 8 bytes or 64 bits. The double data type can store fractional numbers from
                 1.7e-308 to 1.7e+308 i.e., values up to 16 decimal digits.



                106106  Touchpad Computer Science-XI
   103   104   105   106   107   108   109   110   111   112   113