Java User Defined Methods

Selenium Class 18 - Java User Defined Methods

Java Methods
Predefined Methods
String Methods
Array Methods
Number Methods
Character Methods etc...

User defined Methods
Methods with return value (Perform Operations, and return values)
Call Methods by invoking Object (Non Static Methods)
Call Methods without invoking Object (Static Methods)

Methods returns nothing (Performing Operations only)
Call Methods by invoking Object (Non Static Methods)
Call Methods without invoking Object (Static Methods)
----------------------------------------------
User defined Methods - Examples

1) Write methods (with return value)
a) Call the methods by invoking object (Non-static methods)

Syntax:

acessModifier returnType methodName (Parameters...){
Statements
---------------
-------------
------------
return Statement...
}

Note: methods take Parameters but Parameters are optional, if we don't want use Parameters then write ()...
And use Data Type for these type methods,
Ex:
(String Username, String Password)
(int val1, int val2, int val3)
----------------------------------------------
Call methods

Create Object...
ClassName objectName = new Classname();

Call methods...
dataType variableName = objectname.method(values for Parameters...);
Or
system.out.println(objectname.method(values for Parameters...);
----------------------------------------------
Example:
public class JavaMethods {
// Create a Non-static method with Parameters....
public int add1(int num1, int num2){
int result = num1 + num2;
return result;
}
//Create a Non static method without Parameters....
public int add2(){
int num1 =10, num2 =20;
int res = num1 + num2;
return res;
}
public static void main(String[] args) {
//Create Object 
JavaMethods obj = new JavaMethods();

//Call Methods
int x = obj.add1(11, 22);
int y = obj.add2();

System.out.println(x);//33
System.out.println(y);//30

//OR
System.out.println(obj.add1(14, 25));//39
System.out.println(obj.add2());//30
}
}
----------------------------------------------
1) Writing Methods (Methods with return value)
b) Call methods without invoking Object (Static Method)

Syntax:

accessModifier nonAcessModifier / static retun Type methodName (parameters...){
Statements
-------------
-------------
--------------
return statement;
}
----------------------------------------------
Call Static Methods
dataType variableName = ClassName.method(values for Parameters...);

Note: we can call this type of methods without ClassName also / directly.
----------------------------------------------
Example:

public class JavaMethods {
//Create a Static Method with Return value and Parameters....
public static int multiply1(int a, int b){
int result = a * b;
return result;
}
//Create a Static Method with Return value and No Parameters....
public static int multiply2(){
int a =10, b =20;
int result = a*b;
return result;
}
public static void main(String[] args) {
int res1 = JavaMethods.multiply1(7, 9);
int res2 = JavaMethods.multiply2();

System.out.println(res1);
System.out.println(res2);
//Or
System.out.println(JavaMethods.multiply1(1, 2));
System.out.println(JavaMethods.multiply2());
}
}
----------------------------------------------
Call Methods within the Methods....

i) Call Static method within Static Method
public static int sub2(){
int a=10, b =7;
int val =sub1(); 
int result = (a-b) + val;
return result;
}
----------------------------------------------
ii) Call Static within Non Static Method

public int add2(){
int c=100;
Sample obj = new Sample();
int d = sub2();
int res = (obj.add()) + c +d;
return res;
}
----------------------------------------------
iii) Call Non static method within Non Static Method

public int add2(){
int c=100;
Sample obj = new Sample();
int d = sub2();
int res = (obj.add()) + c +d;
return res;
}
----------------------------------------------
iv) Call Non Static Method within Static method

public static int sub1(){
int a=100, b =30;
Sample obj = new Sample();
int val =obj.add(); 
int result = (a-b) - val;
return result;
}
----------------------------------------------
Executing Methods...

Sample obj2 = new Sample();
int x = obj2.add();
int y = obj2.add2();
System.out.println(x);//30
System.out.println(y);//173

