Commonly Asked Java and Selenium Interview Questions
Commonly Asked Java and Selenium Interview Questions
The Java Class Loader is a part of the Java Runtime Environment that dynamically
loads Java classes into the Java Virtual Machine.
Wrapper classes provide a way to use primitive data types ( int, boolean,
etc..) as objects.
The objects are necessary if we wish to modify the arguments passed into the method
(because primitive types are passed by value). The classes in java. util package handles
only objects and hence wrapper classes help in this case also
Integer we can reverse number or rotate it left or right using reverse(), rotateLeft() and
rotateRight() respectively.
The class must be declared as final (So that child classes can’t be created)
Data members in the class must be declared as final (So that we can’t change
the value of it after object creation)
A parameterized constructor
Getter method for all the variables in it
No setters(To not have the option to change the value of the instance variable)
What are OOPS concepts? Explain them. What all OOPS concepts
have you used in your framework?
Data abstraction is the process of hiding certain details and showing only
essential information to the user.
The Object class, in the java.lang package, sits at the top of the class hierarchy tree. Every class is a
descendant, direct or indirect, of the Object class
Equals() method verify if both objects are equal wrt the data but the object class
returns false
hashcode() – Returns a unique integer value for the object in runtime. By default,
integer value is mostly derived from memory address of the object in heap
with the object memory address and the calculation in the Hashcode methode
hash code is returned its an it.
// Upcasting Vs Downcasting
// Parent class
class Parent {
String name;
void method()
}
// Child class
int id;
// child class
@Override
void method()
// Driver code
// Upcasting
Parent p = new Child();
p.name = "GeeksforGeeks";
// p.id = 1;
System.out.println(p.name);
p.method();
// Downcasting Explicitly
Child c = (Child)p;
c.id = 1;
System.out.println(c.name);
System.out.println(c.id);
c.method();
No, We can not override private method in Java, just like we can not override static method in
Java. Like static methods, private method in Java is also bonded during compile time using static
binding by Type information and doesn't depends on what kind of object a particular reference
variable is holding. Since method overriding works on dynamic binding, its not possible to
override private method in Java. private methods are not even visible to Child class, they are
only visible and accessible in the class on which they are declared. private keyword provides
highest level of Encapsulation in Java. Though you can hide private method in Java by declaring
another private method with same name and different method signature.
return types can be different, but they can only restrict the type used in the super class
because of the Liskov Substitution Principle.
Association of method call to the method body is known as binding. There are
two types of binding: Static Binding that happens at compile time
and Dynamic Binding that happens at runtime.
https://beginnersbook.com/2013/04/java-static-dynamic-binding/
Can a overriding method throw new or broader checked
exception?
The overriding method must NOT throw checked exceptions that are new or broader
than those declared by the overridden method. For example, a method that declares a
FileNotFoundException cannot be overridden by a method that declares a
SQLException, Exception, or any other non-runtime exception unless it's a subclass of
FileNotFoundException.
Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their
corresponding object wrapper classes. For example, converting an int to an Integer, a double to
a Double, and so on. If the conversion goes the other way, this is called unboxing.
Abstract class and interface both are used to achieve abstraction where we can declare
the abstract methods. Abstract class and interface both can't be instantiated.
1) Abstract class can have abstract and Interface can have only abstract methods.
non-abstract methods. Since Java 8, it can have default and static
methods also.
3) Abstract class can have final, non- Interface has only static and final variables.
final, static and non-static variables.
4) Abstract class can provide the Interface can't provide the implementation
implementation of interface. of abstract class.
6) An abstract class can extend another An interface can extend another Java interface
Java class and implement multiple Java only.
interfaces.
8) A Java abstract class can have class Members of a Java interface are public by
members like private, protected, etc. default.
9)Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }
Yes, when we define a class to be an Abstract Class it cannot be instantiated but that
does not mean an Abstract class cannot have a constructor. Each abstract class must
have a concrete subclass which will implement the abstract methods of that abstract
class.
es, you can declare abstract class without defining an abstract method in it. Once you
declare a class abstract it indicates that the class is incomplete and, you cannot instantiate
it
1. class Vehicle {
2.
3. public Vehicle() {
4. System.out.println("I am the super vehicle");
5. }
6. }
7.
8. class FourWheeler extends Vehicle {
9. public FourWheeler() {
10. System.out.println("I am a car or a truck or whatever 4 wheel has");
11. }
12. }
13.
14. class Car extends FourWheeler{
15. public Car() {
16. System.out.println("I am a car");
17. }
18. }
19.
20. public class Demo{
21. public static void main(String[] args) {
22. Car c = new Car();
23. }
24. }
25. I am the super vehicle
26. I am a car or a truck or whatever 4 wheel has
27. I am a car
https://www.programiz.com/java-programming/
instanceof#:~:text=In%20Java%2C%20the%20instanceof
%20keyword,discussed%20later%20in%20this%20tutorial).
There are two types of modifiers in Java: access modifiers and non-access modifiers.
The access modifiers in Java specifies the accessibility or scope of a field, method,
constructor, or class. We can change the access level of fields, constructors, methods,
and class by applying the access modifier on it
1. Private: The access level of a private modifier is only within the class. It cannot
be accessed from outside the class.
2. Default: The access level of a default modifier is only within the package. It
cannot be accessed from outside the package. If you do not specify any access
level, it will be the default.
3. Protected: The access level of a protected modifier is within the package and
outside the package through child class. If you do not make the child class, it
cannot be accessed from outside the package.
4. Public: The access level of a public modifier is everywhere. It can be accessed
from within the class, outside the class, within the package and outside the
packag
https://www.javatpoint.com/access-modifiers
https://www.geeksforgeeks.org/final-keyword-java/#:~:text=First
%20of%20all%2C%20final%20is,contexts%20where%20final
%20is%20used.&text=When%20a%20variable%20is
%20declared,must%20initialize%20a%20final%20variable.
https://www.geeksforgeeks.org/g-fact-24-finalfinally-and-finalize-
in-java/?ref=rp
,equal = True
.euqla – true and == also true since the object will created in
string constant pool
true
false
true
22. }
What will be the output of below code?
hello
How many methods of String class have you used? Name them
with example
https://www.seleniumeasy.com/java-tutorials/string-examples-
using-selenium-webdriver
https://www.geeksforgeeks.org/string-vs-stringbuilder-vs-
stringbuffer-in-java/
Strings are stored on the heap area in a separate memory location known
as String Constant pool. String constant pool: It is a separate block of memory where all
the String variables are held.
Once string object is created its data or state can't be changed but a new string object is
created.
https://www.javatpoint.com/immutable-string#:~:text=In%20java
%2C%20string%20objects%20are,new%20string%20object%20is
%20created.&text=println(s)%3B%2F%2Fwill%20print%20Sachin
%20because%20strings%20are%20immutable%20objects
javamadesoeasy.com/2015/06/differences-between-
instance.html#:~:text=static%20blocks%20executes%20when
%20class,be%20used%20in%20static%20blocks.
Instance variables have default values. For numbers, the default value is 0, for Booleans it is
false, and for object references it is null. Values can be assigned during the declaration or
within the constructor.
There is no default value for local variables, so local variables should be declared and an
initial value should be assigned before the first use.
tutorialspoint.com/java/java_variable_types.htm#:~:text=Local
%20variables%20are%20visible%20only,assigned%20before
%20the%20first%20use.
In Java, static keyword is mainly used for memory management. It can be used
with variables, methods, blocks and nested classes. It is a keyword which is used to share
the same variable or method of a given class. Basically, static is used for a constant variable
or a method that is same for every instance of a class.
https://www.edureka.co/blog/static-keyword-in-java/#StaticBlock
When you declare a variable as static, then a single copy of the variable is created and
divided among all objects at the class level. Static variables are, essentially, global variables.
Basically, all the instances of the class share the same static variable. Static variables can
be created at class-level only.
non-static methods can access any static method and static variable also, without using
the object of the class. In static method, the method can only access
only static data members and static methods of another class or same class but cannot
access non-static methods and variables
https://www.geeksforgeeks.org/difference-between-static-and-non-static-method-in-java/
#:~:text=before%20method%20name.-,non%2Dstatic%20methods%20can%20access
%20any%20static%20method%20and%20static,the%20object%20of%20the
%20class.&text=members%20and%20methods-,In%20static%20method%2C%20the
%20method%20can%20only%20access%20only%20static,non%2Dstatic%20methods
%20and%20variables.
Static variables are class variable not instance or local variable . that is why we can use
static variable in non static method also.
https://study.com/academy/lesson/static-vs-non-static-methods-
in-java.html#:~:text=To%20create%20a%20static
%20method,design%20from%20the%20original%20dress.
A static method belongs to the class, and you do not have to create an instance of the
class to access the static method.
1. class Calc {
3. return x * y;
4. }
7. System.out.println(ans);
8. }
9. }
while loop check condition before iteration of the loop. On the other hand, the do-while loop
verifies the condition after the execution of the statements inside the loop
Switch case statements are used to execute only specific case statements based on the
switch expression. If we do not use break statement at the end of each case,
program will execute all consecutive case statements until it finds next break statement or
till the end of switch case block.
A 'switch' statement should have 'default' as the last label. Adding a 'default' label at the
end of every 'switch' statement makes the code clearer and guarantees that any
possible case where none of the labels matches the value of the control variable will be
handled.
Can your switch statement accept long, double or float data type?
The switch statement doesn't accept arguments of type long, float, double,boolean or
any object besides String
https://docstore.mik.ua/orelly/java/langref/
ch09_04.htm#:~:text=The%20possible%20exceptions%20in
%20a,immediate%20subclasses%3A%20Exception%20and
%20Error.
Unchecked are the exceptions that are not checked at compiled time
https://www.geeksforgeeks.org/checked-vs-unchecked-
exceptions-in-java/#:~:text=In%20Java%2C%20there%20are
%20two,are%20checked%20at%20compile%20time.&text=It
%20is%20up%20to%20the,else%20under%20throwable%20is
%20checked.
An Error "indicates serious problems that a reasonable application should not try to catch."
An Exception "indicates conditions that a reasonable application might want to catch
https://stackoverflow.com/questions/5813614/what-is-difference-
between-errors-and-exceptions#:~:text=An%20Error
%20%22indicates%20serious%20problems,should%20not%20try
%20to%20catch.%22&text=An%20Exception%20%22indicates
%20conditions%20that,their%20subclasses%20are
%20unchecked%20exceptions.&text=On%20the%20other
%20hand%20we%20have%20unchecked%20exceptions.
Throw is a keyword which is used to throw an exception explicitly in the program inside a
function or inside a block of code. Throws is a keyword used in the method signature used
to declare an exception which might get thrown by the function while executing the code.
https://www.tutorialspoint.com/difference-between-throw-and-
throws-in-java#:~:text=Throw%20is%20a%20keyword
%20which,function%20while%20executing%20the%20code.
Yes, we can have try without catch block by using finally block. You can
use try with finally. As you know finally block always executes even if you have exception
or return statement in try block except in case of System.
https://java2blog.com/can-we-have-try-without-catch-block-in-
java/#:~:text=Yes%2C%20we%20can%20have%20try,except
%20in%20case%20of%20System.
How to handle multi level exceptions?
A try block can be followed by one or more catch blocks. Each catch block must contain a
different exception handler. So, if you have to perform different tasks at the occurrence
of different exceptions, use java multi-catch block.
https://www.javatpoint.com/multiple-catch-block-in-java
https://www.geeksforgeeks.org/multicatch-in-java/
Unreachable catch block for FileNotFoundException. It is already handled by the catch block for
IOException
https://stackify.com/what-is-java-garbage-collection/#:~:text=A
%20Definition%20of%20Java%20Garbage,programs%20perform
%20automatic%20memory%20management.&text=When
%20Java%20programs%20run%20on,will%20no%20longer%20be
%20needed.
https://www.geeksforgeeks.org/garbage-collection-java/
1. Using System.gc() method : System class contain static method gc() for requesting
JVM to run Garbage Collector.
2. Using Runtime.getRuntime().gc() method : Runtime class allows the application to
interface with the JVM in which the application is running. Hence by using its gc()
method, we can request JVM to run Garbage Collector.
https://www.geeksforgeeks.org/garbage-collection-java/
1. public class GC {
2.
3. public static void main(String[] args) {
4.
5. GC gc1= new GC();
6. GC gc2 = new GC();
7. GC gc3 = new GC();
8.
9. gc1 = null;
10. }
11.
12. }
https://www.geeksforgeeks.org/different-ways-reading-text-file-
java/ - Read
https://www.geeksforgeeks.org/file-handling-java-using-filewriter-
filereader/ - Write
http://tutorials.jenkov.com/java-functional-programming/
functional-interfaces.html#:~:text=A%20functional%20interface
%20in%20Java,to%20the%20single%20unimplemented
%20method.
https://www.geeksforgeeks.org/functional-interfaces-java/
#:~:text=They%20can%20have%20only%20one,the
%20examples%20of%20functional%20interfaces.
A functional interface is an interface that contains only one abstract method. They can have
only one functionality to exhibit. From Java 8 onwards, lambda expressions can be used to
represent the instance of a functional interface. A functional interface can have any number
of default methods. Runnable, ActionListener, Comparable are some of the examples of
functional interfaces.
Before Java 8, we had to create anonymous inner class objects or implement these
interfaces.
https://www.geeksforgeeks.org/functional-interfaces-java/
#:~:text=They%20can%20have%20only%20one,the
%20examples%20of%20functional%20interfaces.
An empty interface in Java is known as a marker interface i.e. it does not contain any
methods or fields by implementing these interfaces a class will exhibit a special behavior
with respect to the interface implemented. java.
https://www.tutorialspoint.com/marker-interface-in-java-
programming#:~:text=An%20empty%20interface%20in
%20Java,java.
Multithreading is a Java feature that allows concurrent execution of two or more parts of a
program for maximum utilization of CPU. Each part of such program is called a thread. So,
threads are light-weight processes within a process.
Process
Process means any program is in execution. Process control block controls the operation of
any process.
https://www.edureka.co/blog/java-thread/#:~:text=A%20thread
%20is%20actually%20a,a%20separate%20path%20of
%20execution.
https://www.geeksforgeeks.org/difference-between-process-and-
thread/
https://medium.com/@bharatkulratan/difference-between-
runnable-and-thread-in-java-aacced9dca44#:~:text=Runnable
%20is%20an%20interface%20which,t%20create%20a%20new
%20thread.
How to get today’s date using date class? How to add days in
today’s date?
https://howtodoinjava.com/java/date-time/add-days-to-date-
localdatetime/
import java.time.LocalDate;
import java.time.Month;
The getYear() method returns an integer representing the year filed in the
current LocalDate object.
The getMonth() method returns an object of the java.timeMonth class
representing the month in the LocalDate object.
The getDaYofMonth() method returns an integer representing the day in the
LocalDate object.
https://www.tutorialspoint.com/how-to-get-current-day-month-
and-year-in-java-8
https://www.geeksforgeeks.org/stream-in-java/
#:~:text=Introduced%20in%20Java%208%2C%20the,to
%20produce%20the%20desired%20result.&text=Streams
%20don't%20change%20the,as%20per%20the%20pipelined
%20methods.
https://www.geeksforgeeks.org/default-methods-java/
What is the difference between Collections and Collection?
The differences between the Collection and Collections are given below.
https://www.javatpoint.com/java-collections-interview-
questions#:~:text=14)%20What%20is%20the%20difference
%20between%20Collection%20and%20Collections%3F&text=The
%20Collection%20is%20an%20interface,and%20synchronize
%20the%20collection%20elements.
https://www.geeksforgeeks.org/collections-in-java-2/
What are the sub interfaces and sub classes of List, Set and Map
interface?
https://www.javatpoint.com/collections-in-java
https://www.javatpoint.com/difference-between-arraylist-and-
linkedlist
ArrayList is faster than LinkedList if I randomly access its elements. ... ArrayList has
direct references to every element in the list, so it can get the n-th element in constant
time. LinkedList has to traverse the list from the beginning to get to the n-th
element. LinkedList is faster than ArrayList for deletion
https://www.javatpoint.com/difference-between-arraylist-and-
linkedlist
https://www.geeksforgeeks.org/difference-between-singly-linked-
list-and-doubly-linked-list/#:~:text=Introduction%20to%20Doubly
%20linked%20list,there%20in%20singly%20linked
%20list.&text=SLL%20has%20nodes%20with%20only%20a
%20data%20field%20and%20next%20link%20field.&text=The
%20DLL%20occupies%20more%20memory%20than%20SLL
%20as%20it%20has%203%20fields.
https://www.geeksforgeeks.org/linked-list-in-java/
https://www.geeksforgeeks.org/difference-between-stack-and-
queue-data-structures/#:~:text=Stack%20A%20stack%20is
%20a,the%20list%2C%20called%20the%20top.&text=The
%20insertion%20of%20an%20element%20in%20a%20queue
%20is%20called,is%20called%20a%20dequeue%20operation.
stack A stack is a linear data structure in which elements can be inserted and deleted only
from one side of the list, called the top. LIFO
A queue is a linear data structure in which elements can be inserted only from one side of
the list called rear, and the elements can be deleted only from the other side called
the front. FIFO
HashMap is a part of Java’s collection since Java 1.2. It provides the basic implementation
of the Map interface of Java. It stores the data in (Key, Value) pairs.
https://www.geeksforgeeks.org/java-util-hashmap-in-java-with-
examples/
https://www.geeksforgeeks.org/arraylist-array-conversion-java-
toarray-methods/
https://www.geeksforgeeks.org/conversion-of-array-to-arraylist-in-
java/?ref=rp
Java Set is a part of java.util package and extends java.util.Collection interface. It does not
allow the use of duplicate elements and at max can accommodate only one null element.
https://www.geeksforgeeks.org/program-to-convert-set-to-list-in-
java/
https://www.geeksforgeeks.org/traverse-through-a-hashset-in-
java/ - Hash set
https://www.geeksforgeeks.org/traverse-through-a-hashmap-in-
java/?ref=rp – Has Map
https://www.geeksforgeeks.org/sortedset-java-examples/
https://www.geeksforgeeks.org/sortedmap-java-examples/
https://www.geeksforgeeks.org/linkedhashset-in-java-with-
examples/
https://www.geeksforgeeks.org/linkedhashmap-class-java-
examples/
https://www.geeksforgeeks.org/treeset-in-java-with-examples/
#:~:text=TreeSet%20is%20one%20of%20the,an%20explicit
%20comparator%20is%20provided.
https://www.geeksforgeeks.org/treemap-in-java/
https://www.geeksforgeeks.org/differences-between-hashmap-
and-hashtable-in-java/
https://www.techiedelight.com/java-program-iterate-list-reverse-
order/
https://www.tutorialspoint.com/iterate-through-a-linkedlist-in-
reverse-direction-using-a-listiterator-in-java#:~:text=A
%20ListIterator%20can%20be%20used,reverse%20direction
%20and%20false%20otherwise.
https://www.javatpoint.com/difference-between-comparable-and-
comparator
https://www.javatpoint.com/palindrome-program-in-java
https://www.javatpoint.com/program-to-find-the-duplicate-
characters-in-a-string
What are the challenges you faced in automation? What are the
challenges you faced while working with IE browser?
How to read data from dynamic web table? How to fetch data
from last raw of dynamic web table?
How do you handle Alert? Can you write a method to check if alert
exists?
signOnImage.sendKeys(Keys.RETURN);
2.1
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", signOnImage);
2.2
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementsByName('login')[0].click()");
3.1
Actions actions = new Actions(driver);
actions.click(signOnImage).perform();
3.2
Actions actions = new Actions(driver);
actions.moveToElement(signOnImage).click().perform();
3.3
Actions actions = new Actions(driver);
actions.clickAndHold(signOnImage).release().perform();
3.4
Actions actions = new Actions(driver);
actions.sendKeys(signOnImage, Keys.RETURN).perform();
Send Keys
WebElement inputField = driver.findElement(By.xpath(".//div/input[starts-with(@id,'4')
and @class=' input' and @type='text' and @placeholder='']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].value='text';", inputField);
8+ years experience in test strategy, planning, designing test cases on Data Management platform and data
migration.
Should be hands-on on QuerySurge tool and Shell Scripting.
Previously worked on data migration projects and ETL related testing. DataStage knowledge will be an
advantage
Preferred Technical and Professional Expertise