Page 59 - Trackpad_ipro 4.1_Class8
P. 59

int           32                –2147483648                       2147483647


                 long          64                –9223372036854775808              9223372036854775807

                 char          16                0                                 65535

                 float         32                1.4E -45                          3.4028235E38

                 double        64                4.9E-324                          1.7976931348623157E308

                 boolean       1                 False                             True


                 Non-Primitive Data Types

                 The non-primitive data types are derived from primitive data types. Non-primitive data types are
                 also known as reference data types. Some of the examples are class, interface, and array.
                 Literals

                 A literal denotes a constant value. Java has various types of literals. They are as follows:

                    Character Literal: A character literal is enclosed in single quotes and has exactly one character.
                    For example, ‘a’ is a character literal that means the letter a.

                    String Literal: A string literal is enclosed in double quotes. For example, “Hello World.”
                    Integer Literal: An integer literal is any number without a fraction. For example, 10 and 012
                    Floating-Point  Literal: Any number  with  decimal points, like 3.12, is treated  as a

                    floating-point literal.
                    Boolean Literal: Boolean literals can have either true or false values. They do not correspond
                    to 0 or 1 values as in C/C++.
                 Variables


                 Variables are  memory locations used to  store  values. When  a  variable  is created,  space is
                 allocated to it in the memory. This memory space is identified by the name that we give to the
                 variable. It is easy to create a variable in Java.

                 Declaring a Variable

                 In Java, a variable needs to be declared before use. Declaring a variable involves two steps: giving
                 the variable a name and stating what type of data is to be stored in the variable.

                 For example,
                        int age;
                        String name;

                        float temp;
                        double price;

                 Here, four variables named age, name, temp, and price are declared with the int, String, float, and
                 double data types, respectively.


                                                                                              Program Coding     57
   54   55   56   57   58   59   60   61   62   63   64