System.out.println(sub1());//40
System.out.println(sub2());//43
----------------------------------------------
2) Writing Methods (Methods return Nothing)
a) Call Methods by invoking object (Non static method)

Syntax:

accessModifier returnsNothing methodName(Parameters....){
Statements
-------------
----------
--------
}

Example:

public class Sample2 {
//Create a Non Static Method and returns Nothing
public void comparison(){
int a=10, b=20;

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

public static void main(String[] args) {
//Create Object
Sample2 abc = new Sample2();
abc.comparison();
}
}
----------------------------------------------
2) Writing Methods (Methods return Nothing)
b) Call Methods without invoking object (Static method)

Syntax:

accessModifier static returnsNothing methodName(Parameters){
Statements
-----------
------------
-------------
}

Example:
public class Sample2 {
//Create a Static Method and returns Nothing
public static void comparison(){
int a=100, b=20;

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

public static void main(String[] args) {
Sample2.comparison();
comparison();
}
}
----------------------------------------------
Usage of user defined methods
i) Internal use (Create and Call Methods within the same class/program)
ii) External use (Call Methods from another class/program)
----------------------------------------------
Class 1:
public class Class1 {
public int add(int a, int b){
int result = a+b;
return result;
}
public static void main(String[] args) {
Class1 obj1 = new Class1();
int res= obj1.add(10, 20);
System.out.println(res);
}
}
----------------------------------------------
Class 2:
public class Class2 extends Class1 {

public static void main(String[] args) {
Class2 obj2 = new Class2();
int x= obj2.add(12, 23);
System.out.println(x);
}
}
----------------------------------------------
public class Class2 extends Class1 {
public int sub(){
int a=100, b=45;
int result = a-b;
return result;
}
public static void main(String[] args) {
Class2 obj2 = new Class2();
int x= obj2.add(12, 23);
System.out.println(x);//35

int y = obj2.sub();
System.out.println(y);//55
}
}
----------------------------------------------
public class Class1 {
public static int add(int a, int b){
int result = a+b;
return result;
}
public static void main(String[] args) {
int x= add(10, 30);
System.out.println(x);//40
}
}
----------------------------------------------
public class Class2 {

public static void main(String[] args) {
int y = Class1.add(1, 2);
System.out.println(y);
}
}
----------------------------------------------
public class Class2 extends Class1 {

public static void main(String[] args) {
int y = Class2.add(1, 2);
System.out.println(y);
}
}
----------------------------------------------

Software Testing Jobs in India

Software Testing Jobs in Indai
Software Testing Jobs in India
1)Performance Testing Professionals

Location :Chennai

Company Name :STG Infotech (India)

Experience :2 - 6 Years

Job Description :
Candidates should possess good knowledge in Performace testing tools
Should have good communication.
Willing to work in UK time Zones

Contact :044-22540600

For More Details :

-------------------------------------------------------------------------
2)Qa/mobile Analyst

Location :Mumbai

Company Name :Aditya Birla Customer Services Ltd

Experience :2 - 4 Years

Job Description :
Should have at least 4-5 years of hands-on experience in manual testing.
Hands on expertise on open-sourced automated testing tools viz. Selenium, JMeter, etc. is a must!
Should have experience writing test design documents, standard & borderline test cases.
Should have experience in documenting and executing System Testing Specifications.
Should have experience in documenting and executing User Acceptance Testing Specifications.
Should be able to put together checklists and other QA related templates.
Should have knowledge of QA processes, methodologies and best practices.

For More Details : 

----------------------------------------------------------------------
3)Testing Engineer - Automation

Location :Ernakulam / Kochi/ Cochin

Company Name :GadgEon

Experience :2 - 7 Years

Job Description :
Familiarity with process and better understanding in SDLC, STLC, Agile-Scrum.
Experience with ASP.Net MVC
Experience with version control systems like GIT
Experience with Test Management systems like TestRail, Testopia
Understanding on Test Automation Framework(Selenium)
Good Analytical Skills

