DATA TYPES


Today we are going to discuss different types of data types we have in JAVA language. So let us now walk through it.

DataType

Data type is an attribute which helps us to tell the compiler how we really want to operate the data. It's basically use to describe what type of value our variable will have. They usually are of two types, Primitive and Non Primitive Data Types.

Primitive Data Types:- 

They are of  2 types. Boolean and Numeric.

1 Boolean:- 

As its name suggest, we are going to have bool values in this i.e.  true or false.It is represent by writing 'boolean' keyword itself. It's basically use in conditional expressions. Its default value is false.

Example:- boolean = true or boolean = false.

2 Numeric:-

Its function also goes with its name. It deals with numbers. And it's also use to take character value. It's is again of two types , Integral value and Character. Now let us walk through those.

(a) Character- 

It's use to store character values. It's represented by writing 'char' keyword. Any value will consider as character as long as you quoted it with single quotation marks. Its default value is '/u0000'.

Example:- char = 'A' or char = 'a' or char = '5'

(b) Integral Value:-

It's going to have integer value and decimal values. It's is of two types, Integer and Floating point.

(b.1) Integer 

It's of four types. It's basically differentiate on the basis of amount of space they will occupy in the memory. So, let's see about its types

Bytes:- 

It's nothing but just the central CMU ( central memory unit ) made up of  letter or a string. It's of size of eight bits. One byte is equal to eight bits.
Its values ranges from -128 to 127.Its default value is 0.

Example:- byte is combination of bits used in computer coding to represent a letter in an alphabet.

Short:-

It's is use to stores numeric values. The amount of memory it take is 2 bytes or 16 bits. Value ranges from -32768 to 32767. Its default value is 0

Example:- short x = 121

Int:-

It's also use to have integer values. It takes up 4 bytes in memory . Its value ranges from -2147483648 to 2147483647. Its default value is 0.

Example:- int x = 1000

Long:-

It's going to have bigger integer values and it takes up to 8 bytes of computer memory. Values in it ranges from -9223372036854775808 to 9223372036854775807. Its default value is 0L.

Example:- long x = 1345679

(b.2) Floating point Value:-

It deals with decimal values. Whenever we have to store decimal values we use floating point value type of variable. It's of two types, Float and Double.

Float:-

It stores decimal values with 6 to 7 digit of precision. It takes up 4 bytes in computer memory. Its default value is 0.0f. 

Example:- float x= 12.85

Double:-

It stores decimal values with a very vast digit of precision. It takes up to 8 bytes of computer memory. Its default value is 0.0d.

Example:-  double x  = 123.889764

Non Primitive Data Types:-

These are created by coders only. There are many of its types. Here, we are going to overlook some of them like Class , Array. We will not discuss it much here but will just see its basics.

(a) Class:-

It's nothing but the group of objects and variables
define to carry out some task. 

Example:- 
class CodersThing
{  
//Functions

(b) Array:-

It is the collection of values of same datatype stored at continuous memory location.

Example:- int x[3] = {1, 2, 3}  or char x[3] = {'a', 'A', 'f'}

There are more Non Primitive Datatypes like string, pointer etc.

If you like this article share it with your friends.
                                           :)











Comments

Post a Comment

Popular posts from this blog

FOR LOOP AND EXAMPLES

If and Else