Java – Java Variable Types

In Java all variables must be declared before the use.basic declaration will be like,


‘ DataType VariableName; ‘


int a;

float b;

Continuous declaration also allowed like ‘int a,b,c;’.

There are three types of variables in java.they are,

  • Local Variable.
  • Instance Variable.
  • Class/Static Variable.

Local Variable:

  • Local variables are declared inside the method,constructor or block.
  • They are visible only inside the block in which they are declared.
  • Local variables do not have a default value so it must be declared  and initialized before the first use.
  • Access modifiers cannot be implemented for local variables.
  • Local variables are destroyed immediately after exits the block.

Example Code:

public class Age {

public void printAge()


int ageCount = 0;        // ageCount is a Local Variable

ageCount = ageCount + 5;

System.out.println(“Age is “+ageCount);


public static void main(String args[])


Age object1 = new Age();




Instance Variable:

  • Instance variables are declared outside the method and constructor or block.
  • Memory will be created in the heap when the instance variable is created.
  • Instance variable is created when an object is created using the ‘new’ keyword.
  • Access modifiers can be applied to these variables.but however ‘private’ is advisable.If the variables needs to be accessed by the subclasses then the visibility can be modified.
  • Instance variables have their default values.So it is not a must to declare and instantiate.Example: int a;
    Here the variable ‘a’ holds 0 as its default value.
  • Instance variables holds values that must be referenced by more than one method,constructor or block.State should be maintained throughout the class.
  • They can be directly called by their name inside the class.Subclasses have to use the qualified name.Example: ‘ObjectName.VariableName’

Example Code:

public class Employee {

public String employeeName;     // employeeName and employeeSalary are Instance Variables

public int employeeSalary;

public Employee(String name)


employeeName = name;


public void setEmployeeValues(int pay)


employeeSalary = pay;

System.out.println(“Employee Name is “+employeeName+” and Employee Salary is “+employeeSalary);


public static void main(String args[])


Employee employee = new Employee(“Manishankar”);




Class/Static Variable:

  • Class variables are also called as Static variables.Variables are declared with a ‘Static’ keyword outside the method,constructor or block.
  • There will be only one copy of the static variable.
  • Static variables can have access modifiers.
  • Static variables starts when the program starts and destroyed when the program stops.
  • Static variables have static memory.
  • Static variables can be accessed by calling the variable with its class name.Example: ‘ClassName.VariableName’

Example Code:

public class Test {

// Salary is a private static variable

private static int salary;

// Name is a constant variable

private static final String name = “Manishankar”;

public static void main(String args[])


salary = 50000;

System.out.println(“Salary is “+salary+” and Name is “+name);




Advantages and Disadvantages of Android…

Nobody thought this little Greeny Horny boy would become the competitor for mobile demons like Apple and Blackberry.This is an rapid hike.People started using this Android with lots of expectations.Android is an linux based operating system which is owned by Android.Inc.Later it was owned by Google.You dont have to be an Expert or  Scientist to give a review about this android but Anyone can who own a Android Device.I own a Android device so i thought to have this post.


Advantages of Android:

Cost Effective:


The first thing about Android is its cost.People  who used to be with base level mobiles would be fed up with the boring options.But with the low price now they can go for Android phones with good design and lot of applications which is not possible with the Apple,Blackberry and some.






Android  has a multitasking option so you can run many applications simultaneously.As this is not a new stuff nowadays but it comes under Advantage room.





Easy Access of Store:


So the store is in the home screen which is easy to access the applications.You dont need to settle with the fixed applications as the store is filled,filling and will be filled with plenty of applications.



UserInterface Big Screen:


Android breaks the word ‘More Money Big Phone’.Yes you can afford a big screen android mobile with your savings.So there is no need to close your bank account.




Disadvantages of Android:

Application Quality:


Application Quality is not so good.There is no standard for these applications.Few application roam with the memory Leaks and Crashes




Battery Life:


Android more wasteful than any otheroperating system, because this operating system is a lot of “process”in the background that lead to the battery quickly drains.



Virus Applications:

virusFew Android Applications contain virus also present in the Android Market.Due the lack of Quality Standard many applications contain viruses which makes your mobile hung.





Application in the Android phones can indeed be obtained easily and for free, but the consequences in each of these applications, will always be ads on display, either the top or bottom of the application.