Wednesday 11 May 2022

Top 50 Java interview questions and answers for SDET - QAE - SDE on OOPS Concepts?

 


Java INterview Question SET-01

Java INterview Question Set-02 ARRAY

Java INterview Questiona Set-03 MAP

Java INterview Question Set-04

Java is a very important topic for both developers and testers. It's very difficult to remember all the Java basics, so it's always wise to do a revision before the day of the interview. 

Check out the Top 50 most asked core java interview questions and answers.

Top 50 Java Interview Questions and Answers:

SDET Interview Questions and Answers.  

Jenkins Interview Questions and Answers.


If you are new to Java and your setup is not yet completed, then refer to the link on How to setup JDK on Windows/Linux/MacOS?


1) What is static blocks in Java ?

Static blocks  are used to initialize static fields in java. 

We declare static blocks when we want to initialize static fields in our class. 

Static blocks get executed exactly once the class is loaded. 

Static blocks are executed even before the constructors are executed. 

Syntax:

static {
   // Logic here or Java code.
 }

static block executed before the main method, to check try the code below in your IDE:

public class Test { 
 static { 
   System.out.println("Static block");
 }
public static void main(String [] args){
     System.out.println("Main method running");
 }
}

2. What is super keyword in java ?

Variables and methods of super class can be overridden in subclass .
. Super is used to access superclass variables, methods, and constructors.

Super can be used in two forms :

  1. 1)   to call a super class constructor.

  2. 2)  to call super class variables and methods.

Super if presented it must be the first statement.

It is used to: 

  1. To call methods of the superclass that are overridden in the subclass.
  2. To access attributes of the superclass if both superclass and subclass have attributes with the same name.
  3. To explicitly address superclass non-arg or parameterized constructor from the subclass constructor.

Explain Compilation and Execution in Java with examples?



3. Why is Java platform independent?

The most unique feature of java is that it's platform independent. In any programming language, source code is compiled into executable code. This cannot be run across all platforms. When javac compiles a java program it generates an executable file called .class file.


The class file contains byte codes. Byte codes are interpreted only by JVM’s . Since these JVM’s are made available across all platforms by Sun Microsystems, we can execute this byte code on any platform. Byte code generated in windows environment can also be executed in linux environment. This makes java platform independent.

4.Difference between this() and super() in java ?

this() is used to access one constructor from another with in the same class while super() is used to access superclass constructor. Either this() or super() exists it must be the first statement in the constructor.

5. How to Add/Join/Combine two lists?

Ans:  Click Here For Answers 

6. Explain about main() method in java ?

Main() method is the starting point of execution for all java applications.

public static void main(String[] args) {}
String args[] are array of string objects we need to pass from command line arguments. Every Java application must have at least one main method. 

public : “public” is an access specifier which can be used outside the class. When main method is declared public it means it can be used outside class.
static : To call a method we require an object. Sometimes it may be required to call a method without the help of an object. Then we declare that method as static. JVM calls the main() method without creating object by declaring keyword static.

void : void return type is used when a method does’nt return any value . main() method does’nt return any value, so the main() is declared as void.


"String Question and Answers<== Click


7. What is method overloading in java ?

A class having two or more methods with same name but with different arguments then we say that those methods are overloaded. Static polymorphism is achieved in java using method overloading.
Compiler decides which method to call at compile time. Using overloading static polymorphism or static binding can be achieved in java.

Note: Return type is not part of the method signature. we may have methods with different return types, but the return type alone is not sufficient to call a method in java. 

For a real-time example with code on method overloading please refer the link HERE

8. Difference between Hashmap and Hashtable?

Ans: Click Here For Answer

9. What is the use of constructor in Java?

Ans: A constructor is a special method used to initialize objects in java.

we use constructors to initialize all variables in the class when an object is created. As and when an object is created it is initialized automatically with the help of constructor in java.


10. Explain Java Coding Standards for variables?

Variable names should start with small letters.

Variable names should be nouns

Short, meaningful names are recommended.

If there are multiple words, every inner word should start with uppercase characters.


11.  Difference between ArrayList and HashMap in Java?

Ans: Click Here For Answer 

12. 
What is the difference between processes and threads ?

A process is an execution of a program, while a Thread is a single execution sequence within a process. 

A process can contain multiple threads. A Thread is sometimes called a lightweight process. 

13. Explain what the available thread states at a high-level?

During its execution, a thread can reside in one of the following states:

Runnable: A thread becomes ready to run, but does not necessarily start running immediately. • Running: The processor is actively executing the thread code.

Waiting: A thread is in a blocked state waiting for some external processing to finish.

Sleeping: The thread is forced to sleep.

Blocked on I/O: Waiting for an I/O operation to be completed. • Blocked on Synchronization: Waiting to acquire a lock.

Dead: The thread has finished its execution. 

14. How does Hashmap work internally?

Ans: Click Here For Answers with Explanation


Array Question and Answers } <--Click

Java INterview Question SET-01

Java INterview Question Set-02 ARRAY

Java INterview Questiona Set-03 MAP

Java INterview Question Set-04


Revision:

How do you iterate through a hashmap?


Ans: using entryset:
for
 (Map.Entry<String, Integer> e : map.entrySet())

            System.out.println("Key: " + e.getKey()

                               " Value: " + e.getValue());

    }



Does the hashmap allow duplicate keys and values?


Ans:

Hashmap doesnt allow duplicate keys, but allows duplicate values


How to call a method in Java with and without an object?
 
Ans: Click the link for answers

 How to replace values in a hashmap?


with replace():Replaces the entry for the specified key only if it is currently mapped to some value


HashMap<String, Integer> map = new HashMap<>();

map.put("james", 10);

map.replace("james", 50);


What is a Hashmap? 


- Part of Collection Framework

- Implement Map interface

- There are 4 main fields which are Hash, Key, Value, Node


 How to find duplicate elements using Hashmap ?


Ans: Click here for Answer With Code



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

FACTS about FINAL is Java: 

- final class: the class cannot be extended

- final method: the method cannot be overridden

- final field: the field is a constant

- final variable: the value of the variable cannot be changed once assigned

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

*******************************************************************
For any doubts or career guidance, arrange a 1:1 call with me 


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


Learn (API-Microservice)Testing+(CoreJava+UI)-SDET

with Self Paced Videos and one LIVE Doubt Session

TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,
API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below)
Check Training Page for Course Content or reach out @whatsapp +91-9619094122

Entire course content can be found below:  COURSE CONTENT



SeleniumWebdriver Automation Testing Interview Questions:

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
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/search/label/GIT


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



No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

Introduction to Web Testing with Playwright

  Introduction to Web Testing with Playwright 📌  Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 📌  YouTube channel:  https://lnkd.in/gGUG...