All posts
InterviewsJavaSpring Boot

Java Interview Questions & Answers (Core Java + Spring Boot)

May 12, 20261 min read
Java Interview Questions & Answers (Core Java + Spring Boot)

Here is a focused set of Java interview questions and answers that come up again and again — especially for junior roles at Sri Lankan tech companies.

Core Java

Q: What is the difference between == and .equals()? == compares references (the same object); .equals() compares value/equality as defined by the class. Always override equals and hashCode together.

Q: Explain the four OOP principles. Encapsulation (hide state), Inheritance (reuse via "is-a"), Polymorphism (one interface, many implementations), and Abstraction (expose what, hide how).

Q: ArrayList vs LinkedList? ArrayList gives fast random access (O(1)) but slow inserts in the middle; LinkedList is fast for inserts/removals but slow to index.

Q: String, StringBuilder, and StringBuffer? String is immutable; StringBuilder is mutable and fast (not thread-safe); StringBuffer is mutable and synchronized.

Collections & streams

Q: How does a HashMap work? It stores key-value pairs in buckets by hash code; good hashCode/equals keep lookups near O(1).

Q: What are Java 8 streams good for? Declarative data processing — filter, map, collect — that reads clearly and composes well.

Spring

Q: What is dependency injection? The framework supplies a class's dependencies instead of the class creating them, improving testability and decoupling.

Q: @Component vs @Service vs @Repository? All are beans; the names express intent (@Service for business logic, @Repository for data access with exception translation).

How to use this list

Do not memorize — understand, and have an example ready for each. Pair this with the interview guide for IFS, WSO2 & Sysco LABS and you will walk in prepared.