• Java Constants and Datatypes

    Java Constants and Datatypes

    In Java Constants and Datatypes, It is important to state at the outset that Java is a strongly typed language. Indeed, part of Java’s safety and robustness comes from this fact. Let’s see what this means. First, every variable has a type, every expression has a type, and every type is strictly defined. Second, all assignments, whether explicit or via parameter passing in method calls, are checked for type compatibility. There are no automatic coercion or conversions of conflicting types as in some languages. The Java compiler checks all expressions and parameters to ensure that the types are compatible. Any type mismatches are errors that must be corrected before the compiler will finish compiling the class.


    1.         Numeric Constants

    1. Integer Constants :- 123, -321, 0, 654321,  Octal, Hexadecimal
    2. Real Constants :- 0.0083, -0.75, 435.36, 0.65e4, 12e-2, 1.5e+5

    2.         Character Constants

    1. Single Character Constants :- ‘5’, ‘X’, ‘;’, ‘ ‘
    2. String Constants :- “Hello Java”, “1997”, “?….!”, “5+3”, “X”


    1. primitive (Intrinsic) :
      1. Numeric :
        1. Integer
          1. Byte (1 byte)  -128 to +127
          2. Short (2 bytes)  -32,768 to +32,767
          3. int (4 bytes) -2,147,483,648 to +2,147,483,647
          4. long (8 bytes) -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
        2. Floating Point
          1. float (4 bytes) 3.4e-038 to 3.4e+038
          2. double (8 bytes) 1.7e-308 to 1.7e+308
      2. Non-Numeric :
        1. Character (2 bytes) Holds singles character only
        2. Boolean (1 bit) Holds Only true or false
    2. Non-primitive :
      1. Classes
      2. Interface
      3. Arrays

    Characters :-

    In Java, the data type used to sore characters is char. However C/C++ programmers beware: char in Java is not the same as char in C/C++. In C/C++, char is an integer type that is 8 bits wide. This is not the case in Java. Instead, Java uses Unicode to represent characters. Unicode defines a fully international character set that can represent all of the characters found in all human languages. It is a unification of dozens of character set, such as Latin, Greek, Arabic, Cyrillic, Hebrew, Katakana, Hangul, and many more. For this purpose, it requires 16 bits. Thus, in Java char is a 16-bit type (2 bytes). The range of a char is 0 to 65,536. There are no negative chars. The standard set of characters known as ASCII still ranges from 0 to 127 as always, and the extended 8-bit character set, ISO-Latin-1, ranges from 0 to 255. Since Java is designed to allow applets to be written for worldwide use, it makes sense that it would use Unicode to represent characters. Of course, the use of Unicode is somewhat inefficient for languages such as English, German, Spanish, or French whose characters can easily be contained within 8 bits. But such is the price that must be pain for global portability.

    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *