Curated interview practice questions with answers. These are practice scenarios, not a verified list of past interview questions.
About HCLTech hiring for Java roles
HCLTech is an Indian multinational IT services and consulting company providing digital engineering, cloud, infrastructure, software products and data services. It works with clients in sectors such as financial services, manufacturing, life sciences and telecom. In India it hires for software engineers, test engineers, data analysts and data engineers through campus drives and programmes like TechBee.
For Java roles, this HCLTech practice set focuses most on Java Basics and JVM (7), JDBC, Hibernate and JPA (4), Multithreading and Concurrency (4), Java 8+ Features and Streams (4). It has 14 easy, 15 medium, 1 hard questions, so you can start easy and work up to the harder ones.
Company type
IT services
Headquarters
Noida, India
Main India offices
Noida, Chennai, Bengaluru, Hyderabad, Lucknow
HCLTech Java interview process
Online assessment (aptitude + technical)
Technical interview
Managerial round
HR round
Typical pattern based on public candidate experiences. Rounds vary by role, team and year.
Solved for HCLTechStart practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
wait() is an Object method called inside synchronized code; it releases the monitor and waits until notify(), notifyAll() or a timeout. sleep() is a Thread static method that pauses the current thread for a time but keeps any locks it holds. wait() is for coordination between threads, while sleep() simply delays. Modern code prefers Condition, BlockingQueue or CountDownLatch.
03
How do you take a thread dump and a heap dump of a running Java process?
Find the process id with jps or ps, then use jcmd, which is the recommended tool.
jps -l
jcmd <pid> Thread.print > threads.txt
jcmd <pid> GC.heap_dump /tmp/heap.hprof
Older tools jstack and jmap do the same. Take three thread dumps a few seconds apart to spot stuck threads, and analyse heap dumps in Eclipse MAT.
04
A counter shared between threads shows wrong totals. How do you fix it?
count++ is not atomic; two threads can read the same value and both write the same result, so updates are lost. Use AtomicInteger.incrementAndGet(), which uses CAS, or LongAdder for very high contention, as it spreads updates over cells. A synchronized method also works but is slower. volatile alone does not fix it because it gives visibility, not atomicity.
05
What is the difference between == and equals() in Java?
== compares primitive values, or for objects it checks whether two references point to the same object in memory. equals() checks logical equality and can be overridden, as String, Integer and most value classes do. For example, new String("a") == new String("a") is false, but equals() returns true. Always use equals() to compare object content.
06
What is the difference between intermediate and terminal operations in streams?
Intermediate operations like filter, map, sorted and distinct return a new stream and are lazy; nothing runs until a terminal operation is called. Terminal operations like collect, forEach, reduce, count and findFirst trigger processing and produce a result. Laziness lets streams fuse steps into a single pass and short-circuit, so findFirst on filtered data stops early.
07
Why is PreparedStatement preferred over Statement?
PreparedStatement sends the SQL with placeholders separately from the parameter values, so user input is never treated as SQL, which prevents SQL injection. The database can also cache and reuse the execution plan, and it handles types like dates correctly. Statement with string concatenation is unsafe and slower for repeated queries, so it should not be used with user input.
throw is a statement used inside a method to actually raise an exception object, for example throw new IllegalStateException("closed"). throws is used in a method signature to declare which checked exceptions the method may pass to its caller, for example void read() throws IOException. A method can declare many exceptions with throws but throws one object at a time.
09
What are virtual threads and when should you use them?
Virtual threads, final in Java 21, are lightweight threads managed by the JVM and mounted on a small pool of carrier OS threads. When one blocks on I/O, it unmounts so the carrier can run another. You can run millions of them, which suits thread-per-request servers doing lots of blocking calls. They do not speed up CPU-bound work, and you should not pool them.
The JVM first interprets bytecode, then profiles which methods run often. The Just In Time compiler converts these hot methods into optimised native code at runtime. HotSpot uses tiered compilation: C1 compiles quickly with light optimisation and C2 applies aggressive optimisations like inlining and escape analysis. This is why Java apps get faster after a warm-up period.
11
What is the difference between HashMap, LinkedHashMap and TreeMap?
HashMap gives O(1) average operations with no ordering guarantee. LinkedHashMap keeps insertion order, or access order if configured, which helps build an LRU cache. TreeMap keeps keys sorted by natural order or a Comparator with O(log n) operations and supports range methods like floorKey and headMap. HashMap allows one null key; TreeMap does not allow null keys with natural ordering.
Situation: three freshers joined my Spring Boot team at once. Task: make them productive quickly. Action: I created a starter task list, paired with each on their first story, gave detailed but kind code reviews and held a weekly session on topics like transactions and testing. Result: all three shipped features independently within a month and one now mentors new joiners.
A deadlock happens when two or more threads each hold a lock and wait for a lock held by the other, so none can continue. It needs mutual exclusion, hold and wait, no preemption and circular wait. Prevent it by always acquiring locks in the same global order, using tryLock with a timeout, holding locks briefly and avoiding calls to unknown code while holding a lock.
14
Write a simple REST controller in Spring Boot for creating and fetching products.
Extend RuntimeException for unchecked or Exception for checked, and provide constructors that accept a message and a cause so the root stack trace is kept. Create one when a domain error needs specific handling, such as InsufficientBalanceException, which a Spring @ControllerAdvice can map to an HTTP 422 response. Do not create exceptions for normal control flow.
16
What is the difference between List.of(), Arrays.asList() and Collections.unmodifiableList()?
List.of() returns a truly immutable list; add, set and remove throw exceptions and nulls are not allowed. Arrays.asList() returns a fixed-size list backed by the array: set() works and writes through to the array, but add() and remove() throw. Collections.unmodifiableList() is a read-only view, so changes to the original list are still visible through it.
17
Write a Java program to check whether a number is prime.
Check divisibility only up to the square root, which makes it O(sqrt n).
public static boolean isPrime(int n) {
if (n < 2) return false;
if (n % 2 == 0) return n == 2;
for (int i = 3; (long) i * i <= n; i += 2) {
if (n % i == 0) return false;
}
return true;
}
The long cast avoids overflow for large n.
Method references are short forms of lambdas that just call an existing method. Types: static method (Integer::parseInt), instance method of a specific object (System.out::println), instance method of an arbitrary object of a type (String::toUpperCase) and constructor (ArrayList::new). They make stream code clearer when the lambda only forwards its arguments.
19
Describe a time you improved the design of existing code.
Situation: our notification module used a 400 line class with switch cases for email, SMS and WhatsApp. Task: add push notifications without breaking anything. Action: I wrote tests for current behaviour, extracted a Notifier interface with one class per channel and used Spring to inject them by type. Result: push was added in one new class, bugs in that module dropped and new channels now take hours, not days.
20
What is the difference between static and dynamic binding?
Static binding is resolved at compile time and applies to private, static and final methods and to overloaded methods, because the compiler knows exactly which method to call. Dynamic binding is resolved at runtime based on the actual object type and applies to overridden instance methods. Static methods are hidden, not overridden, so the reference type decides which one runs.
21
What are the four pillars of OOP? Explain with Java examples.
Encapsulation hides data behind methods, for example private fields with getters and setters in a BankAccount class. Abstraction exposes only what is needed through abstract classes or interfaces, like a Payment interface. Inheritance lets a class reuse another, such as SavingsAccount extends Account. Polymorphism lets one reference behave differently, like a Payment variable calling pay() on a UpiPayment or CardPayment.
22
What is the difference between JPA, Hibernate and Spring Data JPA?
JPA, now Jakarta Persistence, is a specification of interfaces and annotations for object relational mapping. Hibernate is the most popular implementation of that specification and adds its own features. Spring Data JPA sits on top and generates repository implementations from interfaces and method names like findByEmail, reducing boilerplate. Your code uses JPA annotations, Hibernate does the work and Spring Data simplifies access.
23
What are the primitive data types in Java and their sizes?
Java has eight primitives: byte (1 byte), short (2), int (4), long (8), float (4), double (8), char (2 bytes, UTF-16 code unit) and boolean (true or false, size JVM dependent). Primitives store values directly and have default values when used as fields, for example 0 for int and false for boolean. Each has a wrapper class such as Integer.
24
You need to add a new payment method to a system that has a big if-else on payment type. How would you redesign it?
This breaks the Open/Closed principle. I would create a PaymentProcessor interface with a pay() method and one implementation per type, such as UpiProcessor and CardProcessor. A factory or a Spring map of beans keyed by type picks the right one. Adding a new method then means adding one new class without touching existing tested code, and each processor can be unit tested alone.
25
Users get LazyInitializationException when the API returns an entity. What is happening?
The entity was loaded inside a transaction, the session closed, and then Jackson touched a lazy association outside it. Do not fix it by turning on open-session-in-view or making everything eager. Instead, map the entity to a DTO inside the service transaction and fetch needed associations explicitly with JOIN FETCH or an entity graph. Spring Boot logs a warning because open-in-view is on by default.
26
What is the difference between reduce() and collect()?
reduce() combines elements into a single immutable value using an identity and an associative function, such as summing numbers. collect() is a mutable reduction that accumulates into a container like a List, Map or StringBuilder, which is far more efficient for building collections. Using reduce to build a list creates many intermediate copies, so use collect for containers.
27
Explain the hierarchy of the Java Collections Framework.
The root interface is Iterable, then Collection, which has List (ordered, allows duplicates: ArrayList, LinkedList), Set (unique: HashSet, LinkedHashSet, TreeSet) and Queue/Deque (PriorityQueue, ArrayDeque). Map is separate and stores key-value pairs: HashMap, LinkedHashMap, TreeMap and ConcurrentHashMap. Java 21 added SequencedCollection and SequencedMap with getFirst() and getLast().
28
A team member chains Optional.get() everywhere and gets NoSuchElementException. What do you suggest?
get() on an empty Optional throws, so it brings back the same problem Optional was meant to solve. Suggest orElseThrow with a clear domain exception, orElse or orElseGet for defaults, and map or flatMap to chain safe transformations. Static analysis can flag get() without isPresent. Since Java 10 orElseThrow() without arguments is the clear name for the unchecked version.
29
Which JVM flags would you set to start a production service with a 4 GB heap, G1 and a heap dump on OOM?
The heap stores all objects and is shared by threads; it is managed by the garbage collector. Each thread has its own stack holding frames with local variables and partial results. Metaspace (native memory since Java 8) stores class metadata. There are also the program counter register and native method stacks. StackOverflowError comes from the stack and OutOfMemoryError usually from heap or metaspace.
Tips to crack the HCLTech Java interview
Revise programming basics, SQL and networking fundamentals, as HCLTech roles span applications and infrastructure services.
Learn about HCLTech's software products business, HCLSoftware, and its engineering and R&D services.
Be clear and honest about your preferred domain and shift flexibility, as some roles involve support or global time zones.
Keep a one-minute story ready for every project on your CV: problem, your part, tools, result.
Practise the hard questions on this page aloud; HCLTech interviewers usually ask follow-ups on your first answer.
Frequently asked questions
How many rounds are there in the HCLTech Java interview?
Candidates usually go through 4 stages: Online assessment (aptitude + technical); Technical interview; Managerial round; HR round. The exact rounds change with the role, team, location and your experience, so confirm the process with the recruiter.
Which topics should I prepare for the HCLTech Java interview?
This practice set leans on Java Basics and JVM (7), JDBC, Hibernate and JPA (4), Multithreading and Concurrency (4), Java 8+ Features and Streams (4). Revise those first, then practise explaining one or two of your own projects end to end, because most HCLTech interviewers ask you to walk through real work.
Are these the exact questions asked at HCLTech?
No. These are curated practice questions that match the skills and difficulty usually tested in it services interviews like HCLTech's. They are not a leaked or verified list of past questions.
Where does HCLTech hire Java professionals in India?
HCLTech has large teams in Noida, Chennai, Bengaluru, Hyderabad, Lucknow. Openings and locations change often, so check the HCLTech careers page and filter by city and experience.