Automation Using Selenium Webdriver

Wednesday 28 December 2016

TCS selenium webdriver interview questions 2nd Dec

---------------    ************   ---------------- *********      -------------------------


  Introduce yourself  tell something about your last project?
  Count no. Of words and sentence in notepad and arrange them in ascending order?
  Write the format of XML file for BATCH EXICUTION?

  Please explain your project architecture with framework with diagram?
  What  are  the technical challanges you have faced?
. there are one string say Aattribute , so write a code to find the repeated word in that string 
  and it should work for case insensitive(work for lower case and upper case) ?
  Write a query for self join?
  how to take screenshot write code?
. if you have opened any web application and it is broken means it has changed its layout and other         thing which type of testing you will perform to check this?
   What are the things u stored in PageFactory ? Why ?
  Explain TestNG?
  What are the annotations U have Used and why ?
  Explain Agile Method?
  What is StringBuffer and StringBuilder?
  Difference between delete and truncate ?















Tuesday 27 December 2016

Collections Set in Java

Collections:
  • Collections in java is a framework that provides an architecture to store and display the data.
  • Collections API provides interfaces and classes.
  • Using Collection we can perform operations like searching,sorting,insertion,deletion,manipulation.
  • Collections is nothing but group of different type of objects together as a single entity is also known as Collections.
  • Collections are growable Nature.
  • Collection Framework having Interfaces like Set,List,Map.Every Interface having classes.
Why Collection Came?
  • Arrays are fixed in size.we can't increase size of Arrays.that's y only collections came.collections having growable nature.we can increase size.
Set Interface:
  • A set is a collection that having only unique elements.Duplicate won't be there.
  • Set having no index.
  • Set allows only one null value.
  • Set having classes like :
  • HashSet
  • LinkedHashMap
  • TreeSet

HashSet:

HashSet having only unique elements.
HashSet having no Order.
HashSet allows only one null value.

Program for HashSet:
package.com.instanceofjava;
import.java.util.HashSet;

public class A{
public static void main(String args[]){

HashSet hashset=new HashSet();

hashset.add("Indhu");
hashset.add("Indhu");
hashset.add("Sindhu");
hashset.add("swathi");
hashset.add(null);
hashset.add(null);
hashset.add("Lavs");
Iterator it=hashset.iterator();
while(it.hasNext()){
System.out.println(it.next);
}
}
}
Output:
Indhu
null
Lavs
Sindhu
swathi

LinkedHashMap:
  • LinkedHashMap allows only unique elements.
  • LinkedHasMap allows Insertion order.
  • LinkedHashMap allows only one null value.

Program for LinkedHashSet;

package.com.instanceofjava;
import.java.util.LinkedHashSet;

