Java Questions
Java Questions
technical concepts and effective teaching methodologies. Below is a curated list of 50 commonly
asked interview questions, categorized by topic, along with conversational explanations to help
you grasp the concepts effectively.
7. Can you explain the difference between an abstract class and an interface?
● Java Data Types: 3. What is the difference between primitive data types and objects in
Java?
6. Answer: Primitive data types (like int, char, float) store simple values and are not
objects; they are stored directly in memory for efficiency. Objects, however, are
instances of classes and can represent more complex structures. They are
stored as references, meaning the variable holds the address of the object in
memory.
■ Answer: Wrapper classes provide a way to use primitive data types (int,
char, etc.) as objects. Each primitive type has a corresponding wrapper
class in Java (e.g., Integer for int, Character for char). They are useful
when you need an object reference to a primitive value, such as when
working with collections that can only store objects.
6. Answer: Java uses a try-catch-finally mechanism to handle exceptions. Code that
might throw an exception is placed in the try block. If an exception occurs, it's
caught in the catch block, where you can handle it appropriately. The finally block
contains code that executes regardless of whether an exception was thrown,
typically used for cleanup operations.
● Collections Overview: 7. What are the main interfaces in the Java Collections
Framework?
8. Answer: The main interfaces include List, Set, and Map. List allows ordered
collection with duplicates, Set is a collection that doesn't allow duplicates, and
Map holds key-value pairs, with unique keys mapping to specific values.
3. Java 8 Features:
● Stream API: 11. What are streams in Java 8, and how are they used? - Answer:
Streams represent a sequence of elements supporting sequential and parallel aggregate
operations. They allow for functional-style operations on collections of data, such as
map, filter, and reduce, enabling concise and readable code for processing collections.
12.Can you explain the difference between intermediate and terminal operations in
streams?
● Thread Management: 13. What is the difference between a process and a thread? -
Answer: A process is an independent program in execution with its own memory space,
while a thread is a lightweight subprocess, the smallest unit of processing. Threads
within the same process share the same memory space but can execute independently.