Java code,java,Example,Tutorials,Syntax,Hibernate,Jsp, Servlet, FileHeadling,Java or Core Java Tutorial or Java Programming Tutorial is a widely used robust technology. learning of java from basic questions like what is java tutorial, core java, where it is used, what type of applications are created in java and why use java.

Search This Blog

Tuesday, 26 July 2016

What is Variable in java


what is Variable in java?
   
                A variable can provide to store the program each of the java Variable has type .
this type is determines the size and layout of the variable memory  .and also the rang of value is store the memory .

variable in java,use of variable and how to define variable in java

What is Variable?type of Variable?


Main Three type of Variable .
                                           Local Variable
                                            StaicVariable
                                           instance Variable
                                  



Local variables:


What is Variable?Explain LocalVariable?
 Example,LocalVriable


Class/static variables:

Class Variable in java and Explain the Details .

Static variable ues of Static variable in java 
code the class variable

import java.io.*;

public class vipul{
  
   private static double salary;

   // DEPARTMENT is a constant
   public static final String DEPARTMENT = "Development ";

   public static void main(String args[]){
      salary = 1000;
      System.out.println(DEPARTMENT + "average salary:" + salary);
   }
}

Instance variables:

  • Instance variables are declared in a class, but outside a method, constructor or any block.
  • When a space is allocated for an object in the heap, a slot for each instance variable value is created.
  • Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed.
  • Instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an object's state that must be present throughout the class.
  • Instance variables can be declared in class level before or after use.
  • Access modifiers can be given for instance variables.
  • The instance variables are visible for all methods, constructors and block in the class. Normally, it is recommended to make these variables private (access level). However visibility for subclasses can be given for these variables with the use of access modifiers.
  • Instance variables have default values. For numbers the default value is 0, for Booleans it is false and for object references it is null. Values can be assigned during the declaration or within the constructor.
  • Instance variables can be accessed directly by calling the variable name inside the class. However within static methods and different class ( when instance variables are given accessibility) should be called using the fully qualified name . ObjectReference.VariableName.

 



Share:

Related Posts:

Agravat &Google

Total Pageviews

4,842

Blog Archive

vipul c.Agravat . Powered by Blogger.

myjava

myjava
java

myimg

myimg
good

Translate

Recent Posts

Unordered List

Definition List

Pages

Theme Support