55 Java Interview Questions PDF
55 Java Interview Questions PDF
55 Java Interview Questions PDF
You have 2 free stories left this month. Sign up and get an extra one for free.
Below you’ll find a list of Java interview questions and answers I’ve
gathered during my own job hunts. Before you continue, please note that
answers may not be 100% complete, up to date, or optimized, but are in
my experience sufficient for interview situations.
OOP Questions
These questions apply not only to Java, but object oriented languages in
general.
2. Explain inheritance
Making one object the child of another gives the child all properties and
methods (with respect to access modifiers) of its parent and ancestors.
That is inheritance — it is used to achieve code reusability and
polymorphism. In Java, as in most modern languages, an object can
only have one parent — Java does not support multiple inheritance.
Inheritance creates tight coupling between the parent and its children,
which is why dependency injection is often a preferred alternative, as it
allows related pieces of code to be decoupled.
3. Explain polymorphism
There are many ways to answer this one. A first approach could look
something like this:
User
* Id: Long
* Name: String
Post
* Id: Long
* Likes: Integer
Thread
* Id: Long
* Post: ForeignKey<Post>
Java Questions
6. What can you tell me about memory management and garbage collection
in Java?
They encapsulate optional values, and are used to make code more
readable, stable, and avoid having to deal with null values, thus avoiding
NullPointerExceptions .
The part of the JVM that loads bytecodes for classes at runtime.
They differ in how their items’ ordering and uniqueness. Lists are
ordered and allow duplicate values. Sets are unordered and do not allow
duplicate elements.
14. Which two methods do you have to override for an object to be usable as
a key in a hash map?
You can either make the constructor of the class private, or mark the Top highlight
class as final .
This will return false, because some floating point numbers cannot be
represented exactly.
Because Java was designed on the assumption that strings will be heavily
used. Making it immutable allows for some optimization around easily
sharing the same string between multiple clients.
21. What are some ways that you could sort a collection?
Fizz buzz
Palindromes
Even or Odd
Naive Fibonacci
or
Endless Loop
1 bool isPrime(int n) {
2 if (n % 2 == 0) return false;
3 for (int i = 3; i*i <= n; i += 2) {
4 if (n % i == 0) return false;
5 }
6 return true;
7 }
Primes
Stacks
28. In a stack, peek() is O(1). How would you achieve O(1) lookup for
peek() in a linked list?
Linked lists typically keep a reference to the head node. In peek() just
return head.value .
Singly-linked List
32. in Java, how fast is direct lookup in a hash map theoretically, and why is
it often slower in reality?
Arrays.binarySearch(sortedArray, key);
Binary search
Bubble Sort
35. Given a string like a**hf*kl9* , write a function that returns a string with
all asterisks appearing first.
Sort String
. . .
37. Tell us the details of an interesting problem you worked on. What made it
interesting?
41. Tell us about a time when you had to make a trade-off between user
experience and optimization / technical design?
42. What’s an example of a time, when you had make a decision quickly?
What were the reasons behind that decision? Would you have done anything
differently?
Nontechnical Questions
47. Tell us about yourself. What are your career goals and past projects?
Where do you see yourself in 2 / 5 / 10 years?
49. Which parts of our Creed / Mission / Vision resonate the most with you?
Why us? What do you like about our company?
50. Which of our products / projects would you be excited to work on and
why? Are there technologies you don’t want to work with and why not?
51. How do you use our and / or our competitors’ products? How would you
improve on them?
52. What is your dream job? What’s your perfect work day like?
The last one is important. Here are some suggestions for questions you
may want to ask your interviewer:
What does the career path look like for this role?
Do you feel there are any skills currently lacking on the team?
What is the biggest change the company has gone through in the last
year?
What type of background and experience are you looking for in this
position? What would your ideal candidate be like?
Is there anything that stands out to you that makes you think I might
not be the right fit for this position?
469 claps
WRIT T EN BY
Linux user tries My Top 20 VS Code Tricky Java Interview 5 T hings T hat Are Hard
Windows, in 2020 Extensions Questions To Grasp When You
Dominik Tarnowski in Level Up Neo Hao Jun in Level Up Manusha Chethiyawardhana in Start Programming
Coding Coding Level Up Coding Daan in Level Up Coding
5 Lessons I’ve Learned Handling Authorization 4 JavaScript Tricks You 3 Habits T hat Will Help
on How to Structure In Clean Architecture Should Know You Become a Top
Code with ASP.NET Core and Anupam Chugh in Level Up Developer
Daan in Level Up Coding MediatR Coding Manish Jain in Level Up Coding
Austin Davies in Level Up
Coding