About Variables In Java Programming

In this tutorials we will discussed more about variables in java programming of Class Or Static, Instance, Local and Parameters Or Arguments. 


Types of variables:

Class Or Static 
Instance 
Local
Parameters Or Arguments 



What we need before start the code, I'm using as mention below and already installed in my system:
1. JDK1.6 or +
2. Eclipse
3. Windows OS
4. Basic knowledge of java

Let's start:



Verify the JDK installation

Open the command prompt and verify the java installation
Type the 
C:\>javac -version
javac 1.7.0_25

C:\>java -version

java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

Now java installation got verified, as installed JDK1.7.0_25

Verify the Eclipse installation

Go the the installation directory of eclipse and click on the eclipse.exe
e.g C:\eclipse\eclipse-java-mars-1-win32\eclipse\eclipse.exe

Create the new java project in Eclipse:

Open the eclipse

File
New
Java project
Type the project name: Variables_In_Java_Programming
Next
Finish

Create the VariablesInJavaProgramming.java file


Right click on the src created under project Variables_In_Java_Programming

New
Class
Type the name of class: VariablesInJavaProgramming 
Type the package name: com.variables.atozexamples
Finish


package com.variables.atozexamples;

public class VariablesInJavaProgramming {

       // Declared and instantiated with 100 value
       // This is also called as filed.
       private int iInstanceVariables = 100;

       // Class or Static variable
       public static int iClassOrStaticVarible = 1;

       // Class or Static variable as final, we can't change the value and name
       // must be in capital
       public static final int I_CLASS_OR_STATIC_FINAL_VARIBLE = 200;

       // Default Constructor
       public VariablesInJavaProgramming() {
       }

       // Constructor
       public VariablesInJavaProgramming(int iParameterOrArgument) {
              // Overriding the value of iInstanceVariables by iParameterOrArgument
              // value.
              this.iInstanceVariables = iParameterOrArgument;
       }

       private void print(Object oParameter) {
              Object oLocalVaribles = oParameter;
              System.out.println(oLocalVaribles);
       }

       public static void main(String[] args) {
              VariablesInJavaProgramming objVariablesInJavaProgramming
                         new VariablesInJavaProgramming();
              objVariablesInJavaProgramming
                           .print("Hello iInstanceVariables you have value =" +                                       objVariablesInJavaProgramming.iInstanceVariables);

              objVariablesInJavaProgramming.iInstanceVariables = 300;
              objVariablesInJavaProgramming
                           .print("Hello iInstanceVariables you have value =" +                                      objVariablesInJavaProgramming.iInstanceVariables);

              objVariablesInJavaProgramming.print("Hello iClassOrStaticVarible " +
                "you have value =" + iClassOrStaticVarible);

              objVariablesInJavaProgramming.iClassOrStaticVarible = 2004;

              objVariablesInJavaProgramming.print("Hello iClassOrStaticVarible "+
                   "you have value =" + iClassOrStaticVarible);

              VariablesInJavaProgramming objVariablesInJavaProgrammingOne
                       new VariablesInJavaProgramming();
              objVariablesInJavaProgrammingOne.print("Hello iClassOrStaticVarible "+
                     " you have value =" + iClassOrStaticVarible);

              objVariablesInJavaProgramming
                           .print("Hello I_CLASS_OR_STATIC_FINAL_VARIBLE you have "+
                         "value =" + I_CLASS_OR_STATIC_FINAL_VARIBLE);

              VariablesInJavaProgramming objVariablesInJavaProgrammingTwo
                    new VariablesInJavaProgramming(500);
              objVariablesInJavaProgrammingTwo.print(
                    "Hello iInstanceVariables you have value =" +                                      objVariablesInJavaProgrammingTwo.iInstanceVariables);

              objVariablesInJavaProgramming = null;
              objVariablesInJavaProgrammingOne = null;
              objVariablesInJavaProgrammingTwo = null;

              objVariablesInJavaProgrammingTwo.print(
                     "Hello iInstanceVariables you have value =" +                                           objVariablesInJavaProgrammingTwo.iInstanceVariables);

       }

}





All about all java variables in sing place.

No comments:

Post a Comment