Selenium Tutorial 4


Selenium Tutorial 4

Java programme construction / Java Syntax
> Download Java Software (JDK) as well as Install

> Set Environment (Path) Variable to access Java Run -time Environment from whatever directory inward C drive.

> Download Eclipse software

C:\Program Files\Java\jdk1.8.0_40\bin - Java path

C:\Users\G C Reddy\Desktop\eclipse -Eclipse

How Eclipse communicates alongside Java Run-time Environment

Using Path Environment variable
---------------------------------------------
Java Programming
Java Project
    -> Packages
        -> Classes, Interfaces etc...


> Create Java Project inward Eclipse

> Create a package

> Create a Class
--------------------------------
Sample Java Program
1) Package Declaration statement
Ex:
package abcd;
----------------------
2) Import Statements
We tin flaming import built inward as well as User defined Libraries using import keyword.

Examples for Built inward packages

io, jxl, sql etc...

import java.io.Console;

import java.lang.*;

import is coffee keyword to import Libraries

java - Project

io - package

Console - Class

lang.* - all classes from lang package
-----------------------------
3) Class annunciation statement
Ex:
public degree Sample {

public - Access Modifier

class - coffee keyword to declare a class

Sample - Name of the class
---------------------------------
4) Comments section

// This is a Sample Java Program

5) master copy method tilt - Program execution starts from master copy method
(* It is the mandatory tilt inward every Java program)

public static void master copy (String [] args){

public - Access Modifier

static - purpose master copy method without invoking whatever object

void - returns nothing

main method name

6) Declarations
We tin flaming declare variables as well as constants
---------------------
System.out.println ("Addition of a, b, c is: "+ (a+b+c));

System - Class

out - Object

println - method

"Addition of a, b, c is: " - Message / Details

+ - Concatenation

a, b, c, d -Variables

Conditional statements
Loop statements
Built inward as well as user defined methodsOperators etc....
------------------------------
Writing Normal statements - every tilt should terminate alongside ;

Writing blocks - Statements of the block enclosed {}
----------------------------------------
Java Program Example:
package abcd;

import java.io.Console;
import java.lang.*;
public degree Sample {
    // This is a Sample Java Program
public static void master copy (String [] args){
    int a = 10, b, c; // Declartion of Variables
    b= 20; // Initialization
        System.out.println (a+b);
    a = 50;
    concluding int MONEY = 100; // declaring constant
    // MONEY = 200;
    System.out.println ("Addition of a, b, is: "+ (a+b));

    if (b > a){
        System.out.println ("B is a Big Number");
        }
    else
    {
        System.out.println ("A is a Big Number");
    }
for (c=1; c <= 10; c++){
    System.out.println (c);
}  
}
}
--------------------------------------------
Java Comments
 

Comments are English linguistic communication word, tin flaming hold upward used for code documentation.

Purpose of Comments:


a) To brand the code Readable

b) To brand the code disable from execution

Comments Syntax inward Java:
Use // for Single business comment

Use /*....
......
.....
*/ for multiple lines comment
--------------
Ex:

int a = 10, b, c; // Declaration of Variables

// world static void master copy (String [] args){

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

Usage of Comments inward Test Automation:


a) To write Test headers

b) To write method headers

c) To explicate complex logic

d) To explicate resources usage
Etc...
--------------------------------
Java Data Types
 

What is Data Type?
 

Data type is a classification of the type of information that a variable or object tin flaming concur inward estimator programming.

Ex: character, integer, float etc....

> Java supports explicit annunciation of Data types.
(we postulate to specify the information type earlier declaring the Variable)

Syntax:
data_type variable_name;

data_type variable_name = value;

Example:
int a;

int a = 100;
----------------------
Two types of Data types inward java 

a) Primitive Data types

b) Non-primitive Data types / Reference Data types
-----------------------------------
a) Primitive Data types8 primitive information types

Integer types
1) byte (8 bits)

Ex:

byte a =100;

2) brusk (16 bits)

short a = 10000;

3) int (32 bits)

int a = 100000;

4) long (64 bits)

long a = 100000L
------------------
Rational types (Numbers alongside decimal places)
5) float (32 bits)

float a = 1.2;

6) double (64 bits)
ex:
double a = 19.3456;
---------------------
Characters
7) char (16 bits)

Ex:

char a ='Z'
------------------------
Conditional
8) boolean (undefined, depends on JVM)

Ex:
boolean a = true
---------------------------------
b) Non-primitive / Reference information types

Non-primitive information types inward Java are Objects as well as Arrays.

Note:

Reference types are non passed value, passed past times reference

Ex:

Button a = novel Button("OK")
-----------------------------------------------
Java Variables
 

1) What is Variable?

A named retentivity location to shop or concur the data.

Two types of retentivity inward Computer environment:

i) Primary retentivity -RAM

ii) Secondary retentivity -ROM
Ex: CD, DVD, HDD etc...
-------------------------
2) Declaration of Variables


Java Supports explicit annunciation of variables

Syntax:

dataType VariableName;

Ex:

int a;
---------------
dataType variable1, variable2, variable3;

Ex:

int a, b, c;
------------------------
dataType VariableName = value;

Ex:

int a =100;
--------------------------
3) Assigning values to variables


a) Initialization

int a;
a=10; // Initialization
--------------
int a=10; // Initialization
----------------
b) Reading
    using Input devices
    from files(text/excel)
    from databases
    from Application objects
-------------------------
4) Types of Variables


a) Instance Variable
A variable that is declared within the degree precisely exterior the method

b) Local variable
A variable that is declared within the method

c) Static variables
A Variable that is declared every bit static, It cannot hold upward local.
----------------------
5) Variables Naming Rules


> Java Variables are representative sensitive, monkey is non the every bit Monkey or MONKEY.

char monkey, Monkey, MONKEY

> Java variable mention must commencement alongside a missive of the alphabet or $ or _

Ex:
myvar
MYVAR
$myvar
_myvar
myvar1
myvar_1
----------
1myvar - invalid
----------------------
> Variable names cannot hold upward equal to coffee reserved words

Ex:

int
for
import

> Must hold upward unique inward the ambit of declaration.

--------------------------------------------
Selenium Tutorial v

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