Sunday 4 June 2023

Top Java Interview Q&A for Automation Test Engineer and SDET with Examples

 



Java Interview Questions SET-01

Java Interview Questions Set-02 ARRAY

Java Interview Questions Set-03 MAP

Java Interview Question Set-04


What are the access modifiers in Java and their visibility scopes? 

Answer

Java has four access modifiers: public, private, protected, and default (no explicit modifier). Their visibility scope is as follows:

  • Public: Visible for all classes.
  • Private: Visible only within the same class.
  • Protected: Visible within the same package and subclasses.
  • Default: Visible within the same package.

    Example:

  • public class MyClass {
    public int publicVariable;
    private int privateVariable;
    protected int protectedVariable;
    int defaultVariable;
    }




    Java Coding Standards for SDET

What is the difference between ArrayList and LinkedList in Java?

Answer

ArrayList is implemented as a resizable array, allowing fast random access but slower insertion and deletion. LinkedList is implemented as a doubly-linked list, providing fast insertion and deletion but slower random access.

 Example:

ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("Element 1");
arrayList.add("Element 2");
String element = arrayList.get(0); // Random access

LinkedList<String> linkedList = new LinkedList<>();
linkedList.add("Element 1");
linkedList.add("Element 2");
linkedList.removeFirst(); // Fast insertion and deletion



How to Integrate Maven suite with Jenkins?





Explain the concept of multithreading in Java?

Answer

Multithreading is the concurrent execution of multiple threads in a program. Threads are lightweight processes that share the same memory space. Java provides built-in support for multithreading through the Thread class and the Runnable interface. 

Example:

class MyThread extends Thread {
public void run() {
    // Code to be executed in the thread
}
}

class MyRunnable implements Runnable {
public void run() {
    // Code to be executed in the thread
}
}

public class Main {
public static void main(String[] args) {
    Thread thread = new MyThread();
    thread.start(); // Start the thread

    Runnable runnable = new MyRunnable();
    Thread thread2 = new Thread(runnable);
    thread2.start(); // Start the thread
}
}



How to create Java method to read properties file ?





what is difference between throws and try-catch in java?

In Java, both "throws" and "try-catch" are mechanisms used for handling exceptions, but they serve different purposes:

  1. "throws" is used to declare that a method may throw one or more exceptions. It is part of the method signature and indicates that the method does not handle the exception itself but rather passes the responsibility of handling it to the caller or the calling method. When a method declares "throws" for an exception, it means it is not handling the exception and expects the caller to handle it or propagate it further up the call stack. The caller must either catch the exception or declare "throws" in its own method signature.

Example:


public void readFile() throws IOException {
// code that may throw an IOException
}


"try-catch" is used to catch and handle exceptions within a block of code. It allows you to anticipate and handle specific exceptions that may occur during the execution of the enclosed code block. With "try-catch," you can catch and handle exceptions within the block, preventing them from propagating further. It provides a way to gracefully handle exceptions by providing alternative code paths or displaying error messages.


try {
// code that may throw an exception
} catch (IOException e) {
// handle the IOException
System.out.println("An error occurred: " + e.getMessage());
}



In summary, "throws" is used to declare that a method can potentially throw an exception and passes the responsibility of handling it to the caller, while "try-catch" is used to catch and handle exceptions within a specific block of code.


How to fetch test data from JSON using Java?



 How does garbage collection work in Java? 

Answer: 

Garbage collection in Java automatically reclaims memory that is no longer in use by the program. It works by identifying objects that are no longer reachable through references and freeing up the memory occupied by those objects. The Java Virtual Machine (JVM) has a built-in garbage collector that runs periodically, determining which objects are no longer needed and reclaiming their memory.





What are the differences between equals() and == in Java?

Answer: In Java, equals() is a method used to compare the content or values of two objects, while == is used to compare the references or memory addresses of two objects. Here's an example:

public class EqualsExample {
public static void main(String[] args) {
    String str1 = "Hello";
    String str2 = "Hello";
    String str3 = new String("Hello");

    System.out.println(str1.equals(str2)); // Output: true
    System.out.println(str1 == str2);  // Output: true

    System.out.println(str1.equals(str3)); // Output: true
    System.out.println(str1 == str3);  // Output: false
}
}



How do I loop around Array, List and Map?




How to Sort a Hashmap in Java?


Ans: Refer to the link HERE for answer with code.

I hope this helps you understand how to loop around arrays, lists, and maps in Java!


Looping around the map: 

A map is a data structure that stores key-value pairs. In Java, the java.util.Map interface is commonly used. Here's an example of looping around a map in Java:


import java.util.HashMap;
import java.util.Map;

// Looping around a map
Map<String, Integer> ages = new HashMap<>();
ages.put("John", 25);
ages.put("Alice", 30);
ages.put("Bob", 35);

for (Map.Entry<String, Integer> entry : ages.entrySet()) {
    String name = entry.getKey();
    int age = entry.getValue();
    System.out.println(name + ": " + age);
}

Output:

makefile
John: 25 Alice: 30 Bob: 35

In this example, we create a map called ages and use the put() method to add key-value pairs to the map. Then, we use a "for-each" loop with entrySet() to iterate over each key-value pair in the map. We extract the key and value using the getKey() and getValue() methods, respectively, and print them.

*******************************************************************
For any doubts or career guidance from me, reach out here: https://topmate.io/sidharth_shukla

********************************************************************

Do remember that knowing Linux is one of the most important aspect to work as an SDET.

Basic Linux Commands for Automation QA


****************************************

 SDET Interview Question and Answers

TestNG Interview questions and answers

Jenkins Interview Questions and Answers

Appium Interview Questions and Answers

Selenium Interview Questions and answers

Java Coding Interview Questions and Answers

GIT Interview Questions and Answers


************************************************

✍️AUTHORLinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employees and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API++Mobile+UI, course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET.

For more details whatsapp : https://lnkd.in/dnBWDM33

*************************************************



SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

Sorting with Examples & Time Complexity for SDET

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl Bubble Sort:    Bubb...