Java-Programs-asked-in-Selenium-Interview

1. How to Print List of Even Numbers in Java?

 package JavaPrograms_InterviewQuestions;

 import java.util.Scanner;

 public class PrintEvenNumbers {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println(“Enter Limit:”);

int value = sc.nextInt();

System.out.println(“Print Even numbers between 1 and ” + value);

for (int j = 1; j <= value; j++) {

// if the number is divisible by 2 then it is even

if (j % 2 == 0) {

System.out.print(j + ” “);

}

}

}

}

Output :

Enter Limit:

40

Print Even numbers between 1 and 40

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40

2.How to Compare Two Numbers In Java ?

 package JavaPrograms_InterviewQuestions;

import java.util.Scanner;

public class CompareTwoNumbersInJava {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println(“Enter Number 1: “);

int num1 = sc.nextInt();

System.out.println(“Enter Number 2: “);

int num2 = sc.nextInt();

if (num1 > num2) {

System.out.println(num1 + ” is greater than ” + num2);

} else if (num1 < num2) {

System.out.println(num1 + ” is less than ” + num2);

} else {

System.out.println(num1 + ” is equal to ” + num2);

}

}

}

Output :

Enter Number 1:

14

Enter Number 2:

12

14 is greater than 12

3.Access Modifiers in Java ?

package JavaPrograms_InterviewQuestions;

public class Java_AccessModifier {

public int a = 10;

protected int b = 20;

private int c = 30;

int d = 40;

public void test1() {

System.out.println(“public test1()”);

}

protected void test2() {

System.out.println(“protected  test2()”);

}

void test3() {

System.out.println(“void test3()”);

}

private void test4() {

System.out.println(“private  test4()”);

}

public static void main(String[] args) {

Java_AccessModifier obj = new Java_AccessModifier();

obj.test1();

obj.test2();

obj.test3();

obj.test4();

System.out.println(obj.a);

System.out.println(obj.b);

System.out.println(obj.c);

System.out.println(obj.d);

}

}

Output :

public test1()

protected  test2()

void test3()

private  test4()

10

20

30

40

HOW TO HANDLE FRAME IN SELENIUM WEBDRIVER USING JAVA?

4.Verify Year is Leap Year or Not in Java ?

package JavaPrograms_InterviewQuestions;

import java.util.Scanner;

public class VerifyLeapYear {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println(“Enter Year: “);

int year = sc.nextInt();

// if year is divisible by 4, it is a leap year

if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {

System.out.println(“Year ” + year + ” is a leap year”);

} else {

System.out.println(“Year ” + year + ” is not a leap year”);

}

}

}

 

Note: Every fourth year is Leap Year.

Output :

Enter Year:

2008

Year 2008 is a leap year

 

5. To verify whether the no is palindrome or not in java?

package JavaPrograms_InterviewQuestions;

import java.util.Scanner;

class VerifyPalindrome {

public static void main(String args[]) {

int r, sum = 0, temp;

Scanner sc = new Scanner(System.in);

System.out.println(“Enter Number to Check Palindrome or Not:”);

int n = sc.nextInt();

temp = n;

while (n > 0) {

r = n % 10;

sum = (sum * 10) + r;

n = n / 10;

}

if (temp == sum) {

System.out.println(“Given Number is Palindrome”);

} else {

System.out.println(“Given Number is Not Palindrome “);

}

}

}

 

Note: A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed.

 

Output :

Enter Number to Check Palindrome or Not:

5

Given Number is Palindrome

STEPS TO CONFIGURE SELENIUM WEBDRIVER WITH JAVA TO DEVELOP TEST SCRIPTS

6. Find Factorial of a Number in Java?

package JavaPrograms_InterviewQuestions;

import java.util.Scanner;

public class FactorialNumber {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println(“Enter Number: “);

int value = sc.nextInt();

int factorial = value;

for (int a = (value – 1); a > 1; a–) {

factorial = factorial * a;

}

System.out.println(“Factorial of number is ” + factorial);

}

}

 

Note : factorial of number 4!= 4*3*2*1=24.

Output :

Enter Number:

4

Factorial of number is 24

7.H ow to Display Fibonacci Series in java?

 

package JavaPrograms_InterviewQuestions;

import java.util.Scanner;

