Sunday 28 February 2016

How to launch a browser browser with out using system.setProperty() method in selenium

How to launch a browser browser with out using system.setProperty() method in selenium:
=====================================================================
For example take the IE browser.......
The very first issue anybody would face with IE Browser is that people expect IE Browser to work exactly like the Firefox Browser in Selenium. See what happens when you use the below Selenium Script to Open an application on IE Browser.
public class IEExplorerTest 
{

public static void main(String[] args) 
{

InternetExplorerDriver  driver = new InternetExplorerDriver();
driver.get(" http://rameshselenium.blogspot.in/");

}
}

Once the above code is executed, Selenium will throw an exception:

Exception in thread “main” java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html

The exception clearly says that the path to the driver must be set by the webdriver.ie.driver system property. This error typically is caused by either not having the required IEDriverServer.exe on your local machine or not having it setup in your PATH environment variable
How to set the path environment variable for IE Browser 
Open the Control Panel -> System or Security –> System; the same thing can be done by right-clicking on ‘My Computer’ and choosing Properties.

Choose ‘Advanced system settings‘.

 Under the Advanced tab Choose the ‘Environment Variable…‘ option.

Now we need to specify the location in the PATH variable. For PATH, most probably it already exists in your machine. So just select it and choose the Edit option.

In the editor add the value ‘Your Location of IE Browser‘(i.e: IE driver path which is downloaded) and click OK.

Note: The new values are separated by a semicolon from the existing ones and be careful and do not make any changes in the existing string, as it is very sensitive information.
Now try opening an IE Browser without specifying System Property in the Selenium        Script.

public class IEExplorerTest 
{

public static void main(String[] args) 
{

InternetExplorerDriver  driver = new InternetExplorerDriver();
driver.get(" http://rameshselenium.blogspot.in/");

}
}
Note: In case it does not work, please reboot the machine.
After executing above steps , still if we get the exception as 
 “java.lang.WebDriverException” 
           For the above write the code as below....
