Top 10 JAVA technical interview questions for QA testers

If you’re preparing for a technical interview for a Quality Assurance (QA) Tester position that involves Java, you might be wondering what types of questions you can expect. The Top 10 JAVA technical interview questions for QA testers article is designed to help you prepare for your upcoming interview.

Contents

1.What is a Exception and what are types of exceptions in JAVA ?

Exception: Exception is a issue or problem that occurs during normal execution of a program which in turn disturbs the flow of execution of program’s instructions.

Types of Exceptions in JAVA :

  1. Checked Exceptions
  2. Un-Checked Exceptions

Checked Exceptions: Checked exceptions are those kind of exceptions which are checked for during compile time . These exceptions have to be handled in the method using a try and catch block or using the throws keyword in the method signature. Again , these can be classified into partially and fully checked exceptions. Some of the common examples of checked exceptions are IOExecption , Interrupted exception.

Un-Checked Exceptions: Unchecked exceptions are those kind of exceptions which are checked for during run time. In JAVA , the exceptions in Error and Runtime Exception classes are considered to un checked exceptions. Some of the common examples of un checked exceptions are Arithmetic , Array Out of Index exceptions.

2. Explain the difference and usage of the keywords Final , Finally and Finalize in JAVA?

Final: In Java, ‘final’ reserved keyword is used with variables ,methods and classes.

If a variable is declared with the keyword final it becomes a unchangeable variable or constant

If a method is declared with final variable this method cannot be overridden ,and

If a class is declared with final variable this class cannot be inherited.

Finally: In Java, the ‘finally’ is a reserved keyword is used in conjunction with try-catch blocks to define a block of code that will be executed regardless of whether an exception is thrown or not. The finally block is guaranteed to execute, even if an exception is thrown, a return statement is encountered, or the thread is interrupted. We can have a try block along with finally without catch block.

 Finalize: In Java, the finalize() method is a special method that is called by the garbage collector before an object is garbage collected. The finalize() method can be used to perform any necessary cleanup before the object is destroyed. But default this method is protected and does not nothing but can be overridden and used according to our purpose.

3. What is the difference between an abstract class and Interface?

Abstract Class: Abstract class is a type of class which is declared with the keyword abstract. This class can have both abstract and non-abstract methods. In Order to use the abstract class it needs to be inherited to child class and all the abstract methods needs to be implemented. Abstract classes cannot be instantiated. They provide partial level of abstraction.

Interface: An interface in the Java is an abstract type that is used to declare a behavior that classes must implement. All the methods in Interface are completely abstract. Using the implements keyword an interface can be implemented and used in a class. Interfaces cannot be instantiated as well. They provide complete level of abstraction.

4. What is difference between method overloading and method overriding ?

Method Overloading  and Method Overriding basically implement different kinds of polymorphisms . Method Overloading helps in implementing the compile time polymorphism and Method Overriding helps in implementing the run time polymorphism.

Method Overloading: Method Overloading in java is a feature by which we can have number of methods with same name but different signature i.e. either having different number of parameters or by changing the data types of parameters.

Method Overriding: Method Overriding in java is a feature by which we have different implementation for the same method in child class which already has its implementation in parent class.

5.Exlpain the OOPS Concepts in JAVA?

There are 4 main pillars of Object Oriented programming in JAVA. They are:

  1. Inheritance: Inheritance is a important pillar of Object oriented programming . It is a concept where in a new class is created by acquiring the properties of a existing class. The class which is getting inherited is called the parent class and the class which inherits is called the child class.
  2. Encapsulation: Encapsulation in Java is a process of wrapping code and data together into a single unit. This can be achieved by using access modifiers.
  3. Abstraction: Abstraction is a concept of Object oriented programming by which only the relevant information is reveled to the outside world. This can be achieved by using access modifiers.
  4. Polymorphism: Polymorphism is a concept of Object oriented programming by which a single action can be done in many forms . There are two types of Polymorphism namely compile time(method overloading ) and run time (method overriding).

6.Explain public static void main (String [] args) which is commonly used in a JAVA program?

Following is the explanation of components for the above program:

public – public is a access modifier which specifies to what level this method is accessible across the project. ‘public’ access modifier states that this method can be across the classes.

static – static is a keyword in JAVA which states that whether this belongs to a particular class or not. This method main() is made static so that this method can be called without creating a object. Else JVM will throw a exception stating that main() method is called even before creating a object.

void- void is a return type in JAVA which states that the main() method does not return anything.

main- It stands for the name of the method.

String[] args – It states the parameters that are being passed to the main() method from command line

The main() method is the starting point of any program . It is the point from where the execution of program starts.

7.What is a constructor and what is their use?

Constructor is a special method in java that has the same name as of the class but does not have a return type. They are used initialize a object. Usually when a object is created a constructor is called.

Some important points to be noted about constructor:

  1.  If we do not create a constructor for a class by default java provides a constructor for us.
  2. There can be private constructors , these type of constructors only allow initialization of object inside the class.
  3. Constructors can be overloaded , Based on the arguments that we pass the specific constructor is called.
  4. Constructors cannot be static , final , abstract or synchronized.

8.What is Inheritance and what are the types of inheritances?

Inheritance: Inheritance is a important pillar of Object oriented programming . It is a concept where in a new class is created by acquiring the properties of a existing class. The class which is getting inherited is called the parent class and the class which inherits is called the child class. Inheritance helps in reusability of code. A simple analogy of inheritance is a relationship between a father and his son.

There are different types of inheritances in JAVA as mentioned below:

  1. Single-level inheritance
  2. Multi-level Inheritance
  3. Hierarchical Inheritance
  4. Hybrid Inheritance

It should be noted that in JAVA Multiple inheritance is not possible . In order have multiple inheritance we need use interfaces for that.

9.What are the different Access modifiers are there in JAVA?

Access modifiers also known as access specifiers are used to define the scope or visibility or accessibility of a data member in java . These data members can be class, method, variable or constructor. Access modifiers help us implement the encapsulation concept.

JAVA has 4 different types of access  modifiers for its data members:

  1.  default: If a access modifier is not mentioned it is considered to be having default as the access modifier. This provides a package level scope for its data member.
  2.  public: Whenever the access modifier is mentioned as public it provides access within and outside the class , within and outside the package . it is the most commonly used access modifier.
  3. private:  Whenever the access modifier is mentioned as private it provides access within the class only. Any data member cannot be accessed outside the class.
  4. protected: Whenever the access modifier is mentioned as protected the data members can be accessed within the package . These data members can also be accessed outside the class by inheriting the class.

10.What is the usage of ‘super’ and ‘this’ keywords?

The super keyword in java are used to refer to data members of the immediate parent class of that particular sub class. Whenever a object for a child class is created implicitly a object for the parent class also gets created. Using the super keyword data members of the parent class can be accessed.

The this keyword in java are used to refer to data members of the current class.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.