SDET INTERVIEW EXAM QUESTIONS WITH
ACCURATE ANSWERS
Are JavaScript and Java the same? - ANSWER • Java is an OOP programming
language while Java Script is an OOP scripting language.
• Java creates applications that run in a virtual machine or browser while
JavaScript code was run on a browser only until recently. JS became cross-
functional thanks to NodeJS
• Java code needs to be compiled while JavaScript code are all in text.
• They require different plug-ins.
What is the method? - ANSWER • Collection of statements that are grouped
together to perform an operation.
• A method is a set of code which is referred to by name and can be called
(invoked) at any point in a program simply by utilizing the method's name.
What is the constructor? - ANSWER • A constructor in Java is a special
method that is used to initialize objects. The constructor is called when an
object of a class is created.
• Each time an object is created using new() keyword at least one constructor (it
could be default constructor) is invoked to assign initial values to the data
members of the same class.
What's abstraction? Please briefly explain what are the differences between
abstract classes and interfaces? - ANSWER In OOP, abstraction is a process of
hiding the implementation details from the user, only the functionality will be
provided to the user. In Java, abstraction is achieved using Abstract classes and
interfaces.
Main difference is methods of a Java interface are implicitly abstract and cannot
have implementations. A Java abstract class can have instance methods that
implements a default behavior. A class that is declared with abstract keyword, is
known as abstract class. It can have abstract and non--abstract methods.
,An Interface is a blueprint of a class. It is a template and it is declared with
interface keyword. It can have abstract methods,default methods, static methods
and public final static variables. When we want to use Abstract class, we use
"extend" keyword.
When we want to use Interface, we use "implement" keyword.
Abstract class and interface both are used to achieve abstraction. Both cannot be
instantiated; we cannot create an object.
Do you know JavaScript? - ANSWER I can get the job done with the simple
JavaScript comments. I don't know deep knowledge but I used before scrolling
up/down, scrolling to elements, clicking some certain elements.
Can you tell some Exception Classes that you are familiar with? - ANSWER
ArrayIndexOutOfBoundsException : It is thrown to indicate that an array has
been accessed with an illegal index. The index is either negative or greater than
or equal to the size of the array.? StringIndexOutOfBoundsException : It is
thrown by String class methods to indicate that an index is either negative than
the size of the string?
NoSuchElementException : It is thrown to indicate that there are no more
elements left in the enumeration.
What is Compile Error, Runtime Error and Runtime Exception? What is the
difference between Error and Exception? - ANSWER Compile Error: syntax or
semantics issue, get detected by the compiler and get fixed at the time of code
development.
Runtime Error: error encountered during the execution of code at runtime, not
get detected by compiler, identified at the time of code execution, get fixed once
code get executed and errors get identified.
RuntimeException: identified at the time of code execution also, but is a direct
subclass of Exception. RuntimeException is the superclass of all the exceptions
which may be thrown for many reasons during expression evaluation, but from
which recovery may still be possible.
,An Error indicates serious problems that a reasonable application should not try
to catch. It is used in situations where there is nothing programmer can do about
it. (Ex: StackOverFlowError, OutOfMemoryError).
An Exception indicates conditions that a reasonable application might want to
catch. It is used when a programmer can handle the exception.
What is Checked and Unchecked Exceptions? - ANSWER 1)
Checked=exceptions that are checked at compile time. If some code within a
method throws a checked exception, then the method must either handle the
exception or it must specify the exception using throws keyword.
Example of checked exceptions are: ClassNotFoundException, SQLException,
FileNotFoundException, IOException(input/output exception, like accessing a
network file without Internet connection)
2) Unchecked= exceptions that are not checked at compiled time. In Java
exceptions under Error and RuntimeException classes are unchecked
exceptions, everything else under throwable is checked.
Example of unchecked exceptions are : ArithmeticException(divide by zero),
ArrayStoreException(store the wrong type of object into an array of objects),
ClassCastException(cast an Object of one data type to another)
What is Throws? - ANSWER Throws clause informs the compiler that a
method throws one or more exceptions. To declare throws it is written next to
method. Whoever calls this method responsible for handling the exception.
Can you create multiple catch block in Java? - ANSWER Yes we can. But we
should handle more specialized exception classes before general exception
classes.
What is the purpose of finally block? - ANSWER Finally block is always
executed(even when an exception is thrown). So if we want some code to be
always executed we can move it finally block. It cannot be executed only:
-If an exception is thrown in finally.
-If JVM crashes
Can you explain the hierarcy of exception handling classes? - ANSWER
, Throw clauses? - ANSWER It can be used to throw an exception manually. We
can throw either checked and Unchecked Exception
throw new Exception Type(MessageString)
What is the differences between Arrays and Collections? - ANSWER 1.Size:
Arrays are fixed in size i.e once the array with the specific size is declared then
we can't alter its size afterward. The collection is dynamic.
2. Memory Consumption: Arrays due to fast execution consumes more memory
and has better performance. Collections, on the other hand, consume less
memory but also have low performance as compared to Arrays.
3. Data type: Arrays can hold only the same type of data in its collection i.e only
homogeneous data types elements are allowed in case of arrays. Collection, on
the other hand, can hold both homogeneous and heterogeneous elements.
4. Primitives storage: Arrays can hold both object and primitive type data. On
the other hand, collection can hold only object types but not the primitive type
of data.
5. Performance: Arrays due to its storage and internal implementation better in
performance. Collection on the other hand with respect to performance is not
recommended to use.
List and Set What is the differences between List and Set? - ANSWER 1) List
is an ordered collection it maintains the insertion order, which means upon
displaying the list content it will display the elements in the same order in which
they got inserted into the list. Set is an unordered collection, it doesn't maintain
any order. There are few implementations of Set which maintains the order such
as LinkedHashSet (It maintains the elements in insertion order).
2) List allows duplicates while Set doesn't allow duplicate elements. All the
elements of a Set should be unique if you try to insert the duplicate element in
Set it would replace the existing value.
3) List implementations: ArrayList, LinkedList etc.Set implementations:
HashSet, LinkedHashSet, TreeSet etc.
4) List allows any number of null values. Set can have only a single null value
at most.
5) ListIterator can be used to traverse a List in both the directions(forward and
backward) However ListIterator can not be used to traverse a Set. We can use
Iterator (It works with List too) to traverse a Set.
6) List interface has one legacy class(kept from old versions of Java) called
Vector whereas Set interface does not have any legacy class.
ACCURATE ANSWERS
Are JavaScript and Java the same? - ANSWER • Java is an OOP programming
language while Java Script is an OOP scripting language.
• Java creates applications that run in a virtual machine or browser while
JavaScript code was run on a browser only until recently. JS became cross-
functional thanks to NodeJS
• Java code needs to be compiled while JavaScript code are all in text.
• They require different plug-ins.
What is the method? - ANSWER • Collection of statements that are grouped
together to perform an operation.
• A method is a set of code which is referred to by name and can be called
(invoked) at any point in a program simply by utilizing the method's name.
What is the constructor? - ANSWER • A constructor in Java is a special
method that is used to initialize objects. The constructor is called when an
object of a class is created.
• Each time an object is created using new() keyword at least one constructor (it
could be default constructor) is invoked to assign initial values to the data
members of the same class.
What's abstraction? Please briefly explain what are the differences between
abstract classes and interfaces? - ANSWER In OOP, abstraction is a process of
hiding the implementation details from the user, only the functionality will be
provided to the user. In Java, abstraction is achieved using Abstract classes and
interfaces.
Main difference is methods of a Java interface are implicitly abstract and cannot
have implementations. A Java abstract class can have instance methods that
implements a default behavior. A class that is declared with abstract keyword, is
known as abstract class. It can have abstract and non--abstract methods.
,An Interface is a blueprint of a class. It is a template and it is declared with
interface keyword. It can have abstract methods,default methods, static methods
and public final static variables. When we want to use Abstract class, we use
"extend" keyword.
When we want to use Interface, we use "implement" keyword.
Abstract class and interface both are used to achieve abstraction. Both cannot be
instantiated; we cannot create an object.
Do you know JavaScript? - ANSWER I can get the job done with the simple
JavaScript comments. I don't know deep knowledge but I used before scrolling
up/down, scrolling to elements, clicking some certain elements.
Can you tell some Exception Classes that you are familiar with? - ANSWER
ArrayIndexOutOfBoundsException : It is thrown to indicate that an array has
been accessed with an illegal index. The index is either negative or greater than
or equal to the size of the array.? StringIndexOutOfBoundsException : It is
thrown by String class methods to indicate that an index is either negative than
the size of the string?
NoSuchElementException : It is thrown to indicate that there are no more
elements left in the enumeration.
What is Compile Error, Runtime Error and Runtime Exception? What is the
difference between Error and Exception? - ANSWER Compile Error: syntax or
semantics issue, get detected by the compiler and get fixed at the time of code
development.
Runtime Error: error encountered during the execution of code at runtime, not
get detected by compiler, identified at the time of code execution, get fixed once
code get executed and errors get identified.
RuntimeException: identified at the time of code execution also, but is a direct
subclass of Exception. RuntimeException is the superclass of all the exceptions
which may be thrown for many reasons during expression evaluation, but from
which recovery may still be possible.
,An Error indicates serious problems that a reasonable application should not try
to catch. It is used in situations where there is nothing programmer can do about
it. (Ex: StackOverFlowError, OutOfMemoryError).
An Exception indicates conditions that a reasonable application might want to
catch. It is used when a programmer can handle the exception.
What is Checked and Unchecked Exceptions? - ANSWER 1)
Checked=exceptions that are checked at compile time. If some code within a
method throws a checked exception, then the method must either handle the
exception or it must specify the exception using throws keyword.
Example of checked exceptions are: ClassNotFoundException, SQLException,
FileNotFoundException, IOException(input/output exception, like accessing a
network file without Internet connection)
2) Unchecked= exceptions that are not checked at compiled time. In Java
exceptions under Error and RuntimeException classes are unchecked
exceptions, everything else under throwable is checked.
Example of unchecked exceptions are : ArithmeticException(divide by zero),
ArrayStoreException(store the wrong type of object into an array of objects),
ClassCastException(cast an Object of one data type to another)
What is Throws? - ANSWER Throws clause informs the compiler that a
method throws one or more exceptions. To declare throws it is written next to
method. Whoever calls this method responsible for handling the exception.
Can you create multiple catch block in Java? - ANSWER Yes we can. But we
should handle more specialized exception classes before general exception
classes.
What is the purpose of finally block? - ANSWER Finally block is always
executed(even when an exception is thrown). So if we want some code to be
always executed we can move it finally block. It cannot be executed only:
-If an exception is thrown in finally.
-If JVM crashes
Can you explain the hierarcy of exception handling classes? - ANSWER
, Throw clauses? - ANSWER It can be used to throw an exception manually. We
can throw either checked and Unchecked Exception
throw new Exception Type(MessageString)
What is the differences between Arrays and Collections? - ANSWER 1.Size:
Arrays are fixed in size i.e once the array with the specific size is declared then
we can't alter its size afterward. The collection is dynamic.
2. Memory Consumption: Arrays due to fast execution consumes more memory
and has better performance. Collections, on the other hand, consume less
memory but also have low performance as compared to Arrays.
3. Data type: Arrays can hold only the same type of data in its collection i.e only
homogeneous data types elements are allowed in case of arrays. Collection, on
the other hand, can hold both homogeneous and heterogeneous elements.
4. Primitives storage: Arrays can hold both object and primitive type data. On
the other hand, collection can hold only object types but not the primitive type
of data.
5. Performance: Arrays due to its storage and internal implementation better in
performance. Collection on the other hand with respect to performance is not
recommended to use.
List and Set What is the differences between List and Set? - ANSWER 1) List
is an ordered collection it maintains the insertion order, which means upon
displaying the list content it will display the elements in the same order in which
they got inserted into the list. Set is an unordered collection, it doesn't maintain
any order. There are few implementations of Set which maintains the order such
as LinkedHashSet (It maintains the elements in insertion order).
2) List allows duplicates while Set doesn't allow duplicate elements. All the
elements of a Set should be unique if you try to insert the duplicate element in
Set it would replace the existing value.
3) List implementations: ArrayList, LinkedList etc.Set implementations:
HashSet, LinkedHashSet, TreeSet etc.
4) List allows any number of null values. Set can have only a single null value
at most.
5) ListIterator can be used to traverse a List in both the directions(forward and
backward) However ListIterator can not be used to traverse a Set. We can use
Iterator (It works with List too) to traverse a Set.
6) List interface has one legacy class(kept from old versions of Java) called
Vector whereas Set interface does not have any legacy class.