Java Tutorial for Selenium
Overview of Java:
> Java Programming Language was developed yesteryear Sunday Microsystems inwards 1995, similar a shot it is subsidiary of Oracle Corporation.
> Java is an Object oriented Programming language. In Java everything is object.
> Java is platform independent language. It tin sack live compiled in addition to interpreted.
> Java is simple, tardily to larn in addition to use.
> Java is securable, using Java nosotros tin sack railroad train virus costless in addition to tamper costless systems.
-----------------------------
Usage of Java:
> To railroad train Desktop Applications (Ex: Acrobat Reader)
> To railroad train Web Applications
> To railroad train corporation Applications (Ex: Banking, Insurance etc...)
> To railroad train Mobile Applications
> To railroad train Embedded Systems.
> To railroad train Smart cards
> To railroad train Games software
Etc...
* Test Automation (To Enhance Test cases)
------------------------------------------
A) Java Fundamentals
1) Comments
Purpose of Comments:
i) To brand the code readable.
ii) To brand the code disable from execution.
Note: Java supports unmarried trouble comment in addition to multiple trouble comments.
-------------------------------------------------
2) Data Types
There are ii categories of Data Types.
a) Primitive Data Types
b) Reference Data Types.
----------------------------------
3) Java Modifiers
Modifiers are used to laid access levels for Classes, variables, Methods etc...
There are ii categories of Modifiers
i) Access Modifiers (default, public, private, protected)
ii) Non-Access Modifiers (static, final, abstract, synchronized)
------------------------------
4) Variables
There are iii types of variables
i) Local variables
ii) Static / Class variables
iii) Instance variables
---------------------------------
5) Operators inwards Java
Operators are used to perform mathematical, comparing in addition to Logical operations.
Categories of Operators
i) Arithmetic
ii) Relational
iii) Bitwise
iv) Logical
v) Assignment
vi) Mise operators
-----------------------------------
6) Conditional statements
In Selenium Test Automation, nosotros usage coffee conditional statements to insert verification points in addition to for mistake handling.
i) Two types of conditional statements inwards Java
a) if statement
b) switch statement
ii) Types of Conditions
a) Single status (Positive/Negative)
b) Compound condition
c) Nested Condition
iii) Usage of Conditional statements
a) Execute a block of statements when status is True.
b) Execute a block of statements when status is True.
Otherwise execute simply about other block of statements.
c) Decide amid several alternates (else if)
d) Execute a block of statements when to a greater extent than than ane status is True(Nested if)
e) Decide amid several alternates (Using switch statement)
----------------------------------------------------
7) Loop Statements
Used for repetitive execution
Types of Loop statements
a) for loop
b) spell loop
c) practise spell loop
d) Enhanced for loop (mainly used for Arrays)
-------------------------------------------
8) Arrays inwards Java
> Generally, Array is a collection of similar information type of elements.
> In Java, Array is an Object that contains elements of similar information types.
> Java Array is index based, index starts from zero.
> The length of an Array is established when the Array is created in addition to Array length is fixed.
-------------------------------------
9) Java Methods
Methods are likewise known equally procedures or Functions.
A Java method is a collection of statements that are grouped together to perform an operation
Types of Methods
i) Built-in/Pre-defined methods
Number methods
Character methods
String methods
Date & Time methods etc...
ii) User defined methods
Method amongst returning value
Method without returning whatever value.
-----------------------------------------------
10) File in addition to I/O operations inwards Java
java.io parcel contains classes to perform input in addition to output operations inwards Java.
> Reading input using Input devices
> Displaying output on the Console.
> Handling Files
-----------------------------------------
11) Exception treatment inwards Java.
> In Computer programming exception is an abnormal condition.
The exception treatment inwards Java to grip run-time errors in addition to thus that normal time period of the application tin sack live maintained.
-----------------------------------
B) Java Object Oriented Programming
In Object Oriented programming System (OOPS), nosotros pattern programs using objects in addition to classes.
1) Inheritance
> Inheritance is a machinery inwards which ane object acquires all properties in addition to behaviors of nurture object.
> Using Inheritance nosotros tin sack practise classes that are built inwards upon existing classes.
> When nosotros inherit from an existing class, nosotros tin sack reuse methods in addition to fields from nurture class
Java Supports
i) Single Inheritance
ii) Multi score Inheritance
Note: Java doesn't back upward multiple Inheritance.
--------------------------------
2) Polymorphism
It is a concept yesteryear which nosotros tin sack perform an performance inwards dissimilar ways.
Polymorphism derived from ii Greek words
Poly - many
Morphs - forms/ways
Polymorphism way many forms/ways.
Two types of Polymorphism inwards java.
i) Compile fourth dimension Polymorphism
ii) Runtime Polymorphism
we tin sack hit Polymorphism yesteryear Method loading in addition to Method overriding.
------------------------------------------------------------------
3) Abstraction
> Abstraction is physical care for of hiding the implementation details in addition to showing functionality to the user.
Another way, It shows of import things to the User in addition to hides internal details.
In ii ways nosotros tin sack hit Abstraction.
i) Abstract class
ii) Interface.
------------------------------------
4) Encapsulation
Encapsulation is a physical care for of wrapping code in addition to information together into a unmarried unit.
--------------------------------------------
Java Packages
A Java parcel is a grouping of similar type of classes, Interfaces in addition to sub-packages.
There are ii types of Java packages
i) Built inwards packages
Ex: io, util, sql etc...
ii) User defined packages
Java Interface
An Interface is a collection of abstract methods.
An Interface is non a Class, writing an Interface is similar to writing a Class.
--------------------------------------------------------
Java Environment Setup in addition to write outset Java Program
> Download Java (JDK) software in addition to Install.
> Set Environment Variable (Path variable) to access Java shape whatever directory.
How to laid path variable inwards MS Windows 7.
Select MyComputer in addition to correct click
> Properties
> Advanced System Settings
> Environment Variables
> Select System variables.
> Select Path variable
> Enter JDK bin directory path.
>OK > OK > OK
------------------------------------------
Verify the Java Environment setup
Launch ascendancy prompt
> Type coffee (it provides details)
--------------------------------------
Three steps for writing in addition to executing Java programs.
i) Write Java programme inwards Notepad (Editor)
ii) Compile the Program
Command prompt > alter to Program file directory)
> Type javac ProgramName.java (java is programme file extension, javac is Java ascendancy for compilation)
iii) Run / Execute the Program
> Command prompt > Type coffee Program Name
Sample Java Program
package JavaExamples;
public course of report Sample {
populace static void main(String[] args) {
System.out.println("Hello Java");
}
}
--------------------------------------------------------
Download Eclipse software in addition to unzip
Eclipse IDE (Integrated Development Environment)
It is platform to practise in addition to execute Java programs, Perl, Python, Ruby, PHP etc... programs.
It provides Editor, assistance for syntax errors, Auto compilation in addition to debugging.
Open Eclipse principal folder
> Click Eclipse file (It launched eclipse IDE)
---------------------------
Create Java Project
> Create a package
> Create course of report /Interface
Java programme Structure / Java Program Syntax
1) Package proclamation statement
package JavaExamples;
2) Import statements
We tin sack import Built inwards in addition to User defined Libraries using "import" keyword.
Ex:
import java.io.Console;
java - Project
io - package
Console - Class
-----------------
java.io.*;
io.* - all classes from io package.
---------------------------------------
import java.io.Console;
import java.lang.*;
---------------------------------------
3) Class proclamation statement
Ex:
public course of report Sample {
public - Access modifier
class - Java keyword to declare a class
Sample - Name of the class
-----------------------------------
4) Comments sections
// This is a sample Program
-----------------------------
5) principal Method - Program execution starts from principal method
(* It is the mandatory disceptation inwards every coffee program.)
public static void main(String[] args) {
public - Access Modifier
static - Non Access Modifier (use principal method without invoking whatever object)
void - returns nothing
main - Method name
-------------------------------------
6) Declarations
we tin sack declare Variables in addition to constants
Ex:
int a = 10;
int a =10, b =20, c =30;
Or
int a;
a =100;
final int x =100; // Constant declaration
-----------------------------------
System.out.println("Hello Java");
System - Class
out - object
println - Method
"hello Java" -message
----------------------------------
7) Conditional blocks
Loop blocks
Method declarations
etc....
-----------------------------------------
A Sample Java Program:
package JavaExamples;
import java.io.Console;
import java.lang.*;
public course of report Sample {
// This is a Sample Program
populace static void main(String[] args) {
int a = 100, b, c; //Variables Declaration
b = 20;
lastly int Money = 100; // Constant declaration
System.out.println("Addition of a, b is: " + (a+b));
if ( a > b){
System.out.println("A is a Big Number");
}
else {
System.out.println("B is a Big Number");
}
for (c =1; c <=10; c++){
System.out.println(c);
}
}
}
-----------------------------------------------------
Overview of Java:
> Java Programming Language was developed yesteryear Sunday Microsystems inwards 1995, similar a shot it is subsidiary of Oracle Corporation.
> Java is an Object oriented Programming language. In Java everything is object.
> Java is platform independent language. It tin sack live compiled in addition to interpreted.
> Java is simple, tardily to larn in addition to use.
> Java is securable, using Java nosotros tin sack railroad train virus costless in addition to tamper costless systems.
-----------------------------
Usage of Java:
> To railroad train Desktop Applications (Ex: Acrobat Reader)
> To railroad train Web Applications
> To railroad train corporation Applications (Ex: Banking, Insurance etc...)
> To railroad train Mobile Applications
> To railroad train Embedded Systems.
> To railroad train Smart cards
> To railroad train Games software
Etc...
* Test Automation (To Enhance Test cases)
------------------------------------------
A) Java Fundamentals
1) Comments
Purpose of Comments:
i) To brand the code readable.
ii) To brand the code disable from execution.
Note: Java supports unmarried trouble comment in addition to multiple trouble comments.
-------------------------------------------------
2) Data Types
There are ii categories of Data Types.
a) Primitive Data Types
b) Reference Data Types.
----------------------------------
3) Java Modifiers
Modifiers are used to laid access levels for Classes, variables, Methods etc...
There are ii categories of Modifiers
i) Access Modifiers (default, public, private, protected)
ii) Non-Access Modifiers (static, final, abstract, synchronized)
------------------------------
4) Variables
There are iii types of variables
i) Local variables
ii) Static / Class variables
iii) Instance variables
---------------------------------
5) Operators inwards Java
Operators are used to perform mathematical, comparing in addition to Logical operations.
Categories of Operators
i) Arithmetic
ii) Relational
iii) Bitwise
iv) Logical
v) Assignment
vi) Mise operators
-----------------------------------
6) Conditional statements
In Selenium Test Automation, nosotros usage coffee conditional statements to insert verification points in addition to for mistake handling.
i) Two types of conditional statements inwards Java
a) if statement
b) switch statement
ii) Types of Conditions
a) Single status (Positive/Negative)
b) Compound condition
c) Nested Condition
iii) Usage of Conditional statements
a) Execute a block of statements when status is True.
b) Execute a block of statements when status is True.
Otherwise execute simply about other block of statements.
c) Decide amid several alternates (else if)
d) Execute a block of statements when to a greater extent than than ane status is True(Nested if)
e) Decide amid several alternates (Using switch statement)
----------------------------------------------------
7) Loop Statements
Used for repetitive execution
Types of Loop statements
a) for loop
b) spell loop
c) practise spell loop
d) Enhanced for loop (mainly used for Arrays)
-------------------------------------------
8) Arrays inwards Java
> Generally, Array is a collection of similar information type of elements.
> In Java, Array is an Object that contains elements of similar information types.
> Java Array is index based, index starts from zero.
> The length of an Array is established when the Array is created in addition to Array length is fixed.
-------------------------------------
9) Java Methods
Methods are likewise known equally procedures or Functions.
A Java method is a collection of statements that are grouped together to perform an operation
Types of Methods
i) Built-in/Pre-defined methods
Number methods
Character methods
String methods
Date & Time methods etc...
ii) User defined methods
Method amongst returning value
Method without returning whatever value.
-----------------------------------------------
10) File in addition to I/O operations inwards Java
java.io parcel contains classes to perform input in addition to output operations inwards Java.
> Reading input using Input devices
> Displaying output on the Console.
> Handling Files
-----------------------------------------
11) Exception treatment inwards Java.
> In Computer programming exception is an abnormal condition.
The exception treatment inwards Java to grip run-time errors in addition to thus that normal time period of the application tin sack live maintained.
-----------------------------------
B) Java Object Oriented Programming
In Object Oriented programming System (OOPS), nosotros pattern programs using objects in addition to classes.
1) Inheritance
> Inheritance is a machinery inwards which ane object acquires all properties in addition to behaviors of nurture object.
> Using Inheritance nosotros tin sack practise classes that are built inwards upon existing classes.
> When nosotros inherit from an existing class, nosotros tin sack reuse methods in addition to fields from nurture class
Java Supports
i) Single Inheritance
ii) Multi score Inheritance
Note: Java doesn't back upward multiple Inheritance.
--------------------------------
2) Polymorphism
It is a concept yesteryear which nosotros tin sack perform an performance inwards dissimilar ways.
Polymorphism derived from ii Greek words
Poly - many
Morphs - forms/ways
Polymorphism way many forms/ways.
Two types of Polymorphism inwards java.
i) Compile fourth dimension Polymorphism
ii) Runtime Polymorphism
we tin sack hit Polymorphism yesteryear Method loading in addition to Method overriding.
------------------------------------------------------------------
3) Abstraction
> Abstraction is physical care for of hiding the implementation details in addition to showing functionality to the user.
Another way, It shows of import things to the User in addition to hides internal details.
In ii ways nosotros tin sack hit Abstraction.
i) Abstract class
ii) Interface.
------------------------------------
4) Encapsulation
Encapsulation is a physical care for of wrapping code in addition to information together into a unmarried unit.
--------------------------------------------
Java Packages
A Java parcel is a grouping of similar type of classes, Interfaces in addition to sub-packages.
There are ii types of Java packages
i) Built inwards packages
Ex: io, util, sql etc...
ii) User defined packages
Java Interface
An Interface is a collection of abstract methods.
An Interface is non a Class, writing an Interface is similar to writing a Class.
--------------------------------------------------------
Java Environment Setup in addition to write outset Java Program
> Download Java (JDK) software in addition to Install.
> Set Environment Variable (Path variable) to access Java shape whatever directory.
How to laid path variable inwards MS Windows 7.
Select MyComputer in addition to correct click
> Properties
> Advanced System Settings
> Environment Variables
> Select System variables.
> Select Path variable
> Enter JDK bin directory path.
>OK > OK > OK
------------------------------------------
Verify the Java Environment setup
Launch ascendancy prompt
> Type coffee (it provides details)
--------------------------------------
Three steps for writing in addition to executing Java programs.
i) Write Java programme inwards Notepad (Editor)
ii) Compile the Program
Command prompt > alter to Program file directory)
> Type javac ProgramName.java (java is programme file extension, javac is Java ascendancy for compilation)
iii) Run / Execute the Program
> Command prompt > Type coffee Program Name
Sample Java Program
package JavaExamples;
public course of report Sample {
populace static void main(String[] args) {
System.out.println("Hello Java");
}
}
--------------------------------------------------------
Download Eclipse software in addition to unzip
Eclipse IDE (Integrated Development Environment)
It is platform to practise in addition to execute Java programs, Perl, Python, Ruby, PHP etc... programs.
It provides Editor, assistance for syntax errors, Auto compilation in addition to debugging.
Open Eclipse principal folder
> Click Eclipse file (It launched eclipse IDE)
---------------------------
Create Java Project
> Create a package
> Create course of report /Interface
Java programme Structure / Java Program Syntax
1) Package proclamation statement
package JavaExamples;
2) Import statements
We tin sack import Built inwards in addition to User defined Libraries using "import" keyword.
Ex:
import java.io.Console;
java - Project
io - package
Console - Class
-----------------
java.io.*;
io.* - all classes from io package.
---------------------------------------
import java.io.Console;
import java.lang.*;
---------------------------------------
3) Class proclamation statement
Ex:
public course of report Sample {
public - Access modifier
class - Java keyword to declare a class
Sample - Name of the class
-----------------------------------
4) Comments sections
// This is a sample Program
-----------------------------
5) principal Method - Program execution starts from principal method
(* It is the mandatory disceptation inwards every coffee program.)
public static void main(String[] args) {
public - Access Modifier
static - Non Access Modifier (use principal method without invoking whatever object)
void - returns nothing
main - Method name
-------------------------------------
6) Declarations
we tin sack declare Variables in addition to constants
Ex:
int a = 10;
int a =10, b =20, c =30;
Or
int a;
a =100;
final int x =100; // Constant declaration
-----------------------------------
System.out.println("Hello Java");
System - Class
out - object
println - Method
"hello Java" -message
----------------------------------
7) Conditional blocks
Loop blocks
Method declarations
etc....
-----------------------------------------
A Sample Java Program:
package JavaExamples;
import java.io.Console;
import java.lang.*;
public course of report Sample {
// This is a Sample Program
populace static void main(String[] args) {
int a = 100, b, c; //Variables Declaration
b = 20;
lastly int Money = 100; // Constant declaration
System.out.println("Addition of a, b is: " + (a+b));
if ( a > b){
System.out.println("A is a Big Number");
}
else {
System.out.println("B is a Big Number");
}
for (c =1; c <=10; c++){
System.out.println(c);
}
}
}
-----------------------------------------------------