37 Java Interview Questions

Arc & Codementor
Arc & CodementorArc & Codementor
37 Java Interview
Practice Questions
What is the difference between String,
StringBuffer, and StringBuilder in
Java?
Question 1:
How do you run a Java application
on the command line and set the
classpath with multiple jars?
Question 2:
What is the difference between final,
finalize, and finally?
Question 3:
How does Garbage Collection
prevent a Java application from
going out of memory?
Question 4:
What is the difference between a
ClassNotFoundException a n d
NoClassDefFoundError?
Question 5:
Why isn't String's .length() accurate?
Question 6:
Given two double values d1, d2, why isn’t it reliable to
test their equality using:

Question 7:
d1 == d2
What is the problem with this code:
Question 8:
final byte[] bytes = someString.getBytes();
What is the JIT?
Question 9:
final double d = 1 / 2;
System.out.println(d);
Question 10:
Why does
Print 0? How can you make the code print
0.5 instead?
IntStream.range(0, 10).forEach(System.out::println);
Question 11:
In this code:
what is the inferred type of the method
reference System.out::println?
final Path path = Paths.get(...);
Files.lines(path).forEach(System.out::println);
Question 12:
What is the problem with this code:
What will be the contents of the list after this
operation and why?
Question 13:
final List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.remove(2);
Write a function to detect if two strings are
anagrams (for example, SAVE and VASE)
Question 14:
What is the contract between equals and
hashCode of an object?
Question 15:
Can an enum be extended?
Question 16:
How threadsafe is enum in Java?
Question 17:
How does a JVM handle storing local
variables vs storing objects?
Question 18:
Identify the problem in the following code:
Question 19:
public class Foo {
public Foo() {
doSomething();
}
public void doSomething() {
System.out.println("do something acceptable");
}
}
public class Bar extends Foo {
public void doSomething() {
System.out.println("yolo");
Zoom zoom = new Zoom(this);
}
}
When do you use volatile variables?
Question 20:
Why do you need to use synchronized
methods or blocks?
Question 21:
What is the difference between HashMap and
ConcurrentHashMap?
Question 22:
When do you need to override the equals
and hashCode methods in Java?
Question 23:
What is a service?
Question 24:
What is a good usecase of calling
System.gc()?
Question 25:
What is the marker interface in Java?
Question 26:
How are Annotations better than a Marker
Interfaces?
Question 27:
What are checked and unchecked
exceptions? When do you use them?
Question 28:
int a = 1L; Won’t compile and
int b = 0; b += 1L; compiles fine.
Why ?
Question 29:
Why aren’t you allowed to extend more than
one class in Java but are allowed to
implement multiple interfaces?
Question 30:
Question 31:
Test t = null;
t.someMethod();
public static void someMethod() {
...
}
Why doesn’t the following code generate a
NullPointerException even when the
instance is null?
Question 32:
public class Test
{
public static void main(String[] args)
{
Integer a = 1000, b = 1000;
System.out.println(a == b);
Integer c = 100, d = 100;
System.out.println(c == d);
}
}
why does the first case print false while the
second case prints true?
Question 33:
String s1="home";
String s2="mohe";
How do you check whether or not the following two
strings are anagrams?
How do you reverse String("Java
Programming") without using Iterations
and Recursions?
Question 34:
Give real world examples of when to use an
ArrayList and when to use LinkedList
Question 35:
What is the difference between an Iterator
and a ListIterator?
Question 36:
What is the advantage of a generic
collection?
Question 37:
Did you know how to answer all 37 questions?
Feel free to check your answers here
or
schedule a mock interview with
an experienced Java developer
1 of 39

Recommended

Java questions for viva by
Java questions for vivaJava questions for viva
Java questions for vivaVipul Naik
60.1K views6 slides
21 Essential JavaScript Interview Questions by
21 Essential JavaScript Interview Questions21 Essential JavaScript Interview Questions
21 Essential JavaScript Interview QuestionsArc & Codementor
653.5K views23 slides
Java Interview Questions by NageswaraRao by
Java Interview Questions by NageswaraRaoJava Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJavabynataraJ
10.8K views24 slides
Basic java important interview questions and answers to secure a job by
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobGaruda Trainings
222K views13 slides
Java/J2EE interview Qestions by
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview QestionsArun Vasanth
8.9K views203 slides
20 most important java programming interview questions by
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questionsGradeup
2.9K views17 slides

More Related Content

What's hot

Class notes(week 9) on multithreading by
Class notes(week 9) on multithreadingClass notes(week 9) on multithreading
Class notes(week 9) on multithreadingKuntal Bhowmick
86 views31 slides
Core Java interview questions-ppt by
Core Java interview questions-pptCore Java interview questions-ppt
Core Java interview questions-pptMayank Kumar
524 views13 slides
Interview Questions and Answers for Java by
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for JavaGaruda Trainings
1.1K views3 slides
201 core java interview questions oo ps interview questions - javatpoint by
201 core java interview questions   oo ps interview questions - javatpoint201 core java interview questions   oo ps interview questions - javatpoint
201 core java interview questions oo ps interview questions - javatpointravi tyagi
841 views11 slides
Design pattern application by
Design pattern applicationDesign pattern application
Design pattern applicationgayatri thakur
213 views33 slides
Questions of java by
Questions of javaQuestions of java
Questions of javaWaseem Wasi
103 views27 slides

What's hot(20)

Class notes(week 9) on multithreading by Kuntal Bhowmick
Class notes(week 9) on multithreadingClass notes(week 9) on multithreading
Class notes(week 9) on multithreading
Kuntal Bhowmick86 views
Core Java interview questions-ppt by Mayank Kumar
Core Java interview questions-pptCore Java interview questions-ppt
Core Java interview questions-ppt
Mayank Kumar524 views
Interview Questions and Answers for Java by Garuda Trainings
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for Java
Garuda Trainings1.1K views
201 core java interview questions oo ps interview questions - javatpoint by ravi tyagi
201 core java interview questions   oo ps interview questions - javatpoint201 core java interview questions   oo ps interview questions - javatpoint
201 core java interview questions oo ps interview questions - javatpoint
ravi tyagi841 views
Questions of java by Waseem Wasi
Questions of javaQuestions of java
Questions of java
Waseem Wasi103 views
Java Concurrency Starter Kit by Mark Papis
Java Concurrency Starter KitJava Concurrency Starter Kit
Java Concurrency Starter Kit
Mark Papis391 views
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007 by Arun Kumar
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Arun Kumar17.2K views
EEE oops Vth semester viva questions with answer by Jeba Moses
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses4.5K views
Java design pattern tutorial by Ashoka Vanjare
Java design pattern tutorialJava design pattern tutorial
Java design pattern tutorial
Ashoka Vanjare129 views
Top 20 c# interview Question and answers by w3asp dotnet
Top 20 c# interview Question and answersTop 20 c# interview Question and answers
Top 20 c# interview Question and answers
w3asp dotnet2.3K views

Viewers also liked

29 Essential AngularJS Interview Questions by
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview QuestionsArc & Codementor
487.6K views31 slides
25 php interview questions – codementor by
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementorArc & Codementor
173.1K views37 slides
Django Interview Questions and Answers by
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and AnswersRenjith S Raj
7.2K views12 slides
Ingesting Drone Data into Big Data Platforms by
Ingesting Drone Data into Big Data Platforms Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms Timothy Spann
8.8K views30 slides
Job Interview By Pair Programming by
Job Interview By Pair ProgrammingJob Interview By Pair Programming
Job Interview By Pair ProgrammingAbel Shen
3K views37 slides
ConcurrentHashMap Code Reading by
ConcurrentHashMap Code ReadingConcurrentHashMap Code Reading
ConcurrentHashMap Code ReadingNaoyuki Kakuda
1.7K views85 slides

Viewers also liked(20)

29 Essential AngularJS Interview Questions by Arc & Codementor
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions
Arc & Codementor487.6K views
25 php interview questions – codementor by Arc & Codementor
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementor
Arc & Codementor173.1K views
Django Interview Questions and Answers by Renjith S Raj
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and Answers
Renjith S Raj7.2K views
Ingesting Drone Data into Big Data Platforms by Timothy Spann
Ingesting Drone Data into Big Data Platforms Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms
Timothy Spann8.8K views
Job Interview By Pair Programming by Abel Shen
Job Interview By Pair ProgrammingJob Interview By Pair Programming
Job Interview By Pair Programming
Abel Shen3K views
ConcurrentHashMap Code Reading by Naoyuki Kakuda
ConcurrentHashMap Code ReadingConcurrentHashMap Code Reading
ConcurrentHashMap Code Reading
Naoyuki Kakuda1.7K views
Registry Part 5and6 by woor6j
Registry Part 5and6Registry Part 5and6
Registry Part 5and6
woor6j628 views
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015 by Speedment, Inc.
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015
Speedment, Inc.1.4K views
Registry Part 3 by woor6j
Registry Part 3Registry Part 3
Registry Part 3
woor6j1.1K views
Five Ways to Scale your API Without Touching Your Code by 3scale
Five Ways to Scale your API Without Touching Your CodeFive Ways to Scale your API Without Touching Your Code
Five Ways to Scale your API Without Touching Your Code
3scale10.9K views
Realtime statistics using Java, Kafka and Graphite by Hung Nguyen
Realtime statistics using Java, Kafka and GraphiteRealtime statistics using Java, Kafka and Graphite
Realtime statistics using Java, Kafka and Graphite
Hung Nguyen5.3K views
Java Threads and Concurrency by Sunil OS
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
Sunil OS1.1M views
Refactoring to Java 8 (QCon New York) by Trisha Gee
Refactoring to Java 8 (QCon New York)Refactoring to Java 8 (QCon New York)
Refactoring to Java 8 (QCon New York)
Trisha Gee10.1K views
Introduction to django by Ilian Iliev
Introduction to djangoIntroduction to django
Introduction to django
Ilian Iliev30.5K views
Top 10 architect interview questions and answers by WhitneyHouston012
Top 10 architect interview questions and answersTop 10 architect interview questions and answers
Top 10 architect interview questions and answers
WhitneyHouston0126.6K views
20 iOS developer interview questions by Arc & Codementor
20 iOS developer interview questions20 iOS developer interview questions
20 iOS developer interview questions
Arc & Codementor2.3K views
Pivotal Tracker - Quick Start Guide by Amit Ranjan
Pivotal Tracker - Quick Start GuidePivotal Tracker - Quick Start Guide
Pivotal Tracker - Quick Start Guide
Amit Ranjan2.5K views

Similar to 37 Java Interview Questions

25 java tough interview questions by
25 java tough interview questions25 java tough interview questions
25 java tough interview questionsArun Banotra
482 views5 slides
Latest .Net Questions and Answers by
Latest .Net Questions and Answers Latest .Net Questions and Answers
Latest .Net Questions and Answers Narasimhulu Palle
207 views5 slides
Best interview questions by
Best interview questionsBest interview questions
Best interview questionsThesis Scientist Private Limited
805 views75 slides
GSP 125 Enhance teaching/tutorialrank.com by
 GSP 125 Enhance teaching/tutorialrank.com GSP 125 Enhance teaching/tutorialrank.com
GSP 125 Enhance teaching/tutorialrank.comjonhson300
9 views58 slides
GSP 125 Effective Communication/tutorialrank.com by
 GSP 125 Effective Communication/tutorialrank.com GSP 125 Effective Communication/tutorialrank.com
GSP 125 Effective Communication/tutorialrank.comjonhson282
19 views58 slides
Gsp 125 Education Organization -- snaptutorial.com by
Gsp 125   Education Organization -- snaptutorial.comGsp 125   Education Organization -- snaptutorial.com
Gsp 125 Education Organization -- snaptutorial.comDavisMurphyB85
12 views32 slides

Similar to 37 Java Interview Questions(20)

25 java tough interview questions by Arun Banotra
25 java tough interview questions25 java tough interview questions
25 java tough interview questions
Arun Banotra482 views
GSP 125 Enhance teaching/tutorialrank.com by jonhson300
 GSP 125 Enhance teaching/tutorialrank.com GSP 125 Enhance teaching/tutorialrank.com
GSP 125 Enhance teaching/tutorialrank.com
jonhson3009 views
GSP 125 Effective Communication/tutorialrank.com by jonhson282
 GSP 125 Effective Communication/tutorialrank.com GSP 125 Effective Communication/tutorialrank.com
GSP 125 Effective Communication/tutorialrank.com
jonhson28219 views
Gsp 125 Education Organization -- snaptutorial.com by DavisMurphyB85
Gsp 125   Education Organization -- snaptutorial.comGsp 125   Education Organization -- snaptutorial.com
Gsp 125 Education Organization -- snaptutorial.com
DavisMurphyB8512 views
Gsp 125 Massive Success / snaptutorial.com by NorrisMistryzo
Gsp 125  Massive Success / snaptutorial.comGsp 125  Massive Success / snaptutorial.com
Gsp 125 Massive Success / snaptutorial.com
NorrisMistryzo81 views
Gsp 125 Enthusiastic Study / snaptutorial.com by Stephenson101
Gsp 125 Enthusiastic Study / snaptutorial.comGsp 125 Enthusiastic Study / snaptutorial.com
Gsp 125 Enthusiastic Study / snaptutorial.com
Stephenson10122 views
GSP 125 Technology levels--snaptutorial.com by sholingarjosh136
GSP 125 Technology levels--snaptutorial.comGSP 125 Technology levels--snaptutorial.com
GSP 125 Technology levels--snaptutorial.com
sholingarjosh13612 views
GSP 125 Exceptional Education - snaptutorial.com by donaldzs162
GSP 125 Exceptional Education - snaptutorial.comGSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.com
donaldzs16214 views
GSP 125 Education Specialist / snaptutorial.com by stevesonz146
  GSP 125 Education Specialist / snaptutorial.com  GSP 125 Education Specialist / snaptutorial.com
GSP 125 Education Specialist / snaptutorial.com
stevesonz14635 views
GSP 125 Perfect Education/newtonhelp.com by bellflower169
GSP 125 Perfect Education/newtonhelp.comGSP 125 Perfect Education/newtonhelp.com
GSP 125 Perfect Education/newtonhelp.com
bellflower16915 views
GSP 125 Become Exceptional/newtonhelp.com by bellflower148
GSP 125 Become Exceptional/newtonhelp.comGSP 125 Become Exceptional/newtonhelp.com
GSP 125 Become Exceptional/newtonhelp.com
bellflower1487 views
GSP 125 Doing by learn/newtonhelp.com by bellflower126
GSP 125 Doing by learn/newtonhelp.comGSP 125 Doing by learn/newtonhelp.com
GSP 125 Doing by learn/newtonhelp.com
bellflower12626 views
Gsp 125 Future Our Mission/newtonhelp.com by amaranthbeg8
Gsp 125 Future Our Mission/newtonhelp.comGsp 125 Future Our Mission/newtonhelp.com
Gsp 125 Future Our Mission/newtonhelp.com
amaranthbeg811 views
GSP 125 RANK Education for Service--gsp125rank.com by claric25
GSP 125 RANK  Education for Service--gsp125rank.comGSP 125 RANK  Education for Service--gsp125rank.com
GSP 125 RANK Education for Service--gsp125rank.com
claric258 views
GSP 125 Final Exam Guide by monsterr20
GSP 125 Final Exam GuideGSP 125 Final Exam Guide
GSP 125 Final Exam Guide
monsterr2020 views
CMIS 141 7984 Introductory Programming (2158)A non-local boole.docx by drennanmicah
CMIS 141 7984 Introductory Programming (2158)A non-local boole.docxCMIS 141 7984 Introductory Programming (2158)A non-local boole.docx
CMIS 141 7984 Introductory Programming (2158)A non-local boole.docx
drennanmicah4 views

More from Arc & Codementor

Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc by
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of ArcRemote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of ArcArc & Codementor
364 views31 slides
Introduction to Python for Data Science by
Introduction to Python for Data ScienceIntroduction to Python for Data Science
Introduction to Python for Data ScienceArc & Codementor
4.6K views25 slides
Top 10 Programming Languages in 2015 by
Top 10 Programming Languages in 2015Top 10 Programming Languages in 2015
Top 10 Programming Languages in 2015Arc & Codementor
589 views26 slides
How to Build Your App from Scratch by
How to Build Your App from ScratchHow to Build Your App from Scratch
How to Build Your App from ScratchArc & Codementor
508 views11 slides
Angular meteor for angular devs by
Angular meteor for angular devsAngular meteor for angular devs
Angular meteor for angular devsArc & Codementor
18.8K views34 slides
Tmux tips and_tricks by
Tmux tips and_tricksTmux tips and_tricks
Tmux tips and_tricksArc & Codementor
6.1K views9 slides

More from Arc & Codementor(10)

Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc by Arc & Codementor
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of ArcRemote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
Arc & Codementor364 views
Introduction to Python for Data Science by Arc & Codementor
Introduction to Python for Data ScienceIntroduction to Python for Data Science
Introduction to Python for Data Science
Arc & Codementor4.6K views
Top 10 Programming Languages in 2015 by Arc & Codementor
Top 10 Programming Languages in 2015Top 10 Programming Languages in 2015
Top 10 Programming Languages in 2015
Arc & Codementor589 views
Angular meteor for angular devs by Arc & Codementor
Angular meteor for angular devsAngular meteor for angular devs
Angular meteor for angular devs
Arc & Codementor18.8K views
Introduction to Tmux - Codementor Tmux Office Hours Part 1 by Arc & Codementor
Introduction to Tmux - Codementor Tmux Office Hours Part 1Introduction to Tmux - Codementor Tmux Office Hours Part 1
Introduction to Tmux - Codementor Tmux Office Hours Part 1
Arc & Codementor42K views
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at... by Arc & Codementor
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Arc & Codementor3.4K views
Building Modern and Secure PHP Applications – Codementor Office Hours with Be... by Arc & Codementor
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Arc & Codementor11.2K views
Python Internals Optimization Choices Made - Codementors Office Hours with St... by Arc & Codementor
Python Internals Optimization Choices Made - Codementors Office Hours with St...Python Internals Optimization Choices Made - Codementors Office Hours with St...
Python Internals Optimization Choices Made - Codementors Office Hours with St...
Arc & Codementor20.3K views

Recently uploaded

kibria_portfolio.pdf by
kibria_portfolio.pdfkibria_portfolio.pdf
kibria_portfolio.pdfMasumKhan59
7 views17 slides
Topic 36.pptx by
Topic 36.pptxTopic 36.pptx
Topic 36.pptxsaleh176
7 views6 slides
113. BP International by
113. BP International113. BP International
113. BP InternationalManu Mitra
5 views1 slide
Public Speaking by
Public SpeakingPublic Speaking
Public SpeakingBasel Ahmed
50 views11 slides
1123.CV-02.pdf by
1123.CV-02.pdf1123.CV-02.pdf
1123.CV-02.pdfThomas GIRARD BDes
31 views18 slides
SUDIP DHAR Resume.pdf by
SUDIP DHAR  Resume.pdfSUDIP DHAR  Resume.pdf
SUDIP DHAR Resume.pdfSudip Dhar
13 views2 slides

Recently uploaded(16)

Topic 36.pptx by saleh176
Topic 36.pptxTopic 36.pptx
Topic 36.pptx
saleh1767 views
113. BP International by Manu Mitra
113. BP International113. BP International
113. BP International
Manu Mitra5 views
SUDIP DHAR Resume.pdf by Sudip Dhar
SUDIP DHAR  Resume.pdfSUDIP DHAR  Resume.pdf
SUDIP DHAR Resume.pdf
Sudip Dhar13 views
reStartEvents 12:7 Nationwide TS:SCI & Above Employer Directory.pdf by Ken Fuller
reStartEvents 12:7 Nationwide TS:SCI & Above Employer Directory.pdfreStartEvents 12:7 Nationwide TS:SCI & Above Employer Directory.pdf
reStartEvents 12:7 Nationwide TS:SCI & Above Employer Directory.pdf
Ken Fuller175 views
Software Engineer's Career Management Toolkit by ozgengungor1
Software Engineer's Career Management ToolkitSoftware Engineer's Career Management Toolkit
Software Engineer's Career Management Toolkit
ozgengungor123 views
Resume_McCauleyFynnBullock-1 (1).pdf by FynnBullock
Resume_McCauleyFynnBullock-1 (1).pdfResume_McCauleyFynnBullock-1 (1).pdf
Resume_McCauleyFynnBullock-1 (1).pdf
FynnBullock17 views
Danny Gaethofs CV - n English.pdf by Danny Gaethofs
Danny Gaethofs  CV - n English.pdfDanny Gaethofs  CV - n English.pdf
Danny Gaethofs CV - n English.pdf
Danny Gaethofs13 views
GLS-Recognition-Award-2023 by Manu Mitra
GLS-Recognition-Award-2023GLS-Recognition-Award-2023
GLS-Recognition-Award-2023
Manu Mitra5 views
114. BP International [2023] by Manu Mitra
114. BP International [2023]114. BP International [2023]
114. BP International [2023]
Manu Mitra6 views
WordCamp (Why fret over AI overlords when you can befriend them).pdf by BiaAhmed1
WordCamp (Why fret over AI overlords when you can befriend them).pdfWordCamp (Why fret over AI overlords when you can befriend them).pdf
WordCamp (Why fret over AI overlords when you can befriend them).pdf
BiaAhmed126 views

37 Java Interview Questions

  • 2. What is the difference between String, StringBuffer, and StringBuilder in Java? Question 1:
  • 3. How do you run a Java application on the command line and set the classpath with multiple jars? Question 2:
  • 4. What is the difference between final, finalize, and finally? Question 3:
  • 5. How does Garbage Collection prevent a Java application from going out of memory? Question 4:
  • 6. What is the difference between a ClassNotFoundException a n d NoClassDefFoundError? Question 5:
  • 7. Why isn't String's .length() accurate? Question 6:
  • 8. Given two double values d1, d2, why isn’t it reliable to test their equality using:
 Question 7: d1 == d2
  • 9. What is the problem with this code: Question 8: final byte[] bytes = someString.getBytes();
  • 10. What is the JIT? Question 9:
  • 11. final double d = 1 / 2; System.out.println(d); Question 10: Why does Print 0? How can you make the code print 0.5 instead?
  • 12. IntStream.range(0, 10).forEach(System.out::println); Question 11: In this code: what is the inferred type of the method reference System.out::println?
  • 13. final Path path = Paths.get(...); Files.lines(path).forEach(System.out::println); Question 12: What is the problem with this code:
  • 14. What will be the contents of the list after this operation and why? Question 13: final List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); list.remove(2);
  • 15. Write a function to detect if two strings are anagrams (for example, SAVE and VASE) Question 14:
  • 16. What is the contract between equals and hashCode of an object? Question 15:
  • 17. Can an enum be extended? Question 16:
  • 18. How threadsafe is enum in Java? Question 17:
  • 19. How does a JVM handle storing local variables vs storing objects? Question 18:
  • 20. Identify the problem in the following code: Question 19: public class Foo { public Foo() { doSomething(); } public void doSomething() { System.out.println("do something acceptable"); } } public class Bar extends Foo { public void doSomething() { System.out.println("yolo"); Zoom zoom = new Zoom(this); } }
  • 21. When do you use volatile variables? Question 20:
  • 22. Why do you need to use synchronized methods or blocks? Question 21:
  • 23. What is the difference between HashMap and ConcurrentHashMap? Question 22:
  • 24. When do you need to override the equals and hashCode methods in Java? Question 23:
  • 25. What is a service? Question 24:
  • 26. What is a good usecase of calling System.gc()? Question 25:
  • 27. What is the marker interface in Java? Question 26:
  • 28. How are Annotations better than a Marker Interfaces? Question 27:
  • 29. What are checked and unchecked exceptions? When do you use them? Question 28:
  • 30. int a = 1L; Won’t compile and int b = 0; b += 1L; compiles fine. Why ? Question 29:
  • 31. Why aren’t you allowed to extend more than one class in Java but are allowed to implement multiple interfaces? Question 30:
  • 32. Question 31: Test t = null; t.someMethod(); public static void someMethod() { ... } Why doesn’t the following code generate a NullPointerException even when the instance is null?
  • 33. Question 32: public class Test { public static void main(String[] args) { Integer a = 1000, b = 1000; System.out.println(a == b); Integer c = 100, d = 100; System.out.println(c == d); } } why does the first case print false while the second case prints true?
  • 34. Question 33: String s1="home"; String s2="mohe"; How do you check whether or not the following two strings are anagrams?
  • 35. How do you reverse String("Java Programming") without using Iterations and Recursions? Question 34:
  • 36. Give real world examples of when to use an ArrayList and when to use LinkedList Question 35:
  • 37. What is the difference between an Iterator and a ListIterator? Question 36:
  • 38. What is the advantage of a generic collection? Question 37:
  • 39. Did you know how to answer all 37 questions? Feel free to check your answers here or schedule a mock interview with an experienced Java developer