Fallowing icon

Wednesday, September 19, 2012

Java Data Types


Variables handling is the most important concepts in Computer Programming. We can store information such as Numbers, Characters, Words,True/False and more. We can use in Java Programs, The data have stores like this.



There are two data types in Java -







Primitive Data type


There are eight primitive data types in Java 


                                           1) byte
                                           2) short
                                           3) int
                                           4) long
                                           5) float
                                           6) double
                                           7) char                      
                                           8) boolean

This data types you can use for storing data in Java. When you want to store Name, you can use String data type and when you want to store numbers, You can use int data type for it.





                        Description about data types

Data Type
Bit pattern
Maximum Value
Minimum Value
Maximum Number of
Integer
Maximum Number of Decimal
Default Value
byte
8-bit
+127
-128
3
0
0
short
16-bit
+32 767
-32 768
5
0
0
int
32-bit
+2 147 483 647
-2 147 483 647
10
0
0
long
64-bit
+9 223 372 036 854 775 807
-9 223 372 036 854 775 808
19
0
0L
float
32-bit




0.0f
double
64-bit




0.0d
boolean
1-bit




false
char
16-bit
' \uffff '
' \u0000 '






We use byte data type for store small value. Because it has 8 bit size. But you want to store over 8 bit size, you can use short, int, etc. You want to store Integer with a decimal number, you can use float or double. Normally we use floats for store currency values. We use char for store Characters and use String for store Words.   

Important - When we are building a software, the size of software is very important. When we use long data type for storing small values, it wastes the memory. Because we can use byte data type for storing small values. We want to choose the best data type that matches with value size.



Reference(Object) Data type


              Reference data type variables are declared using defined constructors of the classes.  Those variables cannot be changed after declaring. We cannot directly say, What are the reference data types. Class objects, and various types of array variables come under this data type.  
The default value of a reference variable is  null.  


Example for Reference Data type

ex 1:-  Car nDoor=new Car();  
    Car() is a class type object and Car nDoor is an object type variable. In this example, nDoor come with under the reference data type and store the memory address for it. 

ex 2:-  Home name=new Home("Rose");

    Home() is the object and Home name is an Object type variable.
We store the Rose value for this variable. 


The reference variable can be used to create object type or any compatible type and this variable have fix value. We cannot use reference variables to any computation.  


No comments:

:a   :b   :c   :d   :e   :f   :g   :h   :i   :j   :k   :l   :m   :n   :o   :p   :q   :r   :s   :t

Post a Comment