public class testSet{
public static void main(String args[]){

LinkedHasMap linkedHashMap=new LinkedHasMap();

linkedHashMap.add("Indhu');
linkedHashMap.add("Indhu");
linkedHashMap.add("Sindhu");
linkedHashMap.add("Bindhu");
linkedHashMap.add(null);
linkedHashMap.add(null);

Iterator it=linkedHashMap.iterator();
while(it.hasNext()){
System.out.println(it.next);
}
}
}

Output:
Indhu
Sindhu
Bindhu
null


TreeSet:
  • TreeSet Allows only Unique elements.
  • Treeset having sorted order
  • TreeSet doesn't allow  any null value.
Program for TreeSet:

package.com.instanceofjava;
import.java.util.TreeSet;

Public class testSet2{

public static void main(String args[]){
TreeSet treeSet=new treeSet();
treeSet.add("Sindhu");
treeSet.add("Sindhu");
treeSet.add("Indhu");
treeSet.add("Bindhu');
Iterator it=treeSet.iterator();
while(it.hasNext()){
System.out.println(it.next);
}
}
}

Output:
Bindhu
Indhu
Sindhu
  • in Set interface if you want to add elements you can use add() method.
  • If you want to remove you can use remove() method.

Monday 26 December 2016

String vs stringbuffer vs stringbuilder

1.Definition:

  • String is an immutable sequence of characters.
  • StringBuffer is mutable sequence of characters.
  • StringBuilder is also mutable sequence of characters.

The only difference between StringBuffer and StringBuilder: 

  • StringBuffer object is thread safe , it means StringBuffer object is modified by multiple concurrently, because  all its methods are declared as "synchronized".
  • StringBuilder class is given in jdk 1.5 version as non thread -safe class, means all its methods are non synchronized methods.
  • So , in single model application we must use StringBuilder, so that object locking and unlocking will not be there, hence performance is increased.
  • In single thread model application operations are executed in sequence hence there is no chance of object corruption.

When should we choose String and StringBuffer? 

  • If we do not want to store string modifications in the same memory we must choose String.
  • To do modifications in the same memory, we must choose StringBuffer or StringBuilder.

 Advantage and disadvantage in String: 

  • Advantage : Since modifications are preserving in another memory location, we will have both original and modified values.
  • Disadvantage: It consumes lot memory for every operation, as it stores it modifications in new memory. So it leads to performance issue.
  • Solution: To solve this performance issue , in projects developers store string data using StringBuilder or StringBuffer after all modifications they convert into String and pass it back to user.

Advantage and disadvantage of StringBuffer or StringBuilder:

  • Advantage: It given high performance because consumes less memory as all modifications stored in same memory.
  • Disadvantage: Original value will not be preserved.

2.Creating String , StringBuffer objects: 

String:

  • String object can be created in two ways.
  • By using string literal : String str="instance of java ";
  • By using its constructors: String str= new String("instaneofjavaforus") ;

StringBuffer:

  • By using its available constructors
  • StringBuffer str= new StringBuffer();

StringBuilder:

  • By using its available constructors
  • StringBuilder str= new StringBuilder ();

3.Special operations those we can only perform on StringBuffer and StringBuilder: 

  1. append
  2. insert
  3. delete
  4. reverse
  •  Since string is immutable we cannot perform these operations on String.

4.Concatenation:

  • Using String object we can concat new string to the current  string in two ways.
  1. Using + operator
  2. using concat() method.
  • Using StringBuffer we can perform concat operation only in one way
  1. Using append() method
  • Using StringBuilder we can perform concat operation only in one way
  1. Using append() method
package com.javaforus;
public Class SBDemo{ 
public static void main (String args[]) {
        String str="Java";
        StringBuffer sb= new StringBuffer("Java");
        StringBuilder sbr= new StringBuilder("Java");
       System.out.println(str.concat(" language"));    
       System.out.println(sb.append(" language"));
        System.out.println(sbr.append(" language"));
}
}
OutPut:
Java language
Java language
Java language

5.Comparison:

  • Using equals() method String objects are compared with state, because it is overridden in this class. Also hashcode(0 method is overridden in order to satisfy equals() method contract.
  • But in StringBuffer and in StringBuilder equals() method is not overridden , so using equals() method their object are compared with reference. 

Sunday 25 December 2016

WalkinDrive Interview Questions in cipherCould Saterday

Walkin Drive Interview Questions in cipherCould Saterday

---- frist Written test code----
How to handle run time exception write code with example?
D/w Hashmap&Obbject array?
Reverse String without using Reverse function?
Read values from excel using Apach POI/Jxl write code?
---F2F------------------
List&set D/w?
Interface&Abstract D/w?
Method Overloading&Method Overriding with ex?
how to handle aletrs write methods and code?
write program below code
1
22
333
4444?
what is Inheritance and where to use in your project explan?
About TestNG ?



Friday 23 December 2016

Top 20 collection framework interview questions and answers in java

Java collections interview questions:


1.Why Map interface doesn’t extend Collection interface?

Set is unordered collection and does not allows duplicate elements.
List is ordered collection allows duplicate elements.
Where as Map is key-value pair.
It is viewed as set of keys and collection of values.
Map is a collection of key value pairs so by design they separated from collection interface.

2.What is difference between HashMap and Hashtable?

  • Synchronization or Thread Safe 
  • Null keys and null values 
  • Iterating the values 
  •  Default Capacity 
Hashmap%2Bvs%2Bhashtable

3.Differences between comparable and comparator?

Comparable Interface is actually from java.lang package.
It will have a method compareTo(Object obj)to sort objects
Comparator Interface is actually from java.util package.
It will have a method compare(Object obj1, Object obj2)to sort objects

4.How can we sort a list of Objects?

 To sort the array of objects we will use  Arrays.sort() method.
If we need to sort collection of object we will use Collections.sort().

5.What is difference between fail-fast and fail-safe?

Fail fast is nothing but immediately report any failure. whenever a problem occurs fail fast system fails.
in java Fail fast iterator while iterating through collection of objects sometimes concurrent
modification exception will come there are two reasons for this.
If one thread is iterating a collection and another thread trying to modify the collection.
And after remove() method call if we try to modify collection object


6. What is difference between Iterator ,ListIterator and Enumeration?

Enumeration interface implemented in java 1.2 version.So Enumeration is legacy interface.
Enumeration uses elements() method.
Iterator is implemented on all Java collection classes.
Iterator uses iterator() method.
Iterator can traverse in forward direction only.
ListIterator is implemented only for List type classes
ListIterator uses listIterator() method.
Read more :
What is difference between Iterator ,ListIterator and Enumeration?

7.What is difference between Set and List in Java?

A set is a collection that allows unique elements.
Set does not allow duplicate elements
Set allows only one null value.
Set having classes like :
HashSet
LinkedHashSet
TreeSet
List having index. and ordered  collection
List allows n number of null values.
List will display Insertion order with index.
List having classes like :
Vector
ArrayList
LinkedList
8.Differences between arraylist and vector?

Vector was introduced in  first version of java . that's the reason only vector is legacy class.
ArrayList was introduced in java version1.2, as part of java collections framework.
Vector is  synchronized.
ArrayList is not synchronized.
Read more: Differences between arraylist and vector
9.What are the classes implementing List interface?

ArrayList  
LinkedList  
Vector
10. Which all classes implement Set interface ?

HashSet
LinkedHashSet
TreeSet
11.How to make a collection thread safe?

Vector, Hashtable, Properties and Stack are synchronized classes, so they are thread-safe and can be
used in multi-threaded environment.
By using Collections.synchronizedList(list)) we can make list classes thread safe.
By using
java.util.Collections.synchronizedSet()  we can make set classes thread safe.
12.Can a null element added to a TreeSet or HashSet?

One null element can be added to hashset.
TreeSet does not allow null values
13. Explain Collection’s interface hierarchy?



14.Which design pattern Iterator follows?

Iterator design pattern

15.Which data structure HashSet implements

Hashset implements hashmap internally.

16.Why doesn't Collection extend Cloneable and Serializable?

List and Set and queue extends Collection interface.
SortedMap extends Map interface.

17.What is the importance of hashCode() and equals() methods? How they are used in Java?

equals() and hashcode() methods defined in "object" class.
If equals() method return true on comparing two objects then hashcode() of those two objects must be same.

18.What is difference between array & arraylist?

Array is collection of similar type of objects and fixed in size.
Arraylist is collection of homogeneous and heterogeneous elements.

19.What is the Properties class?

Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key and the value is String.

20.How to convert a string array to arraylist?

ArrayList al=new ArrayList( Arrays.asList( new String[]{"java", "collection"} ) );
 arrayList.toArray(); from list to array

Thursday 22 December 2016

How to read a file in java with example program



  • We can read java file using buffered reader class in java
  • We need to import java.io.BufferedReader in order to read java text file.
  • Create object of java.io.BufferedReader class by passing new FileReader("C:\\Sample.txt") object to the constructor.
  • In order to read line by line call readLine() method of BufferedReader class which returns current line. Initially first line of java text file
  •  Program #1: Write a java program to read a file line by line using BufferedReader class 

  • package com.instanceofjava.javareadfile;

  • import java.io.BufferedReader;
  • import java.io.FileReader;
  • import java.io.IOException;

  • public class ReadFileBufferedReader {

  •  /**
  •   * 
  •   * @category: How to read java read file line by line using buffered reader
  •   */

  • public static void main(String[] args) {

  •   BufferedReader breader = null;

  •  try {

  •  String CurrentLine;

  •  breader = new BufferedReader(new FileReader("E://Sample.txt"));

  •  while ((CurrentLine = breader.readLine()) != null) {
  •     System.out.println(CurrentLine);
  •  }

  • } catch (IOException e) {
  •    e.printStackTrace();
  • } finally {
  •     try {
  •  if (breader != null)
  •      breader.close();
  •      } catch (IOException ex) {
  •     ex.printStackTrace();
  •      }
  • }

  • }

  • }

  •  Output:
  •   
  • Java open and read file
  • Read file line by line in java
  • Example java program to read a file line by line
  • java read file line by line example


  • Java example program to print message without using System.out.println()

    Is it possible to print message without using system.out.println?




    Yes its possible to print message without using System.out.println("");

    System.out.write("www.corejavawithselenium.blogspot.in\n".getBytes());
     System.out.format("%s", "www.java.com \n")
     PrintStream myout =  new PrintStream(new FileOutputStream(FileDescriptor.out));
       myout.print("www.corejavawithselenium.blogspot.in \n");
    System.err.print("This is custom error message");
    System.console().writer().println("Hai");

    1.System.out.write(Byte [] arg0);

    System.out.write(Byte [] arg0) method The java.io.FilterOutputStream.write(byte[] b) method writes b.length bytes to this output stream.

    package com.instanceofjava;

    public class PrintMessage {

    public static void main(String[] args) throws IOException{

           System.out.write("Hello World".getBytes());
    }
    }

    Output:

    Hello World

    2. PrintStream  java.io.PrintStream.format(String arg0, Object... arg1)

    System.out.format("format",Object obj) by using this method we can format the text and print

    package com.instanceofjava;

    public class PrintMessage {

    public static void main(String[] args){

            System.out.format("%s", "James");
    }

    }

    Output:

    James

    3. FileDescriptor:

    Create PrintStream object by passing FileOutputStream(FileDescriptor.out) object as an argument to the constructor
    package com.instanceofjava;

    public class PrintMessage {

    public static void main(String[] args){

           PrintStream myout =  new PrintStream(new FileOutputStream(FileDescriptor.out));
              myout.print("i love Java");
    }
    }

    Output:

    i love java


    4. System.err.print(""):

    We can use System.err.print("") method to print the message actually its used to print error message
    package com.instanceofjava;

    public static void main(String[] args){

           System.err.print("This is custom error message");
    }
    }

    Output:

    This is custom error message


    5.System.console().writer().println("");

    System.console() returns null if your application is not run in a terminal System.console() provides methods for reading password without echoing characters

    package com.instanceofjava;

    public static void main(String[] args){

           System.err.print("This is custom error message");
    }
    }

    Output:

    This is custom error message Exception in thread "main" java.lang.NullPointerException
        at PrintMessage.main(PrintMessage.java:24)