"Karmanyevadhikaraste ma phaleshu kadachana, Ma karma phala hetur bhurmatey sangostva akarmani."

interviewqns-7

) What are the prerequisites to run Java code on your local machine. List all the steps (downloading and installing Java, setting up path and classpath (exact syntax), commands to compile and run)
download java and run the .exe to install Java on your machine
you would need to set environment variables to point to correct installation directories:
·         Right-click on 'My Computer' and select 'Properties'.
·         Click on the 'Environment variables' button under the 'Advanced' tab.
·         Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.
Write java program in notepad or eclpse…and save as xxx.java
public class MyFirstJavaProgram {
 
   /* This is my first java program.  
    * This will print 'Hello World' as the output
    */
 
    public static void main(String []args) {
       System.out.println("Hello World"); // prints Hello World
    }
} 
·         Open a command prompt window and go o the directory where you saved the class. Assume it's C:\.
·         Type ' javac MyFirstJavaProgram.java ' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line (Assumption : The path variable is set).
·         Now, type ' java MyFirstJavaProgram ' to run your program.
·         You will be able to see ' Hello World ' printed on the window.
For all class names the first letter should be in Upper Case. 
·          All method names should start with a Lower Case letter.  Name of the program file should exactly match the class name Examples of legal identifiers: age, $salary, _value, __1_value
·         Examples of illegal identifiers: 123abc, -salary
Java programme:
import java.io.*;
public class Employee{
   String name;
   int age;
   String designation;
   double salary;
         
   // This is the constructor of the class Employee
   public Employee(String name){
      this.name = name;
   }
   // Assign the age of the Employee  to the variable age.
   public void empAge(int empAge){
      age =  empAge;
   }
   /* Assign the designation to the variable designation.*/
   public void empDesignation(String empDesig){
      designation = empDesig;
   }
   /* Assign the salary to the variable     salary.*/
   public void empSalary(double empSalary){
      salary = empSalary;
   }
   /* Print the Employee details */
   public void printEmployee(){
      System.out.println("Name:"+ name );
      System.out.println("Age:" + age );
      System.out.println("Designation:" + designation );
      System.out.println("Salary:" + salary);
   }
}
As mentioned previously in this tutorial, processing starts from the main method. Therefore in-order for us to run this Employee class there should be main method and objects should be created. We will be creating a separate class for these tasks.Save the following code in EmployeeTest.java file
import java.io.*;
public class EmployeeTest{
 
   public static void main(String args[]){
      /* Create two objects using constructor */
      Employee empOne = new Employee("James Smith");
      Employee empTwo = new Employee("Mary Anne");
 
      // Invoking methods for each object created
      empOne.empAge(26);
      empOne.empDesignation("Senior Software Engineer");
      empOne.empSalary(1000);
      empOne.printEmployee();
 
      empTwo.empAge(21);
      empTwo.empDesignation("Software Engineer");
      empTwo.empSalary(500);
      empTwo.printEmployee();
   }
}
Now, compile both the classes and then run EmployeeTest to see the result as follows:
C :> javac Employee.java
C :> vi EmployeeTest.java
C :> javac  EmployeeTest.java
C :> java EmployeeTest
Name:James Smith
Age:26
Designation:Senior Software Engineer
Salary:1000.0
Name:Mary Anne
Age:21
Designation:Software Engineer
Salary:500.0



2) What is the difference in the versioning format in Java (Eg:- 1.5 vs 5.0)
Where there was 1.5.0 now make into 5.0

3)  Name a bug that I missed while testing in my previous project and what did I learn from that
After 3 incorrect validation code, there will be a message box showing error message with ok button, once user clicks on ok button, he will be locked out. But in that case, user will be able to click on ceo drop down menu and would be able to anything else without locking out
4)  More on how I designed my automation framework in Java
----------------------------------------------------------------------------------------------------------------------------------------------------------- 
1) Java basics (Threads, Collections, synchronization, etc)
Thread:All Java programs have at least one thread, known as the main thread, which is created by the JVM at the program’s start, when the main() method is invoked with the main thread. In Java, creating a thread is accomplished by implementing an interface and extending a class. Every Java thread is created and controlled by the java.lang.Thread class.

When a thread is created, it is assigned a priority. The thread with higher priority is executed first, followed by lower-priority threads

