Sunday, 6 October 2013

Abstract class(Abstract class) and interface are opposite side of same coin. You can declare interface by interface interface_name.

Following are the some important points about interface:
  •  Interface contain only method signarute.
  • As like abstract class,interface can not be instantiated.
  • In interface by default member variables are public static final.
  • Interface does not have constructor.
  • One interface can extend multiple interfaces at once. As this is not applicable for classes.
  • To implement a interface we use "implements" keyword.
  • Java contain some empty interfaces like Serialzable, Cloanable...etx. They don't have any method signature.
 Now we will see the difference between abstract class and interface :

Abstract class

This is one of the important and basic features of core Java. You know the class in which you can declare variables,have constructor and member functions,you can create object of an class. As you know in inheritance you can extend one class to another (Inheritance in Java) .

   However abstract class has some different features as following :
  • Abstract class can be declared by preceding abstract keyword to class then class name .i.e abstract class Test { } // this is the abstract class.
  • We can not instantiate abstract class object.
  • Abstract class may inherit another class.
  • Abstract class may contain abstract method (ex. abstract void fun()) which has only signature , it does not have method body.
  • Abstract class may contain non abstract method having body.
  • Abstract class may contain constructor as like normal class.
  • Use of abstract class or interface(Interface) depends upon the scenario where to be used.
  • As like a class it does not allow multiple inheritance.

Final,finally and finalize in java.

This is one of the most famous interview question which is being asked. In this post i will try to explain these three keyword .

Following are the some important points about final in java:
  • If you declare final with variable then that will be considered as constant.You have to initialize constant variable when it is declared or in constructor other wise it throws compile time error.
  • If you use final keyword with method then that method will not be overridden(Overloading and Overriding).
  • If you use final keyword with class then that class can not be extended.
Ex. final int a=12;  //final variable declaration.
      final class Test{ //final class declaration.
      }
    
     class Test
   {
     final void fun() //final method declaration.
     {
     }
   }
    
Few important points about finally :


  • We use finally in context of exception handling.
  • finally is the block of code which it executes either exception is thrown or not.
  • In finally we normally do the task like db connection close,releasing the locked resources...etc
  • In one case finally block will not be executed if you exit from the execution.

Few important points about finalize :
  • finalize is the protected method which is used in context of garbage collection.
  • Signature of this method is protected void finalized() which throws Throwable.
  • This method gets executed before object is getting garbage collected.
  • It gives chance to release allocated resources by an object.

Inheritance in Java

When you start learning ABCD of Java,surely you will see this(Inheritance) keyword . If you come from C++,then you know what is inheritance. However there is some difference between in inheritance in c++ and inheritance in Java. When we proceed through this blog, i will explain .

First of all, inheritance means accessing properties of parent class in child class.Inheritance can be acheived by using extends Class_Name in front of the child class . Ex. class Child extends Parent .

Some important points about inheritance in Java
  • You can only access public ,default,protected member variables and methods in child class.
  • You can not access private members of parent class.
  • Class constructor does not inherits.
  • You can not inherit member variables.
  • You can override (Overriding and overloading)  the methods of parent class in child class.
  • Java does not support multiple inheritance as it leads to diamond problem.
  • You can use reference of parent class and can create object of child class.
I am trying to demonstrate the use of inheritance in simple code :

 public class Inheritance {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Child c=new Child();
        c.printParent();
        c.printChild();
       
    }

}


class Parent
{
    void printParent()
    {
        System.out.println("In parent");
    }
}

class Child extends Parent
{
    void printChild()
    {
        System.out.println("In child");
    }
}

If you think any points are missed the please let me know.

Method overriding and overloading in Java

After going through inheritance now it is time to know about method overriding and overloading.
Method overloading terminology is used where method name is same but it may have different set of parameter list,same parameter with different order. Compile time binding is done for method overloading.

Some important points about method overloading :
  • Method overloading is same method name having different arg list,order withing the class.
  • Binding happens at compile time.
  • Overloaded method must have different sets of param or order or both.
  • Return type in method overloading does not matter as binding happens at compile time.
  • Static method can be overloaded.
Please loot at sample code of overloading :

public class Overload {


    void fun()
    {
      
    }
   
    void fun(int a) //overloaded method of fun
    {
      
    }
}




 Now we will look into method overriding . Method overriding is the concept of overriding the parent method into the child class.
Following are the important points about overriding :


  • Overridden method  has same method signature of parent method.
  • If you mark final method in parent class then that can not be overriden.
  • Binding happens at run time. 
  • One more important point  is if your parent method has throws IOException in signature then in child class overridden method you used "throws Exception", then it shows compile time error .As you can either throw IOException or its child exception.
  • While overriding you can not minimize the visibility of overridden method. It means suppose you have declared public void fun() in your parent class and same method is overridden at child class having void fun() with no visibility mentioned (default) .In such case it throws compile time error.
To be more clear please look at following piece of code:


class Parent
{
    void printParent() throws IOException
    {
        System.out.println("In parent");
    }
}

class Child extends Parent
{
    void printParent() throws IOException
    {
        System.out.println("In child");
    }
}

 

Friday, 4 October 2013

Difference between webdriver and selenium

Now webdriver (selenium 2.0) is the next version of selenium 1.0.  Selenium developers have made some up gradation into webdriver. So i will try to point out those differences as follows ;


  • As selenium injects its core java script into the browser while creating browser profile to drive the operations on browsers like click,type,select ...etc . where as webdriver uses native api of browser to do the operations.
  • Webdriver is pretty faster than selenium 1.0.
  • Webdriver acts like a real user where as selenium is not . Ex. would be suppose you have one alert box and ideally without disappearing that alert box you can not do the operation on web page,such operation can be done by selenium while webdriver does not support it.
  • Webdriver is designed in more object oriented way than selenium.
  • Webdriver supports android and ios app automation.
  • Webdriver supports limited sets of browser , it does not support all the browser which are supported by seleniu 1.0.
Please suggest any point if i have missed here.

Thursday, 3 October 2013

Selenium/Webdriver automation framework using testng.

In this post i will try to explain you about the selenium automation framework using testng.

To build this framework you need following things.
I will explain you the brief explanation of above components in automation framework. This automation framework is the data driver framework because we are keeping data which is input to the automation into mysql database . In later i will explain how the data will driver the execution. We will use basic annotations of testng like @beforetest,@beforesuit,@test ,@aftersuite in framework to do the particular task . @beforetest annoted method gets executed before executing the suite (suite is nothing but a set of test nodes which contains methods,test classes ...),@beforetest annoted methods gets executed before test node of suite ,@aftersuite annoted method gets executed after suite execution. @test annotation will be used to mark method as testng test method , in which we write the actual code for automation. It will support parallel execution of the tests.

To provide the data to the @test method we will use dataprovider from testng. There are two types of data provider one is which returns two dimension object of an array, other one is lazy iterator. So we will use lazy data provider . The difference between these two providers is first one which returns object[][] sends data to the @test annoted method in one pass ,where as lazy data provider sends data one by one , i mean lazy provider sends one set of data to the @test method and waits for its execution completion and sends next set of data. I have implemented this DataProvider as an inner class which implements Iterator<Object[]> interface.

reportng.jar  will be used to generate and html report, This will be used as a third part open source report generator. So use you have to mark this as a listener in your suite xml or in your build.xml

Eclipse  this will be used as an IDE for java development.

Mysql this will be used to store automation related stuffs into the database.

Please find attached sample code and please let me know if you have any concerns.