public class IEExplorerTest 
{

public static void main(String[] args) 
{
Try
{
InternetExplorerDriver  driver = new InternetExplorerDriver();
Thread.sleep(“2000”);
driver.get(" http://rameshselenium.blogspot.in/");
}
Catch(Exception e)
{
e.printStackTrace();
}

}

Thursday 18 February 2016

What is build and release

What is build and release:
=====================
1. Build is Executable file. Release means which ready to use it. Version is extension of the build.

2.  Build is handed over to the tester to test the developed part of the project. Release hand it over to Client/Customer after completion of development and testing phase. Version is number of release made according to the addition of requirement of the client.

3. Build refers to the S/W part which  still in testing. or which is not tested yet. Release refers to the S/W which is no longer in testing. Version refer Variation of an earlier or original type of S/W

4.  Build can be rejected by test team if defect found or it does not meet the certain requirement. One Release can have several builds associated with it. Version  based on the Build, not Vice Versa..

5. Build is nothing but a part of the application. Release is noting but the application. Version is nothing but the application.

6. Build:t is a executable set of code file for the s/w application handed over to the tester to test the developed functionality.


Difference between quit() and close() in selenium

Difference between quit() and close() in selenium:
======================================
driver.close() and driver.quit() are two different methods for closing the browser session in Selenium WebDriver.

driver.close – It closes the the browser window on which the focus is set.
driver.quit – It basically calls driver.dispose method which in turn closes all the browser windows and ends the WebDriver session gracefully.
Basically quit( ) WebDriver command is generally used to shut down the WebDrivers instance. Hence it closes all the Browser windows that are opened by the Selenium Automation.

You should use driver.quit whenever you want to end the program. It will close all opened browser window and terminates the WebDriver session. If you do not use driver.quit at the end of program, WebDriver session will not close properly and files would not be cleared off memory. This may result in memory leak errors.

Wednesday 17 February 2016

Solution for sendkeys(CharSequence) in Selenium

Solution for sendkeys(CharSequence) in Selenium:
=======================================
When ever you are facing this problem ” sendKeys (CharSequence) from the type Webelement refers to the missing type charSequence“  Just do the following then it will be resolved.

1- Change the compiler version from old version to 1.5 or greater.
2- Change the JRE version from JRE8 to JRE7.

How to change the compiler version:
-------------------------------------

1.select the project
2.Right click
3.Build path
4.Configure build path
5.Librarys
6.Add library
7.Select the jvm version
8.Click pon OK

Now the problem will be resolved.

Now time to enjoy with testing.

How to highlight elements in Selenium Webdriver

How to highlight elements in Selenium Webdriver:
========================================
We can highlight the elements in Selenium Webdriver by taking support of JavascriptExecutor interface.
This interface is having one method called executeScript(--),by usiu=ng this method we can highlate the elements when the action is performing


//sample example
----------------------
package files;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class HighLateDemo {

public static void main(String []args) throws InterruptedException{
 
 WebDriver driver=new FirefoxDriver();
 
 driver.manage().window().maximize();
 
 driver.get("http://www.gmail.com");
 
 JavascriptExecutor js=(JavascriptExecutor)driver; 
 
 WebElement username= driver.findElement(By.id("Email"));  

 js.executeScript("arguments[0].style.border='4px groove green'", username);
 
 username.sendKeys("rameshat914@gmail.com");
 
 WebElement next = driver.findElement(By.id("next"));
 
 js.executeScript("arguments[0].style.border='4px groove green'", next);
 
 next.click();
 
 Thread.sleep(3000);
 
 WebElement password = driver.findElement(By.id("Passwd"));
 
 js.executeScript("arguments[0].style.border='4px groove green'", password);
 
 password.clear();
 
 password.sendKeys("selenium");
 
 WebElement signin = driver.findElement(By.id("signIn"));
 
 js.executeScript("arguments[0].style.border='4px groove green'", signin);
 
 signin.click();
 
 driver.quit();
 
}

}

Tuesday 16 February 2016

How to write data to a excel using JExcel API

How to write data to a excel using JExcel API:
===================================
JExcel is free API to work with Excel files;
Basically api is an collection of predefined classes and interfaces...
Following are the regularly used classes and interfaces to read data
Workbook (Class) – Will handle workbook.
Sheet (Interface) – Which will handle sheets
Cell (Interface) – Which will handle cell

Download JExcel API:
-------------------------------
OPEN GOOGLE-->DOWNLOAD JXCEL API

OR

http://mirrors.ibiblio.org/pub/mirrors/maven/net.sourceforge.jexcelapi/jars/jxl-2.6.jar

AFTER DOWNLOADING ADD THAT JXCEL JAR FILE IN TO YOUR PROJECT.


//Sample program on how to write data from jexcel
-------------------------------------------------------------------


How to write:
==============
import java.io.IOException;
import java.util.Date;

import jxl.*;
import jxl.write.*;
import jxl.write.Boolean;
import jxl.write.Number;
import java.io.File;

import org.testng.annotations.Test;

public class JexcelWriteData {

@Test
public void writeData() {

try {
           File exlFile = new File("c:/ramesh/testdata.xls");
           WritableWorkbook writableWorkbook = Workbook
                   .createWorkbook(exlFile);
 
           WritableSheet writableSheet = writableWorkbook.createSheet(
                   "Sheet1", 0);
           Label label = new Label(0, 0, "Label (String)");
           DateTime date = new DateTime(1, 0, new Date());
           Boolean bool = new Boolean(2, 0, true);
           Number num = new Number(3, 0, 9.99);
 
           //Add the created Cells to the sheet
           writableSheet.addCell(label);
           writableSheet.addCell(date);
           writableSheet.addCell(bool);
           writableSheet.addCell(num);
 
           //Write and close the workbook
           writableWorkbook.write();
           writableWorkbook.close();
 
       } catch (IOException e) {
           e.printStackTrace();
       } catch (RowsExceededException e) {
           e.printStackTrace();
       } catch (WriteException e) {
           e.printStackTrace();
       }
   }
}
}
Note:For APACHE API visit our posts in blog

How to read data from excel sheet using JEXcel