Collections: is set of interfaces like collection interface, list, set, map,sorted map, sorted set etc
What is difference between ArrayList and vector?
Ans: )
1) Synchronization - ArrayList is not thread-safe whereas Vector is thread-safe. In Vector class each method like add(), get(int i) is surrounded with a synchronized block and thus making Vector class thread-safe.
2) Data growth - Internally, both the ArrayList and Vector hold onto their contents using an Array. When an element is inserted into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.
The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed.
import java.util.*;

public class ArrayListDemo {
   public static void main(String args[]) {
      // create an array list
      ArrayList al = new ArrayList();
      System.out.println("Initial size of al: " + al.size());

      // add elements to the array list
      al.add("C");
      al.add("A");
      al.add("E");
      al.add("B");
      al.add("D");
      al.add("F");
      al.add(1, "A2");
      System.out.println("Size of al after additions: " + al.size());

      // display the array list
      System.out.println("Contents of al: " + al);
      // Remove elements from the array list
      al.remove("F");
      al.remove(2);
      System.out.println("Size of al after deletions: " + al.size());
      System.out.println("Contents of al: " + al);
   }
}
This would produce the following result:
Initial size of al: 0
Size of al after additions: 7
Contents of al: [C, A2, A, E, B, D, F]
Size of al after deletions: 5 
Contents of al: [C, A2, E, B, D 
Q2) How can Arraylist be synchronized without using Vector?
Ans) Arraylist can be synchronized using:
Collection.synchronizedList(List list)
What is difference between HashMap and HashTable?
Ans) Both collections implements Map. Both collections store value as key-value pairs. The key differences between the two are
1. Hashmap is not synchronized in nature but hshtable is.
2. Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't.
Fail-safe - â€Å“if the Hashtable is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator will throw a ConcurrentModificationExceptionâ€?
3. HashMap permits null values and only one null key, while Hashtable doesn't allow key or value as null.
Q5) What are the classes implementing List interface?
Ans)
There are three classes that implement List interface:
1) ArrayList : It is a resizable array implementation. The size of the ArrayList can be increased dynamically also operations like add,remove and get can be formed once the object is created. It also ensures that the data is retrieved in the manner it was stored. The ArrayList is not thread-safe.

2) Vector: It is thread-safe implementation of ArrayList. The methods are wrapped around a synchronized block.

3) LinkedList: the LinkedList also implements Queue interface and provide FIFO(First In First Out) operation for add operation. It is faster if than ArrayList if it performs insertion and deletion of elements from the middle of a list.
import java.util.*;

public class LinkedListDemo {

   public static void main(String args[]) {
      // create a linked list
      LinkedList ll = new LinkedList();
      // add elements to the linked list
      ll.add("F");
      ll.add("B");
      ll.add("D");
      ll.add("E");
      ll.add("C");
      ll.addLast("Z");
      ll.addFirst("A");
      ll.add(1, "A2");
      System.out.println("Original contents of ll: " + ll);

      // remove elements from the linked list
      ll.remove("F");
      ll.remove(2);
      System.out.println("Contents of ll after deletion: "
       + ll);
      
      // remove first and last elements
      ll.removeFirst();
      ll.removeLast();
      System.out.println("ll after deleting first and last: "
       + ll);

      // get and set a value
      Object val = ll.get(2);
      ll.set(2, (String) val + " Changed");
      System.out.println("ll after change: " + ll);
   }
}
This would produce the following result:
Original contents of ll: [A, A2, F, B, D, E, C, Z]
Contents of ll after deletion: [A, A2, D, E, C, Z]
ll after deleting first and last: [A2, D, E, C]
ll after change: [A2, D, E Changed, C]

Q6) Which all classes implement Set interface?
Ans) A Set is a collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. HashSet,SortedSet and TreeSet are the commnly used class which implements Set interface.
SortedSet - It is an interface which extends Set. A the name suggest , the interface allows the data to be iterated in the ascending order or sorted on the basis of Comparator or Comparable interface. All elements inserted into the interface must implement Comparable or Comparator interface.
TreeSet - It is the implementation of SortedSet interface.This implementation provides guaranteed log(n) time cost for the basic operations (add, remove and contains). The class is not synchronized.
HashSet: This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the null element. This class offers constant time performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets
Q7) What is difference between List and a Set?
Ans)
1) List can contain duplicate values but Set doesnt allow. Set allows only to unique elements.
2) List allows retrieval of data to be in same order in the way it is inserted but Set doesnt ensures the sequence in which data can be retrieved.(Except HashSet)
Q8) What is difference between Arrays and ArrayList ?
Ans) Arrays are created of fix size whereas ArrayList is of not fix size. It means that once array is declared as :
  1. int [] intArray= new int[6];
  2. intArray[7]   // will give ArraysOutOfBoundException.
