
1.What is Java?
The Java language is a high-level, object-oriented, and platform-agnostic programming language. The WORA principle, Write Once, Run Anywhere, is adhered to.
What are the Java language’s primary features?
Object-focused
Independent of Platforms
Easy and Safe
Several threads
Strong
Excellent Performance (using JVM)
Dispersed
2.What is the difference between JDK, JRE, and JVM?
JVM: JVM A virtual machine runs bytecode for Java.
JRE: JVM archives is the Java Runtime Environment.
JDK: JRE and, furthermore, programming tools (compiler and debugger) make up the Java Programming Pack.
3.What is the difference between = and .equals()?
between==: Examines references to objects.
The function .equals() compares the content of an object (may be altered).
4.What is the definition of OOP and its principles?
The principles of Object-Oriented Programming (OOP):
The process of enhancing data
Abstract implementation hidden
inheritance reusing code
Several types of polymorphism include overloading and overriding.
5.What differentiates an interface from an abstract class?
Feature
Methods
Constructor
Many Inheritances
Abstract Class
Can have both abstract and concrete
Yes
No
Interface
Only abstract till Java 7
No
Yes
6.What are a few Java exceptions?
Runtime errors that can interfere with program flow are called exceptions. Java features:
Verified variations, such as IOExceptions, require to be handled.
Runtime errors, such as NullPointerException, are examples of unchecked exceptions.
7.What distinguishes an array from an array list?
Feature
Size
Type
Performance
Array
Fixed
Can hold primitive
Faster
ArrayList
Dynamic
Only objects
Slower, more flexible
8.What is a Java HashMap?
HashMap stores key-value pairs.
computes the index by using a hash algorithm.
permits null values and keys
Unsynchronized for thread safety use ConcurrentHashMap
9.What does Java multithreading?
Multiple threads can run concurrently thanks to multithreading. This is made possible by Java using
Class of threads
Interface that can be run
Explain synchronization.
It is a way to manage which threads have access to shared resources.
Avoid race problems by using a synchronized block or function.
10.What differentiates StringBuffer, StringBuilder, and String?
Class
String
String Builder
String Buffer
Mutable
NO
YES
YES
Thread Safe
YES
NO
YES
Performance
SLOW
FAST
MEDIUM
11.What does Java garbage collection?
The process of clearing out unnecessary items from memory is known as garbage collection. In Java, it happens automatically.
System.gc() can be used to recommend GC, though this is not a safety.
12.What distinguishes finalize() from finally and final?
final: A keyword designating a variable, method, or class as unchangeable or constant.
Finally: The block that always runs following a try-catch.
finalize(): Deprecated since Java 9+, this function is called by GC prior to object destruction.
13.lambda expressions?
Lambdas, which were first introduced in Java 8, enable the development of functional interfaces with simple syntax.
(a b) -> a + b;
14.What is the difference between overriding and overloading?
A feature
Class Same
Signature of the Method
Runtime
Overloading
class
must differ
compile time
overriding
subclass
it mustbe the same
run time
Advanced interview questions for Java
- What distinguishes Thread from ExecutorService?
- Describe Java Stream API’s benefits.?
- Lambda expressions: what are they? How do they operate?
- In Java, what is functional programming?
- What distinguishes notifyAll(), notify(), and wait() from one another?
- How is concurrency managed in Java applications?
- What do phantom, weak, and soft references mean?
- How is class loading handled in Java? Class loaders: what are they?
- Describe Java’s additional capabilities and how to prevent NullPointer Exceptions?
- What is the different memory areas allocated by the JVM?
- Can you explain the Java Memory Model (JMM)?
- How does garbage collection is work in Java?
- What is the difference between stack and heap memory?
- What are the strong, soft, weak, and phantom references in Java?
- Compare Serial, Parallel, CMS, and G1 garbage collectors?
- What are the memory leak in Java? How do you detect and resolve it?
- How the JVM use Just-In-Time (JIT) compilation?
- What are the escape analysis, and how does it optimize performance?
- What is strategies can be used to tune JVM performance?
- How is synchronized different from lock in Java?
- What is the happens before relationship in Java’s memory model?
- What’s the difference between wait(), notify(), and notifyAll()?
- Compare Callable and Runnable interfaces?
- What is the deadlock, and how can it be prevented?
- What is a race condition? How do you avoid it?
- What does the volatile keyword do?
- What are thread starvation and livelock? How they handled?
- What are the ThreadLocal variables, and when should you use them?
- What is ForkJoinPool, and in what scenarios is it used?
- What are the some commonly used design patterns in Java?
- Explain the Singleton pattern using double checked locking.
- How does the Factory pattern differ from Abstract Factory?
- When should you use thbuilderer design pattern?
- How does Dependency Injection (DI) work in Java?
- How does HashMap work internally?
- Compare the HashMap, LinkedHashMap, and TreeMap?
- What is iConcurrentHashMap,ap and how is it implemented?
- What is the difference between fail fast and fail safe iterators?
- How does Java 8 Stream API differ from traditional loops?
- What are functional interfaces? Provide examples?
- How do method references and lambda expressions work?
- What is difference between map() and flatMap() in streams?
- How does Optional help avoid NullPointerException?
- What are default and static methods in interfaces?
- What’s the difference between checked and unchecked exceptions?
- How does the try-with resources improve exception handling?
- How does Java NIO differ from traditional IO?
- What are CompletableFuture and CompletionStage?
- How does Java serialization work internally?
- What are the limitations or drawbacks of Java serialization?
- How do you implement custom serialization in Java?
- What is the JavReflection, and how is it used?
- What are the security risks of using reflection?
- How do you profile a Java application for performance issues?
- What are the most common performance bottlenecks in a Java?
- What tools can you use the monitor JVM performance?
- What is escapanalysis,is and how does it relate to object inlining?
- How do you implement a thread safe Singleton in Java?
- Explain class loader mechanism and hierarchy in Java?