Top 10 Tricky Interview Questions for Java Developers

Here is a list of top ten (10) tricky / popular interview questions and answers for Java developers. I got these questions out from Stackoverflow. You are a Junior or Intermidiate level Java developer and planning to appear for Java developer interviews in near future, you would find these questions to be useful enough.

Q1Is Java “pass-by-reference” or “pass-by-value”?

Ans: Java is always “pass by value”. Read the details on this page, Is Java “pass-by-reference” or “pass-by-value”?

Q2How to create a memory leak in Java?

Ans: This is possible by making use of Class loader and ThreadLocal. Read the details on this page, Creating a memory leak in Java

Q3What is difference between package private, public, protected, and private?

Ans: A private member variable is accessible within the same class; Package private variable (member variable with no access specifier) is accessible within all classes in the same package; A protected variable is accessible within all classes in the same package and within subclasses in other packages; A public member is accessible to all classes. Read greater details on this page

Q4Tell two differences between HashMap and a Hashtable?

Ans: Hashtable is synchronized; Hashtable does not allow null keys or values. Read greater details on this page, differences between HashMap and Hashtable

Q5What are different techniques of avoid != null statements (Not Null Check)?

Ans: Usage of assert statement is one of the ways; Custom annotations can be defined for NotNull checks; Read greater details on this page, How to avoid != null Statement.

Q6Does “finally” always execute in Java?

Ans: Not in the scenario such as invocation of “System.exit()” function, infinite loop or system crash etc; Read greater details on this page, Does finally always execute in Java

Q7Is it possible to call one constructor from another in Java?

Ans: Yes one can only chain to one constructor, and it has to be the first statement in your constructor body. Greater details can be found on this page, How do I call one constructor from another in Java?

Q8Which one should be used, “implements Runnable” vs. “extends Thread”?

Ans: Looks like “implements Runnable” is the preferred way. Read further details on this page, Implements Runnable vs Extends Thread

Q9Is it possible to break out of nested loops in Java?

Ans: Yes; Breaking out of nested loops in Java

Q10What is reflection and why is it useful?

Ans: Reflection is used to describe code which is able to inspect other code in the same system. Read reasons on this page, Why Reflection is useful.

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Recent Posts

Retrieval Augmented Generation (RAG) & LLM: Examples

Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…

7 days ago

How to Setup MEAN App with LangChain.js

Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…

2 weeks ago

Build AI Chatbots for SAAS Using LLMs, RAG, Multi-Agent Frameworks

Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…

2 weeks ago

Creating a RAG Application Using LangGraph: Example Code

Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…

3 weeks ago

Building a RAG Application with LangChain: Example Code

The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…

3 weeks ago

Building an OpenAI Chatbot with LangChain

Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…

3 weeks ago