Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 95 - 2617_JSSPS_C-6
P. 95

    Data Type       Size (in bits)          Minimum Value                    Maximum Value
                     long          64                  –9223372036854775808            9223372036854775807
                     char          16                  0                               65535
                     float         32                  1.4E –45                        3.4028235E38
                     double        64                  4.9E –324                       1.7976931348623157E308

                     boolean       1                   True or False

                     Non-Primitive Data Types

                     The non-primitive  data types are derived from primitive data types. The non-primitive  data types
                     are also known as reference data types. Some of the examples of non-primitive data types 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 must have exactly one character.
                       For example, ‘a’ is a character literal that means the letter a.

                         String literal: A string literal is always 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 the memory locations used to store values. When a variable is created, some space is
                     allocated for it in the memory. This memory space is referred to 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.

                                                                                  Introduction to Programming in Java   93

| 90 91 92 93 94 95 96 97 98 99 100 |