Showing posts with label Java Interview Questions and answers. Show all posts
Showing posts with label Java Interview Questions and answers. Show all posts

Tuesday, 3 January 2017

Selenium Interview Questions and Answers

Listing down some of the links for Interview questions and answers for Selenium webdriver
Please feel free to add more under the comments.

1. http://www.techbeamers.com/category/interview-questions/selenium-interview/
2. https://www.linkedin.com/pulse/selenium-real-time-interview-questions-answers-technologies-13600-
3. https://intellipaat.com/interview-question/selenium-interview-questions/

Sunday, 11 September 2016

Grid Installation/Set up

Prerequisite

1.       Java installed on the machine and environment variable set for Java (JAVA_HOME).
2.       Eclipse installed.
3.      TestNG is installed in eclipse.

Steps to install grid

1.       Download selenium server jar from Selenium Downloads Page , you will find it under section “Selenium-Server (formerly Selenium-RC)”.

2.       Extract it in your system say C drive . For Demonstration purposes , I will be assuming the path of selenium server jar is “C:\”.

Next

Java Program to reverse a string

package My;

import java.util.*;

class ReverseString
{
   public static void main(String args[])
   {
      String original, reverse = "";
      Scanner in = new Scanner(System.in);

      System.out.println("Enter a string to reverse");
      original = in.nextLine();

      int length = original.length();

      for ( int i = length - 1 ; i >= 0 ; i-- )
         reverse = reverse + original.charAt(i);

      System.out.println("Reverse of entered string is: "+reverse);
   }
}

Java program to reverse a number

package My;

import java.util.Scanner;

class ReverseNumber
{
   public static void main(String args[])
   {
      int n, reverse = 0;

      System.out.println("Enter the number to reverse");
      Scanner in = new Scanner(System.in);
      n = in.nextInt();

      while( n != 0 )
      {
          reverse = reverse * 10;
          reverse = reverse + n%10;
          n = n/10;
      }

      System.out.println("Reverse of entered number is "+reverse);
   }
}

Java program to print stars pattern

package My;

class stars {
  public static void main(String[] args) {
    int row, numberOfStars;

    for (row = 1; row <= 10; row++) {
      for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
        System.out.print("*");
      }
      System.out.println(); // Go to next line
    }
  }
}

output :

*
**
***
****
*****

Java Program for Prime number

package My;

import java.util.*;

class PrimeNumbers
{

/*
*
* We have used sqrt method of Math package which find square root
* of a number. To check if an integer(say n) is prime you can check
*  if it is divisible by any integer from 2 to (n-1) or check from 2
*  to sqrt(n), first one is less efficient and will take more time.
*/
   public static void main(String args[])
   {
      int n, status = 1, num = 3;

      Scanner in = new Scanner(System.in);
      System.out.println("Enter the number of prime numbers you want");
      n = in.nextInt();

      if (n >= 1)
      {
         System.out.println("First "+n+" prime numbers are :-");
         System.out.println(2);
      }

      for ( int count = 2 ; count <=n ;  )
      {
         for ( int j = 2 ; j <= Math.sqrt(num) ; j++ )
         {
            if ( num%j == 0 )
            {
               status = 0;
               break;
            }
         }
         if ( status != 0 )
         {
            System.out.println(num);
            count++;
         }
         status = 1;
         num++;
      }        
   }
}

Java Program to find factorial

package My;

import java.util.Scanner;

class Factorial
{
   public static void main(String args[])
   {
      int n, c, fact = 1;

      System.out.println("Enter an integer to calculate it's factorial");
      Scanner in = new Scanner(System.in);

      n = in.nextInt();

      if ( n < 0 )
         System.out.println("Number should be non-negative.");
      else
      {
         for ( c = 1 ; c <= n ; c++ )
            fact = fact*c;

         System.out.println("Factorial of "+n+" is = "+fact);
      }
   }
}

Java program for binary search

package My;

import java.util.Scanner;

class BinarySearch
{
  public static void main(String args[])
  {
    int c, first, last, middle, n, search, array[];

    Scanner in = new Scanner(System.in);
    System.out.println("Enter number of elements");
    n = in.nextInt();
    array = new int[n];

    System.out.println("Enter " + n + " integers");


    for (c = 0; c < n; c++)
      array[c] = in.nextInt();

    System.out.println("Enter value to find");
    search = in.nextInt();

    first  = 0;
    last   = n - 1;
    middle = (first + last)/2;

    while( first <= last )
    {
      if ( array[middle] < search )
        first = middle + 1;  
      else if ( array[middle] == search )
      {
        System.out.println(search + " found at location " + (middle + 1) + ".");
        break;
      }
      else
         last = middle - 1;

      middle = (first + last)/2;
   }
   if ( first > last )
      System.out.println(search + " is not present in the list.\n");
  }
}

Java Program to Add two Matrix

package My;

import java.util.Scanner;

class AddTwoMatrix
{
   public static void main(String args[])
   {
      int m, n, c, d;
      Scanner in = new Scanner(System.in);

      System.out.println("Enter the number of rows and columns of matrix");
      m = in.nextInt();
      n  = in.nextInt();

      int first[][] = new int[m][n];
      int second[][] = new int[m][n];
      int sum[][] = new int[m][n];

      System.out.println("Enter the elements of first matrix");

      for (  c = 0 ; c < m ; c++ )
         for ( d = 0 ; d < n ; d++ )
            first[c][d] = in.nextInt();

      System.out.println("Enter the elements of second matrix");

      for ( c = 0 ; c < m ; c++ )
         for ( d = 0 ; d < n ; d++ )
            second[c][d] = in.nextInt();

      for ( c = 0 ; c < m ; c++ )
         for ( d = 0 ; d < n ; d++ )
             sum[c][d] = first[c][d] + second[c][d];  //replace '+' with '-' to subtract matrices

      System.out.println("Sum of entered matrices:-");

      for ( c = 0 ; c < m ; c++ )
      {
         for ( d = 0 ; d < n ; d++ )
            System.out.print(sum[c][d]+"\t");

         System.out.println();
      }
   }
}

Selenium Java Interview Questions