Monday, 24 March 2014

DATA TYPES IN JAVA

Posted By: Unknown - Monday, March 24, 2014


What is variable in Java ? It is memory location size in RAM. These variable comes under object umbrella. If object is garbage collected when it is not reference any where. All variables memory locations also will be garbage collected along with object. Java have all signed data types for numbers.
Java have rich set of data types to hold different kind of data like character, number, binary …etc. Following is list of data types in Java :
1. Primitive Data Type :
All primitive data types are keywords of java. They hold all basic data like char, numbers and liters.
There are following 8 types of primitive data types in java :
i) byte : It is integer ( non decimal ) numeric data type. Size of byte is 1 byte. Range :
ii) short : It is integer ( non decimal ) numeric data type. Size of short is 2 bytes. Range :
iii) int : It is integer ( non decimal ) numeric data type. Size of int is 4 bytes. Range :
iv) long : It is integer ( non decimal ) numeric data type. Size of long is 8 bytes. Range :
v) float : It is floating ( decimal ) numeric data type. Size of float is 4 bytes. Range :
vi) double : It is floating ( decimal ) numeric data type. Size of double is 8 bytes. Range :
vii) char : It is integer ( non decimal ) numeric data type. Size of char is 1 byte. It hold Unicode char. Range :
viii) boolean : It is non numeric data type. It holds logical value true or false. Size is not applicable for this data type.
We also have literals in java. true and false are literal and they can not be used as identifier. Liters are keyword in Java.
2. Non primitive Data type :
Arrays and String are non primitive data types. Array can be one dimension, two dimension and multidimensional.
Examples of Arrays : Char Array syntax will be ( char ch[2] = {‘a’,'b’}; ..etc
In similar way, we can create array for any primitive data types as well as non primitive data types like String.
String is class in java. It is used hold multiple characters in one data types. It has no limit.
List of data types and its default values :
DATA TYPEDEFAULT VALUE
byte0
short0
int0
long0L
float0.0f
double0.0d
char‘\u0000′
String (or any object)null
booleanfalse
Examples of default values program is given below :
class DefaultValueProgram
{
 byte b;
 short s;
 int i;
 long l;
 float f;
 double d;
 char c;
 String str;

 public static void main(String args[])
 {
  DefaultValueProgram obj = new DefaultValueProgram();
  System.out.println("Byte default value " + obj.b );
  System.out.println("Short default value " + obj.s );
  System.out.println("Int default value " + obj.i );
  System.out.println("Long default value " + obj.l );
  System.out.println("float default value " + obj.f );
  System.out.println("double default value " + obj.d );
  System.out.println("char default value " + obj.c );
  System.out.println("String default value " + obj.str );
 }
}
Output of default value program of Java :
G:\>java DefaultValueProgram
Byte default value 0
Short default value 0
Int default value 0
Long default value 0 
float default value 0.0
double default value 0.0
char default value
String default value null

0 comments:

Post a Comment

this blog is helpful or not

International

Auto News

Translate

Pages

Popular Posts

Popular Posts

Designed By Templatezy / Sb Game Hacker Apk / MyBloggerThemes