Address :
VI 405/E1 , Fathima Tower ,, Malepally Road,
Thrikkakkara .P.O. , Kakkanad,
ERNAKULAM,Kerala,India

Contact :91-484-2903000

For More Details : 

-----------------------------------------------
4)Senior QA Engineer - Manual Testing

Location :Bangalore/Bangalore

Company Name :Epicor

Experience :5 - 9 Years

Job Description :
As a Senior QA Engineer-Manual Testing will join a Product Engineering team ofbright,
talented developers and designers working hard to create phenomenaluser experiences for our customers.
Youwill be very familiar with agile development processes.

For More Details : 

-----------------------------
5)Rational Functional Tester 
Location : Bangalore/Bangalore

Company Name :IDEXCEL TECHNOLOGIES PVT LTD.

Experience : 3 - 7 Years

Job Description :
Good in designing manual test and execute them
Good Analytical and problem solving skill
Travel/Transportation domain experience is a plus.
Experience in automation testing with RFT

Address :
Crystal Plaza, Opp Forum Mall, Hosur Road,
Koramangala, Bangalore-560029.

Contact :91 80 2550 8830 Ext: 154 | Mobile: 7406164447 |

For More Details : 

---------------------------
6)Test Engineer

Location :Noida

Walk-in on 25th Feb'17 (Saturday)

Company Name :Acidaes Solutions Pvt Ltd

Experience :1 - 5 Years

Job Description :
Should have been in the Automation Tester role for last 1 years or more.
Should be an expert in working & creating scripts using
Telrik Automation (preferred), QTP or any other functional testing tool.
Strong development experience is a must. ]
Should have development experience using C# (C Sharp), Java, VBscript, JavaScript.

Address :
Location: Unitech Infospace, Ground Floor,
Tower 1, Block B, Plot No. 2 Sector 62,
NOIDA,Uttar Pradesh,India

Contact :91-120-6784313

For More Details : 

-----------------------------
7)Senior Quality Analyst

Location : Pune, Thailand

Company Name :Scan-IT (Thailand) Ltd

Experience :8 - 13 yrs

Job Description :
Manual testing experience in multi-tier web applications across open source technologies
In depth knowledge of different types of testing execution
A solid grasping and understanding power so to enable self for creation of test cases
Exposure in automated testing using Selenium is added advan

Address :
Marvel Edge, 5th Floor, D5020/D5030, SY no. 207,
Hissa#1A, Lohegaon, India, Viman Nagar,
Pune,MaharashtraPUNE,
Maharashtra,India 411014

Contact :91-20-9822931409

For More Details : 

---------------------------
8) QA Engineer

Location :1 - 2 yrs

Company Name :ZAPBUILD TECHNOLOGIES PVT LTD

Experience :Mohali

Job Description :
Software experience in IT Industry involving Testing and Quality Assurance.
Extensive experience in Manual Testing.
In-depth experience in preparing Test Cases.

Address :
E-237, First Floor,Industrial Area
Phase- 8 BMOHALI,Punjab,India 160061

Contact :91-172-8699060663

For More Details : 

---------------------------------------------
9)Protractor with JavaScript
Location :Noida

Company Name :Xavient Software Solutions India Pvt Ltd

Experience :2 - 6 yrs

Job Description :
Strong experience in - Protractor tools to handle javascript based projects.
Working experience of Page Object Model or Testng or any other related frameworks
Well versed with Software Development Life Cycle (SDLC), Software Testing Life Cycle (STLC).
Solid problem solving skills and ability to focus both strategically to business goals.

Address :
#54, NSEZ, Phase-IIPhase 2NOIDA,
Uttar Pradesh,India 201008

For More Details :

---------------------------
10)Software Tester

Location : Kochi

Company Name :NOA Infotech

Experience :2 - 5 yrs

