If you are preparing for a Java-based interview, it’s a good idea to go through Java Interview Questions. I have written a lot of interview questions articles in Core Java, Java EE to popular frameworks.
Java Interview Questions FAQs
Let’s go through some common questions before you read articles that focus on specific areas.
1. Which is the best site for Java Interview Questions?
There are tons of websites where you will find java interview questions. So how do you know which ones you should read?
The answer is simple – read the ones that cover the latest features. Also, read the articles where you can post comments. Most of the times, the author makes some mistakes or confusing statements. Then corrects them through user feedback coming through comments.
2. What are the popular topics for Java Interview?
Some of the popular topics for Java interview are:
- OOPS Concepts
- Java String
- Collections Framework
- Multithreading
- Generics
- Exception Handling
- Stream API
- Lambda Expressions
- Latest Release Features
- Java EE Frameworks – Spring, Hibernate etc.
3. What is Java used for?
We use Java programming everywhere. We use Java to create standalone programs, web applications, and web services. We can create distributed enterprise applications using Java EE frameworks.
4. What is Core Java?
Java SE is also called Core Java. It is the set of libraries that are part of standard java installation. For example, the Collections framework is part of Core Java. But, Servlet/JSP is part of Java Enterprise Edition.
5. What are the advanced Java Topics?
Some of the advanced java concepts are:
- Heap and Stack Memory
- Garbage Collection
- Reflection API
- Thread Deadlock
- Java ClassLoader
- Java Logging API
- Internationalization in Java
- Java Module System
6. Is Java a dying language?
Java is still one of the most popular programming languages. It’s still the first choice for enterprise applications. There are tons of free open source resources available to help you in Java programming. So I am not worried that Java is Dying at all.
7. What is difference between JavaScript and Java?
Some of the key differences between JavaScript and Java are:
- Java is Object Oriented Programming Language. But, JavaScript is an Object Oriented Scripting language.
- Java code runs in a virtual machine or browser (Applets) where JavaScript code runs on browser.
- We have to compile Java source code to byte code before JVM can understand and execute it. JavaScript code is text based and we don’t need to compile it.
- We use JavaScript to perform browser specific tasks. We use Java to create standalone utility apps, web applications, and web services.
- JavaScript is lightweight whereas we have to install Java and configure it to run.
8. Which is better – Java or Python?
It’s like comparing Apples to Oranges. Both Java and Python are very popular programming languages. It depends on the project whether you want to use Java or Python or sometimes both together.
Here are some inputs based on my personal experience working with both Java and Python for a long time.
- We prefer Java over Python to create web services or web applications. Java EE APIs and frameworks are robust and secure. Python frameworks such as Flask and Django are still evolving.
- We prefer Python over Java to create a utility script because it’s more lightweight than Java.
- We prefer Python for Data Science, Machine Learning, and Artificial Intelligence applications. It’s because most of the popular APIs in these areas are Python-based.
9. Who Created Java?
Java was first created by James Gosling at Sun Microsystems. The first public version was released in 1996.
10. What is the latest version of Java?
Java 12 is the latest version, released on March 19, 2019. Now, Oracle releases a new java version every 6 months. So you can expect Java 13 release in September 2019.
Java Interview Questions
1. Core Java Interview Questions and Answers
Core Java is the starting point of any Java interview. A strong grip on Core Java is a must to clear the Java interview for experienced as well as beginners. This article lists the most important core java interview questions with answers.
2. Java 8 Interview Questions
Java 8 was a major release with many new features. Some of them are Lambdas, Functional interfaces, Streams, and Date Time API. This article will help you in preparing for the interview related to these APIs.
I recently wrote another article as part-2 of java 8 interview questions.
3. Java Collections Interview Questions and Answers
Collections are core components of Java programming language. They are widely used in interview questions. The post contains 40+ questions on java collections to make sure all the topics are covered.
I also recommend you to read java collections tutorial.
4. Java String Interview Questions and Answers
The String is the most used Java class. Java interview usually starts with tricky questions related to String. This post contains 21 questions with detailed answers for String in Java.
5. Java Multi-Threading and Concurrency Interview Questions
Multithreading and Concurrency is a hot topic in Java interviews. It’s good to have good knowledge of Threads in Java. This post covers 30+ interview questions for Java Threads.
I also recommend you to read Java Thread Tutorial to gain good knowledge on Threads.
6. Java Exception Handling Interview Questions
Exception Handling is one of the tricky areas. Java provides a robust and object-oriented approach for exception handling. There are Exception, Error, and Throwable at the root of Exception Handling. I have seen so many guys who are confused in checked, unchecked, and runtime exceptions. Here you will go through a list of 15 questions related to Exception Handling in Java.
7. Difference between JDK, JRE and JVM
You should know about the Java virtual machine, runtime environment, and Java compiler. A post dedicated to explain these and list out their differences.
8. Java Classloaders
Java ClassLoader comes under advanced java concepts. This article provides a detailed explanation of different types of Java classloaders. You will learn how and when we should write our own classloaders with example programs.
9. Difference between Abstract Class and Interface
Abstract classes and interfaces are used in java for defining the contract. But, what is the difference between them? When should we use interface over the abstract class and vice versa?
It’s a great design question and asked a lot in java interviews. This post provides all the differences between abstract class and interface. When should we use interface over the abstract class and vice versa?
The post also explains how to use abstract class and interface to create a flexible design. I also recommend to read java abstract class and interface in java tutorials.
10. Why Java Doesn’t support multiple inheritance and Composition vs Inheritance
One of the most asked questions is why java doesn’t support multiple inheritances? Why should we prefer composition over inheritance? This article provides a detailed explanation of multiple inheritances. The issues with the inheritance that make composition a better approach.
11. Java Programming Interview Questions
Some tricky questions to test your programming skills. Also, check out java tricky code snippets.
12. Java 7 Catch Block
Java 7 has improved catch block to catch multiple exceptions in a single block. It’s a good improvement for making our catch block code small when we needed to catch a lot of exceptions.
13. Java Heap Memory vs Stack Memory
JVM runtime memory is divided into heap memory and stack memory. An important article explaining the difference between Heap and Stack memory through the program.
14. Java is Pass By Value or Pass by Reference
This is one of the most confusing questions about the Java programming language. Some say it’s pass by value and somewhere you will read that it’s pass by reference. Then again behavior changes for primitive types or Object parameters? Read this out to clear this confusion once and for all. This is one of the favorite questions asked by java interviewers.
Java EE Interview Questions
1. JDBC Interview Questions and Answers
If you are working on Enterprise applications, I am sure that JDBC API is a part of it. JDBC API provides database connectivity for relational databases, such as MySQL and Oracle.
This article has a collection of 40+ interview questions related to the JDBC API. They cover areas from basic Connection to DataSource to Connection Pooling. It will help you in interviews for questions related to JDBC API and how to use it.
If you are new to JDBC, I would suggest you go through JDBC Tutorial to make sure you have covered all the core parts of it.
2. Servlet Interview Questions with Answers
Servlets are one of the hot topics of Java Enterprise Edition interview questions. This post contains a list of 50 servlet interview questions with answers in detail. A must-have bookmarked post because I will keep on adding more questions in the future.
3. JSP Interview Questions and Answers
JSP is an integral part of Java EE. If you are giving an interview for a web developer, then having good knowledge of JSP is very important. This post contains a list of 35 JSP interview questions with answers. Please make sure to bookmark it because I will be kept on adding more to the list in the future.
4. Struts Interview Questions and Answers
Struts2 is one of the modern Java Web Application framework. This article contains a list of 30 questions with answers for Struts2 framework.
5. Spring Interview Questions and Answers
Spring Framework is the most widely used Java EE framework. It’s built on core principles of “Dependency Injection” and “Aspect-Oriented Programming”. This post contains more than 45 questions related to Spring Framework. They also cover Dependency Injection, Spring AOP, Spring JDBC, and Spring MVC.
6. Web Services Interview Questions
Web services are popular these days because they are language and platform independent. It’s easy to create SOAP and REST based web services. This post will help you learn about web services and related interview questions. Then there are questions with detailed answers for Java Web Services.
7. JSF Interview Questions
More than 50 questions on JSF-2 with detailed answers, go through them as a refresher on JSF framework.
8. Hibernate Interview Questions and Answers
Hibernate is the best Java-based ORM tool in the market. It’s used a lot in most of the enterprise applications to overcome the shortcomings of JDBC. Hibernate provides flexible configuration using XML, JPA annotations as well as through code. So it’s always a plus point to have Hibernate in your resume.
9. Scala Interview Questions
Scala is famous programming language that provides functional programming in Java. I have written three successive posts that you can go though for scala interview.
- Scala intermediate interview questions
- Scala intermediate and advanced interview questions
- Scala advanced interview questions
10. Common Job Interview Questions
For clearing an interview, only technical knowledge is not enough. You will have to go through common job interview questions. For example, your last company experience. Why you are looking for a change?. This article covers 40 common job interview questions.
For(;;)
These is infinite loop
All thing are optional but we put 1 or 0 or any negative value at condition like for (;1;)
Then what will be output for any condition. It will be true or false.
first of all this wont get compile
Unresolved compilation problems:
Syntax error on token “For”, for expected
Type mismatch: cannot convert from int to boolean
looks like link is broken / page not found for Restful Interview Questions link
Which URL you are pointing out? Everything seems working fine for me.
Very useful in cracking the interview.
Thanks for sharing.
very much appreciate you time spent on publishing this blog.!
Thank you for taking time in it and providing us.
that makes life easy 🙂
thanks for consolidating it.
very much thankful for impo.question of interviews plz provide all on my mail id as well,thanks in advance aswell.
Thank you very much Pankaj for sharing such good collection of questions on wide variety of topics of java ,Your Book on Design patterns was really awesome.
Thanks Chandiprasad, you made my day. Please subscribe to our newsletter too where we share exclusive tips and free Books.
Please help me to get a java code to get number pin which is obtained by concatenating lengths of each word of the string .
for example: number pin for “wipro Technologies” is 512
wipro=”5″
technologies=”12″
String s=”Wipro Technologie”;
String[] word=s.split(“\\s+”);
String pincode=new String();
for(String s1:word){
pincode+=s1.length();
}
System.out.println(pincode);
Can you please shade some light on the use/need of copy constructor.
the concept of copy constructor is supported in java. But unlike C++ java doesnot support the cocept of default copy constructor.
Need of copy constructor:
copy constructor is required when you want memory to be allocated for both the objects a and b belonging to the same class T.
e.g
let us suppose a class T
a and b are its objects
a and b are then references created on stack.
and there will be some memory allocated on heap
Now, without copy constructor both will refer to same memory location.
so to allocate the memory for both a and be seprately we have its solution as copy constructor.
Thank u.
answer:
A is a superclass it has subclass like B and C…..
ur adding an superclass to an collection class, subclass of A will added into collation.
u don’t want the subclass of A to add in collection then u please remove the inheritance between then….
Hi,
Can any please tell me the solution for the below question:
I have a super class named A,and few sub classes named B,C.The both sub classes B and C extends A.
I want to add the super class object in the collection(like arraylist) not sub class objects.
Which means the collection should allow only super class object not sub class object.
Very good collection of question!!!
Many Thanks. I’m not sure where to make a request to you. I can see you’ve covered tutorials for all latest technology, but I see one more important is missing which is JPA (Java Persistent API). May I request you to please create tutorials for same?
JPA is specification and Hibernate is the best implementation of that. I have covered Hibernate and if you read any of my Hibernate posts, you will notice that I am using JPA annotations only. I hope you got the point.
Hello,
Could you please try to create a “Spring Security OAuth2” project with Twitter, Google and Facebook?
Thank you.
Nice info..very useful.plz post question on jax-ws webservices
Very nice collection of interview questions….
quaisens r very nice it will be more usi full for java interviews wen they ask q r very tuff and q r very importent to reed
How to call Informatica workflow from Java
uffffffff
Thanks for helping …..
You right simpe, short and very helpful articles.
If you don’t mind please add questions about JMS.
thank you
Thanks, I will post about it in near future.
Hi pankaj,
May i know your opinion on java certifications.
It’s good to have.
interview questions
1.how class get locks
2.how to get top first 4 repeated words in file
Thank q pankaj its very useful for my interview panel .And some more question on Hybernate and Struts,Servlets
Please add hibernate interview questions also
Great thank you for the articles
hi pankaj,
plz upload tutorials for polymorphism too..
please provide JSF and ADF question and documents
This blog is very good. You have covered all the basic concept of java with proper explanation and example.
And also you have provided the Interview questions on all topics which help the job seeker to get the job as well as his basic concepts also get build.
thanks ton please add struts 1.x interview qstns
Struts 1.x is deprecated and EOL a long time ago, I would suggest you to not waste time on that.
I believe it might be used in some legacy applications only now.
Good effort and easy understand each questions.Please post spring and hibernate tutorial and interview Q&A
Thanks a ton. Desperately waiting for similar posts for Hibernate and Springs 🙂
Thanks a ton. This is very helpful.
This blog helps me a lot in interview preparations . Thanks
Nice blog, please add some more question on spring, spring security & hibernate. This interview question really helpful for the interview preparation. Keep going on.
Thank u sir,for providing this type of clear description to each concept.i am not seen like this in further.
Thank you for sharing this….:)
Helpful to us
What a great idea of posting potential questions!!! Thanks.
nice blog,,,,it’s very helpful for me tqz alot
Hi,
will you please tell me how to impliment breadcrumb using jquery or javascript.
(Anusandhan.net is a sample site where top categories shown i want structure like that)
Wonderful. Thanks for this! 🙂
How to call java methods in oracle methods?