Also the size of array cannot be incremented or decremented. But with arrayList the size is variable.
  1. Once the array is created elements cannot be added or deleted from it. But with ArrayList the elements can be added and deleted at runtime.
List list = new ArrayList();
list.add(1);
list.add(3);
list.remove(0) // will remove the element from the 1st location.
  1. ArrayList is one dimensional but array can be multidimensional.
            int[][][] intArray= new int[3][2][1];   // 3 dimensional array    
  1. To create an array the size should be known or initalized to some value. If not initialized carefully there could me memory wastage. But arrayList is all about dynamic creation and there is no wastage of memory.
Q9) When to use ArrayList or LinkedList ?
Ans)  Adding new elements is pretty fast for either type of list. For the ArrayList, doing  random lookup using "get" is fast, but for LinkedList, it's slow. It's slow because there's no efficient way to index into the middle of a linked list. When removing elements, using ArrayList is slow. This is because all remaining elements in the underlying array of Object instances must be shifted down for each remove operation. But here LinkedList is fast, because deletion can be done simply by changing a couple of links. So an ArrayList works best for cases where you're doing random access on the list, and a LinkedList works better if you're doing a lot of editing in the middle of the list.
Q10) Consider a scenario. If an ArrayList has to be iterate to read data only, what are the possible ways and which is the fastest?
Ans) It can be done in two ways, using for loop or using iterator of ArrayList. The first option is faster than using iterator. Because value stored in arraylist is indexed access. So while accessing the value is accessed directly as per the index.
How to sort list in reverse order?
Ans) To sort the elements of the List in the reverse natural order of the strings, get a reverse Comparator from the Collections class with reverseOrder(). Then, pass the reverse Comparator to the sort() method.
List list = new ArrayList();
Comparator comp = Collections.reverseOrder();
Collections.sort(list, comp)
How to sort list of strings - case insensitive?
Ans) using Collections.sort(list, String.CASE_INSENSITIVE_ORDER); 
2) Differences between Java and Ruby
·         Memory is managed via a garbage collector.
Differences
·         You don’t need to compile your code. You just run it directly.
·         Everything is an object, including numbers like 2 and 3.14159.
·         All member variables are private. From the outside, you access everything via methods.
·         There’s no static type checking.  Variable names are just labels. They don’t have a type associated with them.  There are no type declarations.
·         There’s no casting. Just call the methods.
·         The constructor is always named “initialize” instead of the name of the class.
·         You have “mixin’s” instead of interfaces.

·         == and equals() are handled differently in Ruby. Use == when you want to test equivalence in Ruby (equals() is Java). Use equal?() when you want to know if two objects are the same (== in Java).
3) What I did in my previous work place (what tools, testing frameworks I used, how I programmed the automation framework, Selenium, etc)
4) General QA questions such as how to deal with opening bugs, what kind of bugs were found, how do I come up with testcases
5) Writing a small program in any language for a small problem

------------------------------------------------------------------------------------------------------------------------------------------------------------------
1) Most recent experience: What I did, technologies, languages, What kind of development process was used in my team
2) Questions on Java: Really basic questions: Overriding and Overloading, Classes, objects, methods, how to install Java and set environment on a PC, Does Java5 and Java1.5 refer to the same thing?
3) UNIX / LINUX shell commands, shell programming, editors and tools to login the UNIX server and how I used those in my previous experience
4) Testing and Automation: How I came up with test cases,
 how I developed my atomation framework,
 what is the difference between Verification and Validation, 

other keywords in software testing. Given an application that needs testing,
 how would I develop my automation, i.e., Step-by-step programming solution to the problem
5) Teamwork: How I handled pressure, Deadlines, relationship between testers, developers, etc..by organising things in advance, try to finish u r work as per plan and ahead , think of this situation ahead and work accordingly, work late if needed, take help when required..communication, mutual coordination....