Job Description :
Experience in Manual Testing
Strong Understanding of SDLC and role of a QA Analyst.
Strong Understanding of software testing techniques and tools.
Should have experience in creating Test Plans, Test scripts, Test cases.

Address :
2nd Floor, Jomer Arcade,Chittoor Road,
ERNAKULAM,Kerala,India 682019

For More Details :

11)QA Automation Engineers

Location : Bangalore

Company Name :Nalashaa Solutions India Pvt Ltd

Experience :5 - 9 yrs

Job Description :
 Exposure to Agile Methodology
Mandatory to have hands on experience on automating tests using Selenium Web driver automation using C# technology.
Must have experience on NUnit Framework, Selenium Web driver, Selenium Grid, Easy automated reporting structure.
Building robust regression Test suite for different test environments.

For More Details : 

---------------------------------------------------------------
12)Automation Test

Location :Bangalore

Company Name :GENISYS INFORMATION SYSTEMS INDIA PRIVATE LIMITED

Experience :6 - 10 yrs

Job Description :
Has experience at least in one of the automation testing tool such as
QTP or Open source like (selenium). Experienced in load testing like load runner or web load.
Experienced in testing techniques, test case design.

For More Details : 

-----------------------------------------------------------------------

Java Control Flow Statements

Core Java Tutorial
Java Control Flow Statements

Java Control Flow Statements can be divided in to three categories,
i) Decision Making Statements
ii) Loop Statements
iii) Branching Statements
-------------------------------------------------
i) Decision Making Statements

a) Two types of Statements

1) if statement
2) switch statement

b) Three Types of Conditions

1) Single Condition (Positive, Negative)

ex:
if (a>b) {
.
.
}
-----------------
Negative Condition
if (b<a) {
.
.
}
--------------
if (!(b>a)) {
.
.
}
----------------------------------
2) Compound Condition (Positive, Negative)

Ex:
if ((a>b) && (a>c)){
.
.
}
------------
if ((a>b) || (a>c)){
.
.
}
------------
if ((a>b) && (a>c) && (a>d)){
.
.
}
--------------------------------
if ((a>b) && (a>c) || (a>d)){
.
.
}
--------------------------------------
3) Nested Condition

if(a>b){
 if(a>c){
  if(a>d){
.
.
}
}
}
--------------------------
c) Usage of Conditional Statements / Decision Making Statements

1) Execute a block of Statements when condition is true.

Syntax:

if (condition) {
Statements
---------
--------
}

Example:

int a =10, b=50;

if (a>b){
System.out.println("A is a Big Number");
}
-----------------------------
int a =10, b=5;

if (b<a){
System.out.println("A is a Big Number");
}
--------------------------------
int a =10, b=5;

if (!(b>a)){
System.out.println("A is a Big Number");
}
------------------------------------
2) Execute a block of Statements when a compound condition is true

Syntax:
if ((condition1/Operand1/expression) && Or || (Condition2)) {
Statements
.
.
}
-------------------------------------
int a =10, b=7, c=4;

if ((a>b) && (a>c)){
System.out.println("A is a Big Number");
}
---------------------
int a =10, b=7, c=40;

if ((a>b) || (a>c)){
System.out.println("A is a Big Number");
}
----------------------------------------
3) Execute a block of Statements when condition is true otherwise execute another block of Statements

if (condition) {
Statements
---------
----------
}
else
{
Statements
-------------
------------
}
------------------------------------
Example:

int a =10, b=10;

if (a>b) {
System.out.println("A is a Big Number");
}
else{
System.out.println("B is a Big Number");
}
------------------------------------
4) Decide among several alternates(else if)

Syntax:

if (condition) {
Statements
-------------
------------
----------
}
else if (condition) {
Statements
----------
----------
----------
}
else if (condition) {
Statements
----------
----------
----------
}
else 
{
Statements
----------
-----------
}
---------------------------------
Initialize an Integer Variable and verify the range

