Sunday, January 6, 2019

Both Iterator and Iterable are interfaces in Java Collection Framework. Here are some differences:
Iterator: Iterator  is an interface that manages iteration over an Iterable. It maintains a state of where we are in the current iteration, and knows what the next element is and how to get it. See API here
Iterator lets you check if it has more elements using hasNext() and move to the next element (if any) using next().
This interface is a member of the Java Collections Framework. It has the methods hasNext(), next(), remove()
Iterable: Implementing this interface allows an object to be the target of the "for-each loop" statement. See Iterable API here.
An iterable produces iterators

Both are interfaces in Java. Here some common differences between Comparator and Comparable.
  1. Comparator in Java is defined in java.util package while Comparable interface in Java is defined in java.lang package.
  2. Comparator has the method int compare(T o1,T o2) which compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. While Comparable has method public int compareTo(T o) which returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
  3. compare method of Comparator compares its two arguments for order. compareTo method of Comparable interface compares this object with the specified object for order.
  4. Comparator has equals(Object obj) method while Comparable doesn't.
It is very frequently asked interview question for me. I was no answer as till now we know only we need drivers( like chromedriver.exe, geckodriver.exe, IEDriverServer.exe) and pass them to the System.setProperty() to launch a browser using selenium web driver. But why?
Reason:
As selenium WebDriver has no native implementation of a browser, we have to direct all the webdriver commands through a driver server (driver file).
Driver server is a standalone server which implements WebDriver's wire protocol.
Wire protocol defines a RESTful web service using JSON over HTTP and is implemented in request/response pairs of "commands" and "responses".
The wire protocol will inherit its status codes from those used by the Driver Server.
Each Driver implements Webdriver protocol and starts a server on your system.  All your tests communicate to this server to run your tests
Note: Each browser contains web browser engine. To display the web content, the web browser engine is required. There are different web browser engines and driver servers for each web browsers.


Hope this helps!!!

Friday, January 4, 2019

Difference between HashMap and ConcurrentHashMap:
  • ConcurrentHashMap is thread-safe that is the code can be accessed by single thread at a time. while HashMap is not thread-safe
  • HashMap can be synchronized by using synchronizedMap(HashMap) method. By using this method we get a HashMap object which is equivalent to the HashTable object. So every modification is performed on  Map is locked on Map object. ConcurrentHashMap is by default synchronized
  • ConcurrentHashMap does not allow NULL values . So the key can not be null in ConcurrentHashMap. While In HashMap there can only be one null key.
  • In multiple threaded environment HashMap is usually faster than ConcurrentHashMap. As only single thread can access the certain portion of the Map and thus reducing the performance. While in HashMap any number of threads can access the code at the same time.



Thursday, January 3, 2019

Java API provides foreach() method since jdk1.8v.
This method traverses each element of the collection until all elements have been Processed by the method or an exception is raised.
Exceptions thrown by the Operation are passed to the caller.
foreach() is defined as default method in Iterable interface and overiden in ArrayList and Arrays classes.
(Note: interface allows default and static keywords since jdk1.8v)
Implementation in ArraList:
ArrayList Class implements List interface extends Collection interface extends Iterable interface
 foreach() implementation in Iterable:
default void forEach(Consumer<? super T> action) {
        Objects.requireNonNull(action);
        for (T t : this) {
            action.accept(t);
        }
}

overridden method in ArrayList as below:

@Override
        @SuppressWarnings("unchecked")
        public void forEachRemaining(Consumer<? super E> consumer) {
        }

Parameter: This method takes a parameter action which represents the action to be performed for each element.
Returns: This method does not returns anything.
Exception: This method throws NullPointerException if the specified action is null.
In Java 8 using lambda expressions we can simply replace for-each loop with
elements.forEach (e -> System.out.println(e) );
Map in Java does not extends Iterable. Map itself has its own forEach method that you can use to iterate through key-value pairs. Which is not overriden.

Static is a keyword in Java, which is used for
    1. static blocks
    2. variables
    3. methods and 
    4. inner classes or nested classes
  • A static member can be accessed directly with the class name with out creating an object. 
  • The value of the  static variable is shared by all objects of a class means same set of copy available to all the objects.
  • If any variable is modified by an object those changes visible to every object. Static content doesn't belongs to any particular instance or object.
Static can not be used for Outer most class class. Why?
  1. Every class is already common to all the objects. No need to make class static to become available to all the objects
  2. A class is belongs to package level. Class can be accessed directly with <package_name.ClassName>. No need to make class as static.

Selenium Training in Realtime

Blog helps to a student or IT employee to develop or improve skills in Software Testing.

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *