PageLoadTimeOut in Selenium

package webdriver;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PageLoad {
	
	static WebDriver driver;

	public static void main(String[] args) {
		
		driver = new FirefoxDriver();
		
		driver.manage().window().maximize();
		
		driver.get("http://facebook.com");
		
		driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
		
		driver.quit();
		
	}

}

The above code will verify the page is getting load with expected time(5 Sec) or not.  If Page will not load completely within the given time then selenium will throw the TimeoutException in the console.

Java Program to Sort the Array in an Ascending and Descending Order

Ascending Order:

package javabasics;

import java.util.Arrays;

public class SortingNumbers {

	public static void main(String[] args) 
	{
		// Initializing unsorted int array
		int Arr[] = {2, 1, 8, 6, 4,25,5,19};

		// let us print all the elements available in list
		for (int number : Arr) {
		System.out.println("Number = " + number);
		}

		// sorting array
		Arrays.sort(Arr);

		// let us print all the elements available in list
		System.out.println("The sorted int array is:");
		for (int number : Arr) {
		System.out.println("Number = " + number);
		}

	}

}
package javabasics;

import java.util.Scanner;

public class AscendingOrder {

	public static void main(String[] args) 
	{
		int num, i, j, temp;
		
		Scanner input = new Scanner(System.in);
	 
	    System.out.println("Enter the number of integers to sort:");
	    
	    num = input.nextInt();
	 
	    int array[] = new int[num];
	 
	    System.out.println("Enter " + num + " integers: ");
	 
	    for (i = 0; i < num; i++) 
	    
	    array[i] = input.nextInt();
	 
	    for (i = 0; i < ( num - 1 ); i++) {
	      for (j = 0; j < num - i - 1; j++) {
	        if (array[j] > array[j+1]) 
	        {
	           temp = array[j];
	           array[j] = array[j+1];
	           array[j+1] = temp;
	        }
	      }
	    }
	 
	    System.out.println("Sorted list of integers:");
	 
	    for (i = 0; i < num; i++) 
	      System.out.println(array[i]);

	}

}

Descending Order:

package javabasics;

import java.util.Scanner;

public class DescendingOrder {

	public static void main(String[] args) {
		int num, i, j, temp;
	    Scanner input = new Scanner(System.in);
	 
	    System.out.println("Enter the number of integers to sort:");
	    num = input.nextInt();
	 
	    int array[] = new int[num];
	 
	    System.out.println("Enter " + num + " integers: ");
	 
	    for (i = 0; i < num; i++) 
	      array[i] = input.nextInt();
	 
	    for (i = 0; i < ( num - 1 ); i++) {
	      for (j = 0; j < num - i - 1; j++) {
	        if (array[j] < array[j+1]) 
	        {
	          temp = array[j];
	          array[j] = array[j+1];
	          array[j+1] = temp;
	        }
	      }
	    }
	 
	    System.out.println("Sorted list of integers:");
	 
	    for (i = 0; i < num; i++) 
	      System.out.println(array[i]);
		

	}

}

 

Split string in Java

package javabasics;

public class StringUsage 
{

	public static void main(String[] args) 
	{
		
		String S = "India is my country";				  
		
		//Split string
		String splt[] = S.split("my");
		System.out.println("String Part 1 Is : --- "+splt[0]+"\n");
		System.out.println("String Part 2 Is : --- "+splt[1]+"\n");
		
	}

}

Output:

String Part 1 Is : --- India is 

String Part 2 Is : ---  country

 

Find the length of the string and convert in lower / upper case in Java

package javabasics;

public class StringUsage 
{

	public static void main(String[] args) 
	{
		
		String S1 = "India is my country";
		String S2 = "USA is my country";
		  				
		//Find the length of string S1.
		System.out.println("Length of S1 : --- "+S1.length()+"\n");
		
		//Find the length of string S2.
		System.out.println("Length of S2 : --- "+S2.length()+"\n");
		
		//Converting whole string S1 in lower case
		System.out.println("String S1 in lower case : --- "+S1.toLowerCase()+"\n");
		
		//Converting whole string S2 in upper case
		System.out.println("String S2 in upper case : --- "+S2.toUpperCase()+"\n");				

	}

}

Output:

Length of S1 : --- 19

Length of S2 : --- 17

String S1 in lower case : --- india is my country

String S2 in upper case : --- USA IS MY COUNTRY

 

Retrieve the indexed character from string in Java

package javabasics;

public class StringUsage 
{

	public static void main(String[] args) 
	{
		
		String S1 = "India is my country";
		String S2 = "USA is my country";		  
				  
		//Retrieve the 10th Indexed character from string S1
		System.out.println("Character at Index 10 Is : --- "+S1.charAt(10)+"\n");
		
		//Retrieve the 10th Indexed character from string S2
		System.out.println("Character at Index 10 Is : --- "+S2.charAt(10)+"\n");
		
		

	}

}

Output:

Character at Index 10 from String S1 is : --- y

Character at Index 10 from String S2 is : --- y

 

Concatenate two strings in Java

package javabasics;

public class ConcatenatesTwoStrings 
{

	public static void main(String[] args) 
	{
		
		String S1 = "India is my country";
		String S2 = "USA is my country";
		  			  
		//Concatenates S2 with S1.
		System.out.println("Concatenation of S1 and S2 Is : --- "+S1.concat(S2)+"\n");	  
		
	}

}

Output:

Concatenation of S1 and S2 Is : --- India is my country  USA is my country

 

1 2 3 6