Java Quick Tutorial for Selenium

Java Quick Tutorial for Selenium

Java Environment Setup & Verify

A) Java Fundamentals
i) Comments inward Java
ii) Java Data Types
iii) Java Modifiers
iv) Variables
v) Operators
vi) Conditional Statements
vii) Loop Statements
viii) String Handling inward Java
ix) Arrays inward Java
x) Java IO Operations too File Handling
xi) Java Built-in Methods 
xii) Java User defined Methods
xiii) Java Exception Handling

B) Java OOPS (Object Oriented Programming System)
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
----------------------------------------------------------------
Java Environment Setup & Verify

Steps:
> Download Eclipse IDE too extract
> Download Java too Install
-------------------------
> Launch Eclipse IDE
> Create Java Project
> Create Java Package
> Create Java Class 
Write Java Program too Execute
---------------------------------------
i) Comments inward Java

Purpose of Comments inward Computer Programming

> To brand the Code Readable
> To brand the Code disable from Execution.

Java supports Single trouble comment too multiple trouble comments.
----------------------------------
Single trouble Comment- // earlier the Statement

Multiple lines comment/comment a block of statements
/* Statements
---------------
------------------
------------*/ 
----------------------------------
Example:
public static void main(String[] args) {
//It is a Sample Java Program
int a=10, b =20;
System.out.println(a+b);

/*if ( a > b){
System.out.println("A is a Big Number");
}
else {
System.out.println("B is a Big Number");
}*/

}
}
---------------------------------------
ii) Data Types inward Java

A Data Type is a classification of the type of information that a variable or object tin give the sack concord inward figurer programming.

Example for General Data Types:

Character,

Integer,

String

Float

Boolean etc...

Java supports ii categories of Data types.

a) Primitive Data Types

b) Reference Data Types.

Example:

int a=10;
char b ='A';
double c = 123.234;
boolean d = true;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
---------------------------------------
iii) Java Modifiers

Modifiers are used to ready access levels for Classes, Variables too Methods etc...

Two types of Modifiers inward Java

1) Access Modifiers (default, public, somebody too protected)

2) Non Access Modifiers (static, final, abstract, synchronized etc...)

Example:
public shape Class1 {
public int a =10, b =20;
public void add(){
int consequence = a +b;
System.out.println(result);
}
public static void main(String[] args) {
Class1 obj = novel Class1();
obj.add();
}
}
---------------------------------------
iv) Variables inward Java

A named retention place to shop temporary information inside a program.

Three types of variables inward Java

1) Local Variables

2) Instance Variables

3) Class / Static Variables

Example:

public shape Class1 {
public static int a =100, b =20;

public static void main(String[] args) {
int c = 30;
System.out.println(a);
System.out.println(c);

if (a > b){
int d=40;
System.out.println(a + b + d);
System.out.println(d);
}
//System.out.println(d);
System.out.println(b);
}
}
---------------------------------------
v) Operators inward Java

Operators are used to perform Mathematical, Comparison too Logical Operations.

Categories of Operators inward Java

1) Arithmetic Operators

2) Relational Operators

3) Assignment Operators

4) Logical Operators
Etc...
----------------------------------------------------
1) Arithmetic Operators

a) Addition + (Addition, String Concatenation)

b) Subtraction - (Subtraction, Negation)

c) Multiplication *

d) Division /

e) Modules % 

f) Increment ++

g) Decrement --
------------------------------------------
2) Relational Operators

a) == 

b) !=

c) >

d) >=

e) <

f) <=
--------------------------------------------
3) Assignment Operators

a) Assignment  =

b) Add too Assign +=

c) Subtract too Assign -=

d) Multiply too Assign *=
--------------------------------------------
4) Logical Operators

a) Logical Not operator !

b) Logical And Operator &&

c) Logical Or operator ||
---------------------------------------------
Example:

public shape Class1 {
public static void main(String[] args) {
int a=10, b=20, c =30;

System.out.println(a+b);
System.out.println(a*b);
System.out.println(a-b);

System.out.println(a > b);
System.out.println(a < b);

System.out.println(a+10);

if ((c > a) && (c > b)){
System.out.println("C is a Big Number");
}
else {
System.out.println("C is Not a Big Number");
}

}
}
---------------------------------------
vi) Java Conditional Statements

1) Two types of statements

a) if statement

b) switch statement
-----------------------
2) Three types of Conditions

a) Single Condition (Positive/Negative)

b) Compound Condition (Positive/Negative)

