Final and Finally:
//Final variable can not be changes
//Finally is a block in try catch clock
//Throw: deliberately throwing exception- your own description-uncaught exception
//when we deliberately throw?? suppose we have 4 tests..1 st test to run 2nd no run , here we deliberately throw exception
//Throws -capable of throwing an exception
//Finally is always executed whether or not the try catch block is success or not
//Throw able is super class-under this exception and error..and there is one more called, run time exception
//so we use catch(throw able) in that case- any type of error or exception
try{
//establish connection and get results and close connection, to close connection always use finally
//int i=8/0;
return;
}
catch(Exception e){
System.out.println("error");
}
finally{
System.out.println("close");
Collection API's:
//i want to store all links on a page into an array, the no.of links may change when i refresh my page
//i don't know the final size of array
//array list used to create dynamically growing list of array
ArrayList<String> list = new ArrayList<String>();
list.add("A");//0
list.add("B");//1
//list.add(667) //we get errpr as it is string type
//we get some warniing symbol if we do list.add("A")
//we need to give which type of array<string>
System.out.println(list.get(1));
for (int i=0;i<list.size();i++)
System.out.println(list.get(i));
//hash table//Hash table table= new Hash table();
//hash table is another type for dynamically growing list
//hash table use key and value concept
//hash table doesn't have index
Hashtable<String,String> table=new Hashtable<String,String>();
table.put("name","meeraja");
table.put("place","ca");
System.out.println(table.get("place"));// will print ca
table.put("place","san ramon");
System.out.println(table.get("place")); will print san ramon
Properties file:
//create properties file with various fields for the use of selenium
//we can store x paths
//it is similar to Object repository
//to keep all the x paths of files, check boxes etc
//get this properties file by using its path by right click and select properties
//Final variable can not be changes
//Finally is a block in try catch clock
//Throw: deliberately throwing exception- your own description-uncaught exception
//when we deliberately throw?? suppose we have 4 tests..1 st test to run 2nd no run , here we deliberately throw exception
//Throws -capable of throwing an exception
//Finally is always executed whether or not the try catch block is success or not
//Throw able is super class-under this exception and error..and there is one more called, run time exception
//so we use catch(throw able) in that case- any type of error or exception
try{
//establish connection and get results and close connection, to close connection always use finally
//int i=8/0;
return;
}
catch(Exception e){
System.out.println("error");
}
finally{
System.out.println("close");
Collection API's:
//i want to store all links on a page into an array, the no.of links may change when i refresh my page
//i don't know the final size of array
//array list used to create dynamically growing list of array
ArrayList<String> list = new ArrayList<String>();
list.add("A");//0
list.add("B");//1
//list.add(667) //we get errpr as it is string type
//we get some warniing symbol if we do list.add("A")
//we need to give which type of array<string>
System.out.println(list.get(1));
for (int i=0;i<list.size();i++)
System.out.println(list.get(i));
//hash table//Hash table table= new Hash table();
//hash table is another type for dynamically growing list
//hash table use key and value concept
//hash table doesn't have index
Hashtable<String,String> table=new Hashtable<String,String>();
table.put("name","meeraja");
table.put("place","ca");
System.out.println(table.get("place"));// will print ca
table.put("place","san ramon");
System.out.println(table.get("place")); will print san ramon
Properties file:
//create properties file with various fields for the use of selenium
//we can store x paths
//it is similar to Object repository
//to keep all the x paths of files, check boxes etc
//get this properties file by using its path by right click and select properties
name=meeraja
age=34
hobbies=cooking
dob=oct 18
public class ReadingProperties {
public static void main(String[] args) throws IOException {
Properties prop= new Properties();
FileInputStream fs= new FileInputStream("C:\\eclipse-workspace-meeraja\\Test\\src\\config\\Employee.properties");
//FileInputStream fs1= new FileInputStream(System.getProperty("user.dir" ) + "\\src\\config\\Employee.properties");
prop.load(fs);
//properties is a inbuilt class...
Reading File:
//create file
File f=new File("c:\\meeraja-Selenium\\temp.txt");
f.createNewFile();
//write into file
FileWriter w=new FileWriter("c:\\meeraja-Selenium\\temp.txt");
BufferedWriter bf= new BufferedWriter(w);
bf.write("first line");
bf.newLine();
bf.write("first line");
bf.flush();
//read file
FileReader r=new FileReader("c:\\meeraja-Selenium\\temp.txt");
BufferedReader br= new BufferedReader(r);
String x="";
while((x=br.readLine()) !=null)
{
System.out.println(x);
}
String functions:
String str="My name is padmaja";
String str1="My name is rama";
System.out.println("length is " +str.length());
System.out.println("char is " +str.charAt(5));
System.out.println("index is " +str.indexOf('m'));//first occurance is at 5
System.out.println("index is " +str.indexOf('m',6));// index of functiom ith letter and index from there i.e.after 5 so, give 6
System.out.println(str.indexOf("hello")); //will print -1
System.out.println(str.equals(str1)); //will print false
System.out.println(str.substring(3, 10)); //will print 'name is'
//String temp[]=str.split("name");
String temp[]=str.split(" ");
for(int i=0;i<temp.length;i++)
System.out.println(temp[i]); //print each word in separate line
String z= "800";
int y= Integer.parseInt(z);// use only numbers..we get exception....if we give String as "meer"
System.out.println(y);
String k =String.valueOf(y);
ExceptionHandling
System.out.println("A");
try{
System.out.println("B");
int i= 8/0;
}catch(Exception e){
System.out.println("C");
System.out.println("error" +e.getMessage());
e.printStackTrace();
System.out.println("D");
//will get output as A B java.lang.ArithmeticException: / by zero
at Exception.ExceptionHandling.main(ExceptionHandling.java:10) C error/ by zero D
Throws and Throw :
public static void clickLink() throws InterruptedException
Interrupted Exception Thrown when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted, either before or during the activity. Occasionally a method may wish to test whether the current thread has been interrupted, and if so, to immediately throw this exception. The following code can be used to achieve this effect:
if (Thread.interrupted()) // Clears interrupted status! throw new InterruptedException();