0% found this document useful (0 votes)
56 views14 pages

Java - Cluster 1 - Questions and Answers Interview Prep

The document provides a comprehensive set of technical interview questions and answers focused on Java programming, covering core concepts, object-oriented programming, data structures, algorithms, exception handling, garbage collection, and multithreading. It includes coding problems and explanations of various Java features such as JVM, inheritance, polymorphism, and exception handling mechanisms. Additionally, it contrasts Java with other programming languages like C and Python, and discusses string manipulation and memory management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views14 pages

Java - Cluster 1 - Questions and Answers Interview Prep

The document provides a comprehensive set of technical interview questions and answers focused on Java programming, covering core concepts, object-oriented programming, data structures, algorithms, exception handling, garbage collection, and multithreading. It includes coding problems and explanations of various Java features such as JVM, inheritance, polymorphism, and exception handling mechanisms. Additionally, it contrasts Java with other programming languages like C and Python, and discusses string manipulation and memory management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Java – Cluster 1 - Technical Interview Questions

✅Java Coding Questions


✅ OOPs Based Asked Questions!
✅ DSA & Exceptional Handling Based
✅ April Month QnA

CAREERSYNC
Core Java Concepts:
What is Java?
Java is a high-level, object-oriented programming language used for building platform-independent
applications.
Features of Java
Java is platform-independent, secure, robust, multi-threaded, and supports automatic memory
management (garbage collection).
Why is Java platform-independent?
Java is platform-independent because it uses the Java Virtual Machine (JVM) to execute compiled
bytecode on any platform.
What is JVM? What are its advantages?
JVM (Java Virtual Machine) is an engine that provides runtime environment to execute Java
bytecode. It ensures portability, security, and performance optimization.
What is a String Literal?
A String literal is a sequence of characters enclosed in double quotes, representing a constant value.
Difference between C and Java
C is a procedural language while Java is object-oriented, and Java is platform-independent, unlike C.
Difference between Python and Java
Python is dynamically typed and interpreted, whereas Java is statically typed and compiled.

CAREERSYNC
Core Java Concepts:
Can static methods be overridden? Why or why not?
Static methods cannot be overridden because they belong to the class itself, not an instance, and are
resolved at compile-time.
What is the use of the final keyword?
The final keyword in Java is used to define constants, prevent method overriding, and prevent
inheritance.
What are Servlets, Streams?
Servlets are Java programs that run on a server and handle client requests. Streams are used for
input and output operations.
What is heap and a stack?
Heap is used for dynamic memory allocation (objects), while the stack is used for static memory
allocation (method calls and local variables).
Why Java uses objects?
Java uses objects to represent real-world entities, enabling modular and reusable code through
object-oriented principles.
Access specifiers in Java
Java has four access specifiers: public, protected, private, and default (no modifier).

CAREERSYNC
Object-Oriented Programming (OOPs)
Inheritance in Java
Inheritance allows a class to acquire properties and methods of another class using the extends
keyword.
Polymorphism
Polymorphism allows one interface to be used for different data types or behaviors.
Explain polymorphism with an example
Example: Animal a = new Dog(); a.sound(); — the method sound() behaves differently based on the
object type.
What is a constructor and destructor?
A constructor initializes objects in Java; Java has no destructor—garbage collection handles memory
deallocation.
Explain the concept of a constructor in Java. Can a constructor be private?
A constructor is a special method used to initialize objects; yes, it can be private (e.g., Singleton
pattern).
Method overloading and method overriding
Overloading allows multiple methods with the same name but different parameters; overriding
redefines a parent method in a subclass.

CAREERSYNC
Object-Oriented Programming (OOPs)
Overloading and overriding example program
class A {
void show(int a) { System.out.println("Overloaded"); }
void display() { System.out.println("Parent"); }
}
class B extends A {
void display() { System.out.println("Overridden"); }
}

Difference between method overloading and method overriding with example


Overloading:
void sum(int a, int b) {}
void sum(double a, double b) {}
Overriding:
class A { void run() {} }
class B extends A { void run() {} }

CAREERSYNC
Object-Oriented Programming (OOPs)
Encapsulation
Encapsulation is binding data and code into a single unit by making variables private and using
getters/setters.
Abstraction
Abstraction hides implementation details and shows only essential features to the user.
Difference between an interface and an abstract class
An interface has only abstract methods (Java 8+ allows default methods), while an abstract class can
have both abstract and concrete methods.
Types of Inheritance in Java
Java supports single, multilevel, and hierarchical inheritance; multiple inheritance is supported
through interfaces.
What is a Constructor and Destructor?
A constructor initializes an object; Java does not have destructors—JVM handles cleanup via garbage
collection.
Explain the Concept of Constructor in Java. Can it be Private?
A constructor is called when an object is created; yes, it can be private (e.g., Singleton pattern).