If the number is in between 1 and 100 then display "Number is a Small Number"
If the number is in between 101 and 1000 then display "Number is a Medium Number"
If the number is in between 1001 and 10000 then display "Number is a Big Number"
If the number is more than 10000 then display "Number is a High Number"
Otherwise display "Number is a either Zero or Negative Number"
-----------------------------------------
Java Program:

int a = -100;

if ((a>0) && (a<=100)){
System.out.println("A is a Small Number");
}
else if ((a>100) && (a<=1000)){
System.out.println("A is a Medium Number"); 
}
else if ((a>1000) && (a<=10000)){
System.out.println("A is a Big Number"); 
}
else if (a>10000){
System.out.println("A is a High Number"); 
}
else 
{
System.out.println("Number is either Zero or Negative Number"); 
}
}
}
-----------------------------
5) Execute a block of Statements when more than one condition is true (nested if)

syntax:
if (condition){
 if (condition){
  if (condition){
  Statements
  --------------
  --------------
  }
  }
  }
-------------------------------------------
Example:
Initialize a, b, c, and d variables (Integer variables), check if the a variable is bigger than other three variables or not?

int a=100, b=90, c=80, d=700;

if (a>b){
 if (a>c){
  if (a>d){
  System.out.println("A is a Big Number"); 
  }
 }
}
----------------------------------------
int a=100, b=900, c=800, d=700;

if (a>b){
 if (a>c){
  if (a>d){
  System.out.println("A is a Big Number"); 
  }
  else {
  System.out.println("A is Not a Big Number-3rd condition is False");
  }
 }
 else{
 System.out.println("A is Not a Big Number-2nd condition is False");
 }
}
else
{
System.out.println("A is Not a Big Number -1st condition is False"); 
}
}
}
-----------------------------------------------
Using Compound Condition

int a=100, b=90, c=80, d=70;

if ((a>b) && (a>c) && (a>d)){
System.out.println("A is a Big Number"); 
}
else
{
System.out.println("A is Not a Big Number");
}
------------------------------------------------------
Nested if Condition vs. Compound Condition

In Nested if condition we can write multiple else parts, where as in Compound Condition we can write single else part only.
-----------------------------------------------------
Problem: Find the biggest variable (Integer variables) among 4 variables

Use Compound Condition and else if...

int a=100, b=90, c=80, d=700;

if ((a>b) && (a>c) && (a>d)){
System.out.println("A is a Big Number");
}
else if ((b>a) && (b>c) && (b>d)){
System.out.println("B is a Big Number");
}
else if ((c>a) && (c>b) && (c>d)){
System.out.println("C is a Big Number");
}
else {
System.out.println("D is a Big Number");
}
}
}
-------------------------------------
6) Decide among several alternates (using switch statement)

Syntax:

switch (expression) {

case value:
Statements
-------------
--------------
break;
case value:
Statements
-------------
--------------
break;
case value:
Statements
-------------
--------------
break;

default:
Statements
-----------
-----------
}

Example:

char grade = 'Z';

switch (grade){

case 'A':
System.out.println("Excellent");
break;

case 'B':
System.out.println("Good");
break;

case 'C':
System.out.println("Better");
break;

default:
System.out.println("Invalid Grade");
}

}
}
-------------------------------------------------
ii) Looping Statements

1) for loop
2) while loop
3) do while loop
4) Enhanced for loop

1) for loop

Description: It repeats a block of statements for a specified number of times,

Syntax:

for (Stratvalue; EndValue; Increment / Decrement){
Statements
-------------
-----------
}
--------------------------------------
Print 1 to 10 Numbers
Example:
for (int i=1; i<=10; i++){
System.out.println(i);
}
------------------------------
Print 1 to 5 Numbers except 4th Number

for (int i=1; i<=5; i++){

if (i != 4){
System.out.println(i);
}

}
----------------------------------------------
Print 1 to 10 Numbers in reverse Order