c) Nested Condition (Positive/Negative)
---------------------------------------
3) Usage of Conditional Statements

a) Execute a block of statements when a status is true.

b) Execute a block of statements when a status is true, otherwise execute unopen to other block of statements.

c) Execute a block of statements when a Compound status is true, otherwise execute unopen to other block of statements.

d) Decide with several alternates (Else if)

e) Execute a block of statements when to a greater extent than than ane status is truthful (Nested if).

f) Decide with several alternates using Switch statement
----------------------------------------------------
Example:

int a=100, b=20;

if (a > b){
System.out.println("A is a Big Number");
}

if (a > b){
System.out.println("A is a Big Number");
}
else {
System.out.println("B is a Big Number");
}

if (!(b > a)){
System.out.println("A is a Big Number");
}
else
{
System.out.println("B is a Big Number");
}
---------------------------------------
vii) Loop Statements

Used for Repetitive execution.

Four types of loop structures inward Java

1) for loop

2) piece loop

3) create piece loop

4) Enhanced for loop(Arrays)
-----------------------------------------
Examples:

//Print 1 to 10 Numbers
for (int i=1; i<=10; i++){
System.out.println(i);
}
--------------------
//Print 1 to 10 Numbers
int i=1;
while (i<=10){
System.out.println(i);
i++;
}
----------------------------
//Print 1 to five Numbers Except 4
for (int i = 1; i <=5; i++){
if (i != 4){
System.out.println(i);
}
}
---------------------------------------
viii) String treatment inward Java

> Sequence of characters written ""

> String may incorporate Alfa bytes or Alfa-numeric or Alfa-numeric too Special characters or exclusively numeric.


"ABCD"
"India123"
"India123$#@"
"123"
---------------------------------
Example:
System.out.println("India");
System.out.println("India123");
System.out.println("123");
System.out.println("$%^");
System.out.println("India123%^&*");
----------------------------------
Creating Strings

String myTool = "UFT";//String Variable
String [] myTools ={"UFT", "RFT", "Selenium"};//Array of Strings
System.out.println(myTool);//UFT
--------------------------------------
Example 3:

String str1 ="Selenium";
String str2 = " UFT";
System.out.println(str1 + str2);//Selenium UFT
System.out.println(str1.concat(str2));//Selenium UFT
System.out.println("Selenium"+1+1);//Selenium11
System.out.println(1+1+"Selenium");//2Selenium
---------------------------------------
ix) Arrays inward Java

> Generally, Array is a collection of like type of elements.

> In Java, Array is an Object that contains elements of like information type.

> Each exceptional inward an Array is called an Element.
----------------------------
Example:

int a [];
a= novel int[3];
a[0]=10;
a[1]=20;
a[2]=30;
System.out.println(a[1] + a[2]);
--------------------------------------
int a [] = novel int [3];
a[0]=10;
a[1]=20;
a[2]=3;
System.out.println(a[0] - a[2]);
--------------------------------------
int a [] = {10, 20, 30, 40};
System.out.println(a[1] + a[3]);
--------------------------------------------
//Different Types of Arrays

char [] a = {'A', 'B', 'C', 'd'};//Array of Characters
int [] b ={10, 20, 30, 40}; //Array of Integers
String [] c = {"UFT", "RFT", "Selenium"};//Array of Strings
boolean [] d ={true, false, false, true}; //Array of Boolean values.
double [] e ={1.234, 2.345, 5.6}; // Array of decimal betoken values
---------------------------------------
x) Java IO Operations

Reading Data (Read Input, Read information from files)
-----------------------------
Using java.util.Scanner is the easier means too it includes many methods to banking concern gibe input is valid to read.

Examples:

1) Read Input:

Scanner scan = novel Scanner(System.in); //System.in is an Input stream
System.out.println("Enter Your Name");
String cite = scan.nextLine();
System.out.println("Your Name is "+ name);

System.out.println("Enter Your Number");
int num = scan.nextInt();
System.out.println("Your Number is "+ num);
---------------------------
2) Display Output on the Console

public static void main(String[] args) {
int a =10, b=20;
System.out.println(a);//10
System.out.println("welcome to Selenium");//welcome to Selenium
System.out.println("Addition of a, b is "+ (a+b));//Addition of a, b is 30
System.out.println("value of a is "+ a + " Value of b is "+b);//Value of a is 10 value of b is 20"
}
---------------------------------------------------------------------
Java Quick Tutorial for Selenium Part 2

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post