Escolar Documentos
Profissional Documentos
Cultura Documentos
Selenium Overview
Seleniumis a portablesoftware testing
frameworkforweb applications.
Selenium provides a record/playback
tool for authoring tests without learning
a testscripting language(Selenium IDE)
Selenium provides a domain specific
language i.e, tests can be written in any
language like java, c#...
Selenium can be deployed on any
platform.
Components
Features of java
Simple
Secure
Portable
Object oriented
Robust
Multithreaded
Architecture neutral
Interpreted
High performance
Distributed
dynamic
OOP Principles
Data Abstraction
Encapsulation
Polymorphism
Inheritance
Data abstraction
Encapsulation
Encapsulation literally means to enclose in or as if in
a capsule.
Encapsulation is defined as the process of enclosing
one or more items with in a physical or logical section.
It involves preventing access to non essential details
Ex:when u plug in the cord of the vaccum cleaner and
turn on the switch, the vaccum cleaner starts.we do
not see the complex process needed to actually
convert electricity into suction power.
In other words,the exact working of the cleaner has
been encapsulated.
Therefore encapsulation is also defined as information
hiding or data hiding because it involves hiding many
of the important details of an object from the user.
polymorphism
It is the ability that helps in executing
different operations in response to the
same message.
We can implement polymorphism by
creating more than one function with in a
function within a class that have the same
name.
The difference in the functions lies in the
number and types of parameters passed to
each function.
Inheritance
Deriving the properties from parent
to child is inheritance
with parent reference ,we can access
child class methods
With child reference, we cannot
access parent class methods
Program made up of
Program made of
1.Keywords
2.Identifiers
3.Literals
Ex: Int EmpId =10310;
Int = keyword
EmpId =identifier
10310 =literal
//documentation section
//package section
//import section
//class section
{
Variables
Methods
}
Comments // for single line comment
Multiline comment /*-------*/
Platform independence
The output of java compiler is not
executable code. rather it is byte code.
Byte code is highly optimized set of
instructions designed to be executed by
java run time system, which is called
java virtual machine.
Translating a java program into byte
code helps makes it easier to run a
program in a wide variety of
environments. Only the JVM needs to be
implemented for each platform.
Explanation of structure
note
1.Every java program should have class
definition block
class ClassName
{
body
}
2.While saving a java program the file name
should be same as class name
3.Inside class body we can develop any java
script
Main method is mandatory to start the
execution
4.Java file is compiled using a command javac
Note contd.
5.compiler generates .class file if there are no
errors
6.by default .class file will be saved in same
location where java file is saved
7.every statement in java must be terminated by ;
8.The java class can be executed by using a cmd
java ClassName
9.When ever a class is executed java starts the
execution by running main method
10.Java executes all the statements sequentially of
main method
11.Java throws error if main method is not defined .
Datatypes in java
String class
If(condition){ statment1;}
If-else
If (condition){stat1}else{stat2;}
If(condition){stat1}-else if(condition){stat2}
Switchstatement allows a variable to be
tested for equality against a list of values.
switch(expression){
case value1 : //Statements
break;
default : //Statements }
Concatenation operator
}
}
//for numbers + symbol acts as arthemetic operator
//for non numerics +symbol acts as concatenation operator
loops
Arrays
Grouping the data objects of same
type in a contiguous block of
memory.
Array is an object created with new
operator.
Array index starts with zero.
Array size cannot be resized.
Initialization of Array
-> Primitive Array:
Int[] myArray={1,2,3,4,5}
-> Explicit initialization:
MyArray[0]=10;
MyArray[1]=20;
Two dimensional Array:
int sample[][] = new int[3][3];
Drawbacks of Array
Large arrays take up space.
Arrays can hold only one data
type at a time.
Searching and sorting arrays is
difficult.
Inserting and removing data
from arrays is clumsy.
Local Variables
Local variable are variables defined
inside methods, constructors or
blocks.
The variable will be declared and
initialized within the method and the
variable will be destroyed when the
method has completed.
Global variable
Global variables are declared in a class,
but outside a method, constructor or any
block.
Global variables can be accessed any
where in the class ,methods defined in
the class.
EX
public class Test {
static int a= 6 ;
int b= 8;
public static void main(String[] args) {
Test obj1=new Test();
Test obj2=new Test();
obj1.a=10;
obj2.a=12;
obj1.b=24;
obj2.b=3 6 ;
System.out.println("Static a + obj1.a); //12
System.out.println("Static a + obj2.a); //12
System.out.println("Static a +a); //12
System.out.println("Static b + obj1.b); //24
System.out.println("Static b +obj2.b); //36
}
}
Static Function
public class A {
static int add(int i,int j) {
return( I + j);
}
}
public class B extends A {
public static void main(String args[]) {
int s= 9;
System.out.println(add(s, 6 ));
}
}
Static/NonStatic members
works
when ever a java program is executed
.....the following steps happen
i)memory is allotted for execution
ii)and this memory is divided into heap
and stack
iii)java enter into stack and calls class
loader
iv)the class loader loads static members
of class into heap memory.
Call By Value
Passing a value held in the variable as
an argument to the method.
The value is copied to method
parameters and changes takes place
to that parameters.
That is why changes made to the
variable within the method had no
effect on the variable that was
passed.
Call By Reference
The Object is passed as an argument
to the method.
No copy of object is made here.
Changes made in the method will be
reflected in the original object
constructors
It can be tedious to initialize all of the variables in a
class each time an instance is created.
it would be simpler and more concise to have all of
the setup done at the time the object is first created.
Java allows objects to initialize themselves when
they are created. This automatic initialization is
performed through the use of a constructor.
Constructor is a special block in java class invoked at
the time of object creation
Constructor should always be public
A constructor name is same as class name ,the
constructor should not have return type and
return statement
Whenever we create an object , the constructor body
will get executed.
constructor
Constructor gets
executed only when
object is created
Constructor name will
be same as class name
Constructor should not
have return type
Constructor will get
executed only once per
object
Super keyword
Using super keyword
We can call immediate super class
instance variable.
this
1.this keyword can be used to refer current class
instance variable.
2.this() can be used to invoke current class constructor
3.this keyword can be used to invoke current class
method (implicitly).
4.this can be passed as an argument in the method call
5.this can be passed as argument in the constructor call
6.this keyword can also be used to return the class
instance.
7.We cannot use this and super at a time
final
Final is the keyword to avoid
inheritance
We use final in three ways
1.Before a variable(you cant change)
2.Before a method (you cant over
ride)
3.Before a class(you cant inherit)
Inheritance
Deriving members of one class to another class is known as
inheritance.
The class from where member s are inherited are known a
super class or base class
The class to which members are inherited are known as
subclass or derived class
The general syntax to write inheritance class
Class SubClassName extends SuperClassName
Using extends keyword a class can inherit from super class
Always inheritance happens from super class to subclass.
Static members of the super class will not be inherited to
subclass because the static members will not be loaded into
object memory
Whenever an object of subclass is created both super class
member and sub class member will be loaded into object
Inheritance happens through constructor chain.
Inheritance contd
Whenever an object of sub class is
created ,the subclass constructor
calls super class constructor ,the
super class constructor calls its super
class constructor . this is known as
constructor chain.
Types of inheritance
Interface
Interface
Abstract class
It is partly unimplemented or partly
implemented class which contains zero or
more abstract methods
Concrete method is the method with body
Abstract method is the method with out
body
If user want to inherit the abstract
class;he need to extend but not
implement
Abstract class
Partly implemented or
unimplemented structure
Can contain variables
Can contain constructors
Abstract class object get
created automatically
when sub class object
got created
Uses extends
Over loading
Overloading is about creating multiple methods
with the same name, but different signatures, in
the same scope.
overloading can take place in the same class or
in the subclass.
overloaded methodsMUSThave a different
argument list.
overloaded methodsMAYchange the return type
(in case argument list is different).
overloaded methodsMAYchange the access
modifier.
reference type determines which overloaded
method will be used at compile time.
constructorsMAYbe overloaded .
Over Riding
Overriding is about changing the behavior of a certain
method in the child class from the way it is behaving in
the parent class.
AppliesONLYto inherited methods
is related to polymorphism
object type (NOTreference variable type) determines
which over riden method will be used at runtime
overriding methodMUSThave the same argument list
(if not, it might be a case of overloading)
Abstract methodsMUSTbe overridden
Final methodsCANNOTbe overridden
Static methodsCANNOTbe overridden
ConstructorsCANNOTbe overridden
Packages
Exception Handling
->Exception is an Event which halts
normal execution abruptly and
alternatively the program will be
terminated.
Exception occurs when our code asks JVM
to do technically impossible tasks.
Ex:Divide by Zero.
All Exception classes are subclasses of
Throwable.
Throwable has two subclass :Exception
and Error
contd
Types of Exception
1)Checked Exception: A checked exception is an
exception
that is typically a user error or a problem that cannot
be foreseen by the programmer.
EX: If a file is to be opened, but the file cannot be found,
an exception occurs
2)A runtime exception is an exception that occurs that
probably could have been avoided by the programmer.
EX:ArrayIndexOutOfBoundException
3)Error describes internal error and resource exhaustion.
Mostly beyond the programmers control.
Exception Handling
1. Anticipate the error by the user/system.
2. Return the program to a safe state that
enables
the
user
to
execute
other
commands.
3. Inform the user of the errors cause.
4. Allow the user to save work and terminate
the program gracefully.
63
Keywords of Exception
Try
Catch
Throw
Throws
finally
Try-Catch block
In this mechanism Try block will
contain the code which may throw
the exception.
Catch block will declare the type of
exception occurred.
EX:try{
}
catch(Exception E){
}
Throws-Throws
If a method does not handle a checked
exception, throws keyword should be used
at the end of a method's signature.
To explicitly throw the exception of a newly
instantiated one or an exception that you
just caught, we use Throw keyword.
EX: public void deposit(double amount)
throws RemoteException { // Method
implementation throw new
RemoteException(); } //Remainder of class
definition }
Finally
The finally keyword is used to create
a block of code that follows a try
block. A finally block of code always
executes, whether or not an
exception has occurred.
A finally block appears at the end of
the catch blocks .
Collections
Collection is a set containing the classes
and interfaces which implements reusable
data structures like List,Array,HashTable.
There are so many interfaces available like
java.util.ArrayList;
java.util.Iterator;
java.util.List;
java.util.ListIterator;
Array List
1)We are Creating the ArrayList as
ArrayList<String> list =
newArrayList<String>();
2)To add elements to the list is
list.add("A");
List.add(2,S);//index=2
3)To get the element from list
list.get(index).
stack
Stack is a subclass of Vector that
implements a standard last-in, firstout stack.
boolean empty()
Object peek( )
Object pop( )
Object push(Object element)
int search(Object element)
HashTable
Thejava.util.Hashtableclass implements
a hashtable, which maps keys to values.
Hash function will compute unique value
as a index to the key.
Methods are:
Set<Map.Entry<K,V>> entrySet()
Collection<String> collection =ht.values();
Set<String> set1 =ht.keySet()
Linked HashSet
Linked HashSet maintains a list of
the entries in the set, in the order in
which they were inserted. This allows
insertion-order iteration over the set.
The values will be retrieved in same
order of insertion using iterator.
Reflection API