How to read data from excel sheet using JEXcel:
=====================================
JExcel is free API to work with Excel files;
Basically api is an collection of predefined classes and interfaces...
Following are the regularly used classes and interfaces to read data
Workbook (Class) – Will handle workbook.
Sheet (Interface) – Which will handle sheets
Cell (Interface) – Which will handle cell

Download JExcel API:
----------------------
OPEN GOOGLE-->DOWNLOAD JXCEL API

OR

http://mirrors.ibiblio.org/pub/mirrors/maven/net.sourceforge.jexcelapi/jars/jxl-2.6.jar

AFTER DOWNLOADING ADD THAT JXCEL JAR FILE IN TO YOUR PROJECT.


//Sample program on how to read data from jexcel
-----------------------------------------------------

import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.testng.annotations.Test;

public class JexcelRead {

@Test
public void readData() {

File src=new File("./data/testdata.xls");
 
try {
 
Workbook workBook = Workbook.getWorkbook(src);
 
Sheet sheet=    workBook.getSheet(0);
 
Cell  cell = sheet.getCell(0,0);
 
String cellData=cell.getContents();
 
System.out.println(cellData);
 
System.out.println("Sheet data is "+cellData);
 
}
catch (Exception e) {

e.printStackTrace();
 

 
}
}

Note:If you want APACHE API please refer our previous posts in my blog

Windows authentication in selenium

Windows authentication in selenium:
=============================
We can handle window authentication in 2 ways
1.Using selenium webdriver
2.Using Autoit tool

1.Using selenium webdriver:
----------------------------
Syntax
http://username:password@url
------------------------------
Example :
http://selenium:realtime@www.someurl.com


//sample example code:

package assignments;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;

public class BrowserAuthDemo {

public static void main(String[] args) throws InterruptedException {

WebDriver d = new FirefoxDriver();

d.manage().window().maximize();

d.manage().deleteAllCookies();

d.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

d.get("http://selenium:realtime@www.engprod-charter.net/");

Thread.sleep(3000);

d.quit();
}

}

How to read data from CSV file

How to read data from CSV file:
========================

What is CSV file:
----------------------
CSV stands for comma separated values.
In CSV file we are going to place the values by separating with comma.

"rameshsoft","seleniumexperts"
"realtime","training"

How to create CSV files:
------------------------------
Open notepad-->Enter values("rameshsoft","seleniumexperts")-->save the file in .csv format

How to read CSV files:
-----------------------------
In order to read data from CSV files we need to take support from third party api tools called "OPENCSV"(http://opencsv.sourceforge.net/)

Download the jar from the above site.
Add the jar file in to your eclipse.-->Right click on the project-->selevt build path-->select configure build path-->add external jars-->select the corresponding jars-->click on open.

//SAMPLE EXAMPLE ON HOW TO READ CSV FILE DATA
------------------------------------------------------------------------------
package assignments;

import java.io.FileReader;
import java.util.Iterator;
import java.util.List;

public class CsvReadDemo {

public static void main(String[] args) {

// This will load csv file
CSVReader reader = new CSVReader(new FileReader(
"C:\\Users\\mukesh_otwani\\Desktop\\demo.csv"));

// this will load csv content into list
List list = reader.readAll();

System.out.println("Total rows which we have is " + list.size());

Iterator iterator = list.iterator();


while (iterator.hasNext()) {

String str = (String) iterator.next();

System.out.print(" Values are :" + str);

}
}

}

Sunday 14 February 2016

Sample automation testcase on flipkart application

Automate the following testcase:
=========================

1.Open a browser
2.Enter url as www.flipkart.com
3.Check whether flipkart page is opened or not
4.If it is opened perform the required operations and display on the console that flipkart page is opened.
5.Perform mouse over electronics
6.Click on Mobiles
7.Click on samsung
8.Select the price range
9.Select the first mobile
10.Close the browser

Automation script:
-------------------------
FlipKartTestCase.java
----------------------------

package assignments;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class FlipKartTestCaseOne {

WebDriver webDriver;

String expecteTitle = "";
String actualValue;

@BeforeSuite
public void launchingIEBrowser() {

System.setProperty("webdriver.chrome.driver","D:\\Ramesh\\ChromeDriver.exe");
  webDriver = new ChromeDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

}

@AfterSuite
public void closeBrowser() {
webDriver.quit();

}

@Test
public void testScript() throws InterruptedException {

webDriver.get("https://www.flipkart.com");
actualValue = webDriver.getTitle();
if (actualValue.equalsIgnoreCase(expecteTitle)) {

Actions a = new Actions(webDriver);
a.moveToElement(
webDriver.findElement(By
.xpath("//span[text()='Electronics']"))).build()
.perform();
Thread.sleep(2000);

// clcik on mobiles
webDriver
.findElement(
By.xpath("//*[@id='submenu_electronics']/div[2]/div[1]/ul[1]/li[1]/a"))
.click();
Thread.sleep(2000);

// click on samsung
webDriver.findElement(
By.xpath("//*[@data-tracking-id='Top Brands_Samsung']"))
.click();
Thread.sleep(2000);

// select the price range
webDriver.findElement(
By.xpath("//*[@id='price_range']/li[2]/a/span[1]")).click();
Thread.sleep(3000);

// click on moblie
webDriver.findElement(
By.xpath("//*[@class='pu-visual-section']/a[1]")).click();
;
Thread.sleep(3000);
}

}

}

Thursday 11 February 2016

Difference between testing tool and testing framework

Difference between testing tool and testing framework:
=========================================
Tool:
-------
A testing tool or software development tool is a computer program that  use to create, debug, maintain, or otherwise support other programs and applications.

A tool is used to test the applications.

Tool is dependent on the environment

Selenium is a tool  which works on browsers for web based applications

Framework:
-----------------

A framework is a semi completed application,based on our requirements we can customize it its called framework.
Using testing tools we build the testing frameworks





Difference between pom.xml(maven) and build.xml(ant)

Difference between pom.xml(maven) and build.xml(ant):
============================================
1.Maven doesn't have formal conventions like a common project directory structure, you have to tell Ant exactly where to find the source and where to put the output. Informal conventions have emerged over time, but they haven't been codified into the product.
                    Ant has conventions, it already knew where your source code was because you followed    the convention. It put the byte code in target/classes, and it produced a JAR file in target.

2.Maven has a convention to place source code, compiled code etc. So we don't need to provide information about the project structure in pom.xml file
         Ant doesn't has formal conventions, so we need to provide information of the project structure in build.xml file.

3.Ant is a tool box.
                      Maven is a framework.
4.Ant is mainly a build tool.
                      Maven is mainly a project management tool.
5.Ant scripts are not reusable.
                      Maven plugins are reusable. 
6.Ant is procedural, you need to provide information about what to do and when to do through code. You need to provide order.
                        Maven is declarative, everything you define in the pom.xml file.

Swapping of two numbers without using temporary variable

Swapping of two numbers without using temporary variable:
===============================================
1st way:
=======
package files;

public class SwapProgDemo {

public static void main(String[] args) {

int x = 10;

        int y = 20;
        
        System.out.println("Before swap:");
        System.out.println("x value: "+x);
        System.out.println("y value: "+y);
        
        x = x+y;
        y = x-y;
        x = x-y;
        
        System.out.println("After swap:");
        System.out.println("x value: "+x);
        System.out.println("y value: "+y);

}

}

OUTPUT:
--------------
Before swap:
x value: 10
y value: 20
After swap:
x value: 20
y value: 10


2nd way:
========

package files;

public class SwappROGdEMO {
public static void main(String[] args) {
int x = 10;
        int y = 20;
        
        System.out.println("Before swap:");
        System.out.println("x value: "+x);
        System.out.println("y value: "+y);
        
        x = x*y;
        y = x/y;
        x = x/y;
        
        
        System.out.println("After swap:");
        System.out.println("x value: "+x);
        System.out.println("y value: "+y);
}
}

OUTPUT:
--------------
Before swap:
x value: 10
y value: 20
After swap:
x value: 20
y value: 10



Swamping of two numbers using temporary variable

Swamping of two numbers using temporary variable:
=======================================
package files;

public class SwapDemo {

public static void main(String[] args) {

int x = 20, y = 30,temp;

System.out.println("Before Swapping\nx = " + x + "\ny = " + y);

temp = x;
x  =  y;
y  =  temp;

System.out.println("After Swapping\nx = " + x + "\ny = " + y);
}

}

OUTPUT:
=========
Before Swapping
x = 20
y = 30
After Swapping
x = 30

y = 20

Wednesday 10 February 2016

File uploading in selenium @ 3 ways

File uploading in selenium @ 3 ways:
=============================
We can upload a file using 3 ways

1.Using WebDriver sendKeys() method
2.Using Autoit tool
3.Using Robot class and StringSelection java class

1.Using WebDriver sendKeys() method:
===============================
If we want to upload a file we can upload by using webdriver sendKeys() method.
//example:
-----------
package blog;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class FileUploadSendKeys {

WebDriver webDriver;

@BeforeSuite
public void launchingIEBrowser() {

System.setProperty("webdriver.chrome.driver",
"D:\\Ramesh\\ChromeDriver.exe");
webDriver = new ChromeDriver();

// webDriver = new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

}

@Test
public void testScript() throws InterruptedException, AWTException {

webDriver.get("https://www.sendspace.com/");

webDriver.findElement(By.id("upload_file")).sendKeys(
"C:\\Users\\aramesh\\Desktop\\abc.txt");
;
Thread.sleep(2000);

}

@AfterSuite
public void closeBrowser() {
webDriver.quit();

}

}

2.Using Robot class:
================

Robot class is used to (generate native system input events) take the control of mouse and keyboard. Once you get the control, you can do any type of operation related to mouse and keyboard through with java code.

There are different methods which robot class uses. Here in the below example we have used 'keyPress' and 'keyRelease' methods.

keyPress:
-------------
This method with press down arrow key of Keyboard.
Example: robot.keyPress(KeyEvent.VK_DOWN).

keyrelease:
--------------
This method with release down arrow key of Keyboard
Example: robot.keyRelease(KeyEvent.VK_DOWN) 

mousePress():
-----------------
This method will press the right click of your mouse.
mouseMove() :  This will move mouse pointer to the specified X and Y coordinates.
Example: robot.mouseMove(point.getX(), point.getY()):


mouseRelease():
--------------------
This method will release the right click of your mouse.

robot.keyPress(KeyEvent.VK_DOWN):
---------------------------------------------------
To press down arrow key of Keyboard.

robot.keyPress(KeyEvent.VK_TAB):
------------------------------------------------
To press TAB key of keyboard


robot.keyPress(KeyEvent.VK_ENTER):
---------------------------------------------------
To press copy key from the keyboard

robot.keyRelease(KeyEvent.VK_ENTER):
------------------------------------------------------
To press release copy key from the keyboard

robot.keyPress(KeyEvent.VK_ENTER):
----------------------------------------------------
To press Enter key from the keyboard

//example:
--------------
package blog;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class RobotFileUpload {

WebDriver webDriver;

@BeforeSuite
public void launchingIEBrowser() {

System.setProperty("webdriver.chrome.driver",
"D:\\Ramesh\\ChromeDriver.exe");
webDriver = new ChromeDriver();

// webDriver = new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

}

@Test
public void testScript() throws InterruptedException, AWTException {

webDriver.get("https://www.sendspace.com/");

webDriver.findElement(By.id("upload_file")).click();
Thread.sleep(2000);
// StringSelection is a class that can be used for copy and paste
// operations.
StringSelection stringSelection = new StringSelection(
"C:\\Users\\aramesh\\Desktop\\abc.txt");
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(stringSelection, null);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
// press enter key of keyboard to perform above selected action
robot.keyRelease(KeyEvent.VK_ENTER);
// release the neter key

Thread.sleep(4000);

webDriver.findElement(By.name("recpemail_fcbkinput")).sendKeys(
"rameshat914@gmail.com");

webDriver.findElement(By.id("ownemail")).sendKeys(
"rameshat914@gmail.com");

Thread.sleep(8000);

}

@AfterSuite
public void closeBrowser() {
webDriver.quit();

}

}

3.Using autoit:
============
Please refer the post autoit in our blog@rameshselenium.blogspot.in

Tuesday 9 February 2016

Java source file structure

Java source file structure:
====================
1. A java program can contain any number of classes.
2. Compulsory one class should be declared as public
3. If there is a public class then name of the program and name of the public class must be matched or same,otherwise we will get compile time error.
4. The class which you declared as public,write main() method in that class.

SampleDemo.java:
------------------
              class First
              {
                   ;;;
                   ;;;
                   ;;;
               }

              class Second
              {
                 ;;;;;
                 ;;;;;
                 ;;;;;
               }

              public class SampleDemo
              {
                 ;;;;;
                 ;;;;;
                 ;;;;;
              }


Naming conventions:
================
1.Every class should start with capital letter and if it is having multiple words,every word start with capital letter.

ex:
      class Sample
      {
                 ;;;
       }

      class SampleDemo
      {
              ;;;
       }

2.Every variable name should start with small letter and if it is having multiple words first word start with small letter,next words start with capital letter.

ex:
           int number=10;
           int firstNumber=30;

3.Every method name should start with small letter.

               public void display()
              {
                      ;;;;
                      ;;;;

              }

Types of variables in JAVA

Types of variables in JAVA:
======================
There are 2 types of variables 
1.Primitive variables
2.Reference variables

Primitive variables:
--------------------------
Primitive variables are used to represent primitive values like 

integer etc...
ex:int a=10;


Primitive variables are divided in to 3 types.
      1.Instance variables
      2.Static variables
      3.Local variables

1.Instance variables:
---------------------------
If the value of a variable keep on changes or its varies from 

object to object then that type of variables are called Instance 

variables.

syntax:
----------
  datatype variablename = variablevalue;
----------------------------------------------------

Instance variables should be declared within the class directly.

For every object a separate copy of instance will be created.

Instance variables will be stored in the heap memory.

Instance variables will be created at the time of object 

creation and destroyed at the time object destruction.

Instance variables are also called as object level variables.


Default values:
--------------------
If we dont perform initialization For instance variables JVM 

provide values.
(integer====0)
(float====0.0)
(String ===null) etc...
ex:
package blog;

public class DefaultDemo {

int a,b;
String name;

public static void main(String[] args) {

DefaultDemo defaultDemo = new DefaultDemo();

System.out.println(defaultDemo.a);//0
System.out.println(defaultDemo.name);//null

}

}

In order to access instance variables compulsory we need to create the object.

static variables:
---------------------
If the value of a variable is not varied from object to object 

then declare such type of variables as static variables.

If we want to convey a variable as static declare that variable with static modifier.

syntax:
--------

 static datatype variable name = variable value;
--------------------------------------------------------------
For static variables a single copy will be created at class 

level.

static variables will be created at the time of class loading 

and will be destroyed at the time of class unloading.


Default values:
--------------------
If we dont perform initialization For instance variables JVM 

provide values.
(integer====0)
(float====0.0)
(String ===null) etc...
ex:
package blog;

public class DefaultDemo {

static int a,b;
static String name;

public static void main(String[] args) {

DefaultDemo defaultDemo = new DefaultDemo();

System.out.println(defaultDemo.a);//0
System.out.println(defaultDemo.name);//null

}

}


We can access static variables in 3 ways
1.By using classname
2.Direclty by calling their names
3.By using object

Local variables:
---------------------
Based on requirements some times we need to use some variables at certain extent level only.
When ever we declare a variable inside the method or constructor such type of variables we can call it as local variables

Local variables will be stored in stack memory.
For local variables compulsory we need to perform initialization

The scope of local variable is within that particular method only and when you try to access outside of that we will get compile time error.

package blog;

public class DefaultDemo {

public static void main(String[] args) {

int a;
System.out.println(a);//compile time error...a is local variable should perform      initialisation

}

}


Reference variables:
---------------------------
Reference variables are used to represent or to refer objects.

Ex:Employee emp = new Employee();