Are You Looking For JAVA/J2EE Online Training ?

Fill in your details in below form, we will get back to you

Powered by Blogger.

Hadoop Online Training With Placement in USA

www.itlearnmore.com/special-offer-java-5-for-1-package

Limited Offer


Be an expert at low cost

Core Java and Adv JAVA, Struts, HTML and SQL Server Video courses for $20..... Click here


Thursday, 30 April 2015

  1. Variable
  2. Types of Variable
  3. Data Types in Java
In this page, we will learn about the variable and java data types. Variable is a name of memory location. There are three types of variables: local, instance and static. There are two types of datatypes in java, primitive and non-primitive.


Variable
Variable is name of reserved area allocated in memory.

1.    int data=50;//Here data is variable  
Types of Variable
There are three types of variables in java
·         local variable
·         instance variable
·         static variable

Local Variable
A variable that is declared inside the method is called local variable.
Instance Variable
A variable that is declared inside the class but outside the method is called instance variable . It is not declared as static.
Static variable
A variable that is declared as static is called static variable. It cannot be local.

We will have detailed learning of these variables in next chapters.
Example to understand the types of variables
1.    class A{  
2.    int data=50;//instance variable  
3.    static int m=100;//static variable  
4.    void method(){  
5.    int n=90;//local variable  
6.    }  
7.    }//end of class  


Data Types in Java
In java, there are two types of data types
·         primitive data types
·         non-primitive data types

Data Type
Default Value
Default size
boolean
false
1 bit
char
'\u0000'
2 byte
byte
0
1 byte
short
0
2 byte
int
0
4 byte
long
0L
8 byte
float
0.0f
4 byte
double
0.0d
8 byte

Why char uses 2 byte in java and what is \u0000 ?
because java uses unicode system rather than ASCII code system. \u0000 is the lowest range of unicode system.To get detail about Unicode see below.

Categories:


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque volutpat volutpat nibh nec posuere. Donec auctor arcut pretium consequat. Contact me 123@abc.com

0 comments:

Post a Comment