CAREERSYNC
Object-Oriented Programming (OOPs)
What is a Superclass?
A superclass is a parent class whose properties and methods are inherited by a subclass.
What are Derived Class and Base Class?
A base class (parent) provides common functionality, while a derived class (child) extends or
overrides it.
Why Java Uses Objects?
Java uses objects to model real-world entities and follow object-oriented principles like inheritance,
encapsulation, and polymorphism.

CAREERSYNC
Data Structures and Algorithms:
Difference between Array, LinkedList, and ArrayList
Array: Fixed size, fast access, slow insert/delete.
LinkedList: Dynamic size, fast insert/delete, slow access.
ArrayList: Resizable array, fast access, slower insert/delete compared to LinkedList.
Difference between ArrayList and LinkedList
ArrayList is better for index-based access; LinkedList is better for frequent insertion/deletion.
Binary Search and Code Implementation in Java
Binary search divides the array and searches in half each time (requires sorted array).
Difference between Stack and Queue:
Stack follows LIFO (Last In, First Out) – elements are added and removed from the top.
Queue follows FIFO (First In, First Out) – elements are added at the rear and removed from the front.

CAREERSYNC
String Manipulation:

Write some string methods in java


Reverse string
Print reverse string program
Write a Java program to reverse a string without using inbuilt functions.
Write Java Code to Convert "AkShAy" to "aKsHaY"
Return the count of occurrences of each character in a string using "HashMap".
Return the Duplicate characters in a string
Write a C# program to count vowels in a string.
Write a C# program to find the maximum occurring character in a string.

CAREERSYNC
Exception Handling:
What is Exception Handling in Java?
Exception handling in Java is a mechanism to handle runtime errors using try, catch, finally, throw,
and throws.
Explain Exception Handling with Examples
It allows graceful handling of errors like division by zero, null references, etc., preventing program
termination and providing alternate flow using try-catch.
Exception Handling in Python vs Java (Approach)
Java: Uses try-catch-finally, must declare or handle checked exceptions.
Python: Uses try-except-finally, no need to declare exceptions explicitly.
File Exception Handling in Java
When working with files, use try-except to catch file-related errors like FileNotFoundError, ensuring
safe read/write operations.
Exception Handling Program (Approach)
Wrap risky code inside a try block, handle specific exceptions using catch/except, and use finally for
cleanup (like closing files).
throw and throws in Java
throw is used to explicitly throw an exception.
throws is used to declare exceptions that a method might throw, informing the calling method to
handle it. CAREERSYNC
Garbage Collection
Garbage Collection in Java
Garbage Collection automatically deallocates memory by removing objects that are no longer
referenced.
How Does Garbage Collection Work in Java?
The JVM identifies unreachable objects and reclaims their memory using algorithms like mark-and-
sweep during runtime.
Memory Management in Java
Java manages memory through stack (for method calls/local variables) and heap (for objects), with
automatic garbage collection for unused objects.

CAREERSYNC
Multithreading:
Threads in Java
A thread is a lightweight subprocess that enables concurrent execution of code in a program.
What is Multithreading in Java? How Does It Work?
Multithreading allows multiple threads to run concurrently, improving performance by executing
tasks in parallel; it's managed via the Thread class or Runnable interface.

CAREERSYNC
Coding:
Write a program for palindrome
Write a Java program to check if a number is a palindrome.
Factorial
Factorial coding problem
Write a program to find the factorial of a number using recursion.
Write a Java program to print the first 50 prime numbers.
Write code for print first 10 numbers
Write code for prime numbers in java
Write a Java program to print the Fibonacci series using recursion.
Java Code to Print Sum of First Five Numbers from a Set of Ten Without Giving 11. Values Directly
(Using Loop)
Given: String s1 = "I am happy"; String s2 = "I am sad"; String s3 = "I am happy"; How many objects are
created?
A program based on void, and you should say the output

CAREERSYNC
Coding:

Why does array indexing start from 0? Why can't it start from 1?
Arrays
Basic programs on strings and arrays (swap two numbers using temp and without temp)
Swap 2 numbers without 3 variable
Printing an array in Java
Sum of even numbers
Replace the specified character with a numeric value
Find the first non-repeating character in a string.
Write a Java program for this. (You provided the logic, but couldn’t solve it directly) (Scenario-based
coding problem: In your date of birth, there is a date, month, and year. You need to remove the date
and month step by step and output only the year.)

CAREERSYNC

You might also like