for (int i=10; i>=1; i--){
System.out.println(i);
}
---------------------------------
2) while loop

Description: It repeats a block of Statements while condition is true

Syntax:
initialization
while (condition){
Statements
--------------
--------------
Increment/Decrement
}
---------------------------------
Examples:

1) Print 1 to 10 Numbers
2) Print 10 to 1 Numbers
3) Print 1 to 5 Numbers except 3rd number
------------------------------------------------
int i=1;

while (i<=10){
System.out.println(i);
i++;
}
------------------------------------
int i=10;

while (i>=1){
System.out.println(i);
i--;
}
-------------------------------------------
int i=1;
while (i<=5){
if (i != 3){
System.out.println(i);
}
i++;
}
-----------------------------------------
3) do while loop

It repeats a block of statements while condition is true
It executes statements at least once irrespective of the condition

Syntax:

Initialization
do
{
Statements
-----------
----------
Increment/Decrement
} while (condition);
------------------------------------
Print 1 to 10 Numbers
Print 10 to 1 Numbers
Print 1 to 5 Numbers except 4th number,
----------------------------------------
int i=1;
do
{
System.out.println(i);
i++;
} while (i<=10);
-------------------------------------------
int i=10;
do
{
System.out.println(i);
i--;
} while (i>=1);
--------------------------------------
int i=10;
do
{
System.out.println(i);
i--;
} while (i>=1);
---------------------------------------
int i=1;
do
{
if (i != 4){
System.out.println(i);
}
i++;
} while (i<=5);
---------------------------------------------------------
4) Enhanced for loop

Syntax:

It executes all elements in an Array

Array Declaration;
for (declaration: Expression/Array){
Statements
--------------
--------------
-------------
}

Example:
String [] languages = {"C", "COBOL", "Java", "VBScript"};

for (String lang: languages){
System.out.println(lang);
}
---------------------------------------------
int a=10, b=20;
int [] mathOperations = new int[3];
mathOperations[0]=a+b;
mathOperations[1]=a-b;
mathOperations[2]=a*b;

for (int operation: mathOperations){
System.out.println(operation);
}
---------------------------------
int [] mathOperations = new int[3];
mathOperations[0]=a+b;

for (int operation: mathOperations){
System.out.println(operation);
}
------------------------------------------------
3) Branching Statements

> Branching Statements are used to transfer control from one point to another in the code
> Branching Statements are defined by the three keywords- break, continue, and return.

1) break

> break statement is used to stop the execution and comes out of loop.
> Mostly break statement used in switch, and in loops also we can use it.

Example:
for (int i=1; i<=10; i++){
System.out.println(i);
if (i == 4){
break;
}
------------------------------
2) continue

continue statement is also same as break statement, the only difference is when break statement executes it comes out of loop, whereas continue statement comes out from the loop temporarily.

Example:
for (int i=1; i<=10; i++){
if (i%2 == 0){
continue;
}
System.out.println(i);
}
-----------------------------------
3) return 

return statement is used in user defined methods (methods with return value), which returns a value or statement from current to calling return statement must be always last statement in the method.

Example:
public int add(int a, int b){
int result = a+b;
return result;
}
public static void main(String[] args) {
VariablesOperators sirisha = new VariablesOperators();
int d= sirisha.add(10, 30);
System.out.println(d);//40
System.out.println(sirisha.add(10, 40));//50
--------------------------------------------
public class VariablesOperators {
public static void main(String[] args) {
VariablesOperators sirisha = new VariablesOperators();
int d= sirisha.add(10, 30);
System.out.println(d);//40
System.out.println(sirisha.add(10, 40));//50
}
public int add(int a, int b){
int result = a+b;
return result;
}

}
-----------------------------------------------
Note: 
> Write user defined methods before main method or after main method (with in class only)
> Call user defined (Non-static) methods within main method only
> Don't write user defined methods within main method.
---------------------------------------------------------------------
Also Watch:
Java Step by Step Videos