public class FibonacciSeries {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println(“Enter Number for Fibonacci series :”);

int n = sc.nextInt();

int t1 = 0, t2 = 1;

System.out.print(“First ” + n + ” terms: “);

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

System.out.print(t1 + ” , “);

int sum = t1 + t2;

t1 = t2;

t2 = sum;

}

}

}

 

Output :

Enter Number for Fibonacci series :

10

First 10 terms: 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 ,

8. To Check Whether a Number is Prime or Not in java?

 package JavaPrograms_InterviewQuestions;

import java.util.Scanner;

public class PrimeNumber {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println(“Enter Prime Number: “);

int num = sc.nextInt();

boolean flag = false;

for(int i = 2; i <= num/2; ++i)

{

// condition for nonprime number

if(num % i == 0)

{

flag = true;

break;

}

}

if (!flag)

System.out.println(num + ” is a prime number.”);

else

System.out.println(num + ” is not a prime number.”);

}

}

 

Output :

Enter Prime Number:

29

29 is a prime number.

 

 

 

Automation Testing Tools

Automation Testing Selenium Training in Hyderabad

Automation Testing Tools

There are tons of Functional and Regression Testing Tools available in the market. Here are 5 best tools certified by our experts in Automation Testing.

Automation Testing Tools Selenium Training in Hyderabad

1. Selenium

It is a software testing tool used for regression testing. It is an open source testing tool. That provides playback and recording facility for regression testing. The Selenium IDE only supports Mozilla Firebox web browser.
• It provides the provision to export recorded script in other languages. like Java, Ruby, RSpec, Python, C#, JUnit and TestNG
• It can execute many tests at a time
• Auto-complete for Selenium commands that are common
• Walkthrough tests
• Identifies the element using id, name, X-path, etc.
• Store tests as Ruby Script, HTML, and any other format
• It provides an option to assert the title of every page
• The supports selenium user-extensions.js file
• It allows inserting comments in the middle of the script. The understanding and debugging in Selenium Training in Hyderabad

2. QTP (HP UFT)

It uses for functional and regression testing. It addresses every major software application and the environment. The test creation and maintenance, it uses the concept of keyword driven testing. It allows the tester to build test cases from the application.
• It is easier to use for non-technical person to adapt to and create working test cases
• The fix defects faster by documenting and replicating defects for developer
• Collapse test creation and test documentation at a single site
• Parameterization is easy than Win Runner
• QTP supports.NET development environment
• The better object identification mechanism
• It existing QTP scripts without Application under Test. It is available by using the Active Screen in Selenium.

3. Rational Functional Tester

It is Object Oriented automated functional testing tool. That is performing automated functional, regression, data-driven testing and GUI testing. The main features of this tool are
• It supports a wide range of protocols and applications. Like Java, HTML, NET, Windows, SAP, Visual basic, etc.
• It can record and replay the actions on demand
• It integrates well with source control management tools. Such as Rational Clear Case and Rational Team Concert integration
• It allows developers to create keyword associated script so that it can be re-used
• Eclipse Java Developer Toolkit editor facilitates. the team to code test scripts in Java with Eclipse
• It supports custom controls through proxy SDK
• It supports version control to enable parallel development of test scripts. The concurrent usage by the distributed team in Selenium.

4. WATIR

It is an open source testing software for regression testing. It enables to write tests are easy to read and maintain. Watir supports only internet explorer on windows. While Watir web driver supports Chrome, Firefox, IE, Opera, etc.
• They support many browsers on different platforms
• It using proprietary vendor script. it uses a full-featured modern scripting language Ruby
• It supports web app regardless of develop

5. Silk Test

Silk Test design for doing functional and regression testing. For e-business application, silk test is the leading functional testing product. The product of Software takeover by Borland in 2006. It is an object-oriented language like C++. They Use the concept of an object, classes, and inheritance. Its main feature includes in Selenium Training In Hyderabad

• It consists of all the source script files
• It converts the script commands into GUI commands. On the same machine, commands run on a remote or host machine
• To identify the movement of the mouse along with keystrokes, Silk test executed. It can available both playback and record method or descriptive programming methods.
• It identifies all controls and windows of the application under test as objects. The determine all the attributes and properties of each window

Automation Testing Selenium Training in Hyderabad

Automation Testing Selenium Training in Hyderabad: We provide Classroom and Online  Automation Testing Selenium Training in Hyderabad By Real time experts.