Thursday 29 October 2015

Java primitive and non primitive data types

A variable is a named memory location or a name given to a memory location. Like other languages in java also used to store the data.For example, If you want store a value 10 in memory location, one write as

Example: int a=10

         Here 'a' is the name give to the memory location where the value of '10' is located and the word ' int' tells that what type of data we are storing in that memory location. So, it is called '' data type''. Just like this, in java it is necessary to tell what type of data we are handling to JVM and to this we have data types.

        '' java is a strongly types languages'' that in java it is necessary to tell what type of data we are handling before it can be used and it also tells what types of operation that can be carries out on this. There mainly two types of data types are available in java.

1. Java Primitive Data Types (OR) Java Basic data types
2. Java Non-Primitive Data Types (OR) Derived data types

Primitive or Basic data types in java

                                          java define eight primitive data types namely byte, short, int,long, char, float, double and boolean. These are also called as intrinsic or built-in types. The integer group includes byte, short, int, and long and the floating group includes float and double.

Byte: A byte data type is a 8 bit signed two's complement integer. It can be used as alternative to integer where large amount of arrays what to store information. The maximum value is -128 and the minimum value is +127

Short:  short is a signed 16 bit type. It has a range from -32,768 to 32,767. It is probably the least used data type.

Int: The most commonly used data types is integer.It is signed 32-bit type that has a range from 263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1

long: long is a signed 64-bit type and is useful for those occasions where an integer type is not enough to hold the desired value.We make integers long by appending ''L'' or ''l'' at the end of the number as

          123L or 123l
integer types can hold only whole numbers and therefore we use another type known as floating point type to hold numbers containing fractional parts.

float: the type float specifies a single precision value that uses 32 bits of storage. Variables of type float are useful when you need a fractional component, but don't require a large degree of precision. For example, float can be useful when representing dollars and cents.

double: Double precision, as denoted by the double keyword, uses 64 bits to store a value.

char: In C/C++ the character data type can store 8 bits. But it is not the case in java. Because java follows unicode system to represent all the characters found in all the human languages. So, it requires 16 bits.

boolean: a boolean is a 1 bit data type used to represent two values TRUE or FALSE.

Default Values 

                It is always not necessary to store value in variable. When it is the case it can store some default as either zero or null depending on the data type. Here are basic primitive data type and their default values.
In java we can use ''String'' as a data type. It represents a group of characters like ''hello'', ''world'' ext..The simplest way to create String is by storing a group of characters into a String type variable as:

          String str=" hello";

What is the difference between integer and int in java ?

                            In java integer is a class and int is primitive data type.

What is the difference between float and double? 
                                    float can represent 7 digits accurately after decimal point, where as double can represent up to 15 digits accurately after decimal point.

What is a Unicode system?

                                              Unicode system is an encoding system standard that provides a unique number for every character, no matter what the platform, program, or language is. Unicode uses 2 bytes to represent a single character.

non primitive data types in java

                                       Also refred to as derived types. java supports  non primitive data types classes, interfaces, and arrays ..ext and which will be covered in later topics.


Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning



Java Tutorial




C Programming


Python Tutorial


Data Structures


computer Organization