Java Interview Questions Are Commonly Asked In Google Technical Interviews For Freshers To Test Programming Knowledge, Logical Thinking, And Problem-Solving Skills. These Questions Usually Cover Core Java Concepts Such As OOPs, Strings, Arrays, Collections, Exception Handling, Multithreading, And Basic Coding Problems. Candidates Are Also Expected To Understand Data Structures, Algorithms, And Java Syntax Clearly. Preparing Frequently Asked Java Interview Questions Helps Freshers Improve Confidence And Perform Better In Technical And Coding Rounds. Strong Practice In Simple Programs And Real-Time Scenarios Increases The Chances Of Getting Selected In Top IT Companies.
1. What is Java?
Ans:
Java is a high-level, object-oriented programming language. It is designed to be platform independent using the WORA principle. Java code is compiled into bytecode which runs on JVM. It supports features like multithreading and memory management. It is widely used in web, mobile, and enterprise applications. Java is known for its security, portability, and robustness. It helps developers build scalable applications. Java has a strong standard library and ecosystem. It is continuously updated with new features.
2. What is JVM?
Ans:
JVM stands for Java Virtual Machine and is a core part of Java. It is responsible for executing Java bytecode on any platform. JVM converts bytecode into machine-specific instructions. It provides platform independence to Java programs. It manages memory through heap, stack, and garbage collection. It includes components like class loader and execution engine. JVM is part of the JRE environment. It ensures secure execution of Java applications. It optimizes performance through runtime management.
3. What is JDK?
Ans:
JDK stands for Java Development Kit and is used for Java development. It contains tools required to write, compile, and debug Java programs. JDK includes JRE, compiler, and development utilities. It helps developers build and run Java applications. It is platform dependent in nature. It provides everything needed for Java programming. JDK is essential for software development in Java. It also includes documentation tools for developers. It supports different Java versions and updates.
4. What is JRE?
Ans:
JRE stands for Java Runtime Environment used for running Java programs. It provides libraries and JVM required for execution. It does not include development tools like compiler. JRE is only used to run already compiled Java applications. It contains core class libraries and supporting files. It is part of the JDK package. JRE enables Java program execution. It ensures smooth runtime environment for applications. It is required on any machine running Java programs.
5. What is OOP in Java?
Ans:
OOP stands for Object-Oriented Programming used in Java. It is based on objects and classes concept. It includes four main principles like encapsulation, inheritance, polymorphism, and abstraction. OOP helps in code reusability and modular design. It represents real-world entities in programming. Java is fully based on OOP concepts. It improves maintainability and scalability of code. It makes complex systems easier to manage. It is widely used in modern software development.
6. What is Inheritance?
Ans:
Inheritance is a feature where one class acquires properties of another class. It helps in code reusability and reduces duplication. It is implemented using the extends keyword in Java. It supports relationships like single, multilevel, and hierarchical inheritance. It allows parent-child class relationships. It improves code structure and extensibility. It is an important concept of OOP. It helps achieve runtime polymorphism. It reduces maintenance effort in large projects.
7. What is Polymorphism?
Ans:
Polymorphism means one action having many forms in Java. It allows method overloading and method overriding. It improves flexibility and reusability of code. Compile-time polymorphism is achieved through overloading. Runtime polymorphism is achieved through overriding. It helps in designing flexible applications. It is a key feature of OOP. It supports dynamic method dispatch. It improves code readability and scalability.
8. What is Encapsulation?
Ans:
Encapsulation is the process of wrapping data and methods together. It is achieved using private variables and public getter/setter methods. It protects data from direct access and unauthorized modification. It improves security and data hiding. It makes code more maintainable and controlled. It is a fundamental concept of OOP. Encapsulation ensures better data management. It helps in achieving loose coupling. It improves code reusability and flexibility.
9. Write A Program To Check Whether A Number Is Even Or Odd?
Ans:
This program checks whether a number is even or odd using the modulus operator. If the number is divisible by 2, it prints “Even”. Otherwise, it prints “Odd”. It is one of the most common Java interview questions for freshers. This question helps interviewers understand basic conditional statements and logical thinking. It is simple but important for programming fundamental.
- int num = 8;
- if(num % 2 == 0)
- System.out.println(“Even”);
- else
- System.out.println(“Odd”);
10. What is Interface in Java?
Ans:
An interface is a blueprint of a class in Java. It contains abstract methods by default. It is used to achieve abstraction and multiple inheritance. It is implemented using the implements keyword. It defines a contract that classes must follow. Java 8 introduced default and static methods in interfaces. It improves modular and flexible design. It supports loose coupling in applications. It is widely used in framework-based development.
11. What is Method Overloading in Java?
Ans:
Method overloading means defining multiple methods with the same name. It is done by changing the number or type of parameters. It improves code readability and reusability. It is an example of compile-time polymorphism. It occurs within the same class. Return type can be same or different. It helps in performing similar operations in different ways. It makes code flexible and clean. It is resolved at compile time. It increases program clarity and reduces duplication. It is widely used in real-world Java applications.
12. What is Method Overriding in Java?
Ans:
Method overriding occurs when subclass provides specific implementation. It uses the same method name and parameters as parent class. It is an example of runtime polymorphism. It requires inheritance between classes. It improves flexibility and dynamic behavior. The @Override annotation is commonly used. It helps achieve method customization. It is resolved at runtime. It supports dynamic method dispatch. It allows runtime decision-making in programs. It enhances extensibility of Java applications.
13. What is Constructor in Java?
Ans:
Constructor is a special method used to initialize objects. It has the same name as class. It does not have a return type. It is automatically called when object is created. It can be parameterized or non-parameterized. It helps in initializing variables. Constructor overloading is also possible. It is used for object setup. It improves code initialization process. It ensures proper object state creation. It simplifies object creation logic.
14. What is Garbage Collection in Java?
Ans:
Garbage collection is automatic memory management in Java. It removes unused objects from memory. It helps free heap memory automatically. JVM runs garbage collector internally. Developers do not need manual memory deallocation. It improves application performance and stability. System.gc() can request garbage collection. It prevents memory leaks. It is a core JVM feature. It optimizes memory usage efficiently. It enhances overall application performance.
15. What is Exception Handling in Java?
Ans:
Exception handling is used to handle runtime errors. It prevents program abnormal termination. It uses try, catch, finally blocks. It helps maintain normal program flow. It handles checked and unchecked exceptions. throw and throws keywords are used. It improves application reliability. It helps in debugging errors. It is essential for robust applications. It increases fault tolerance in programs. It ensures smooth user experience
16. What is Array in Java?
Ans:
Array is a data structure that stores multiple values. All elements are of same data type. It has fixed size in Java. Indexing starts from zero. It improves data management efficiency. It can be single or multi-dimensional. Arrays are objects in Java. They are stored in contiguous memory. They are widely used in programming. It allows fast element access using index. It simplifies handling multiple values.
17. What is String in Java?
Ans:
String is a sequence of characters. It is an immutable object in Java. It is stored in String pool for optimization. String class is part of java.lang package. It provides many built-in methods. String objects cannot be modified after creation. StringBuilder and StringBuffer are alternatives. It is widely used in applications. It supports efficient text handling. It ensures memory optimization in Java. It is heavily used in input/output operations.
18. What is StringBuilder in Java?
Ans:
StringBuilder is used to create mutable strings. It is faster than StringBuffer in single-threaded environments. It allows modification of string content. It provides methods like append and insert. It is not synchronized. It improves performance in string manipulation. It is used in dynamic string creation. It belongs to java.lang package. It is efficient for frequent modifications. It reduces memory overhead. It is preferred for non-thread-safe operations.
19. What is StringBuffer in Java?
Ans:
StringBuffer is a mutable string class in Java. It is thread-safe and synchronized. It is slower than StringBuilder. It allows modification of string content. It provides append, insert, delete methods. It is used in multithreaded environments. It ensures data consistency. It belongs to java.lang package. It is suitable for safe string operations. It guarantees thread safety in concurrent programs. It is used in legacy applications.
20. Difference Between JVM and JRE?
Ans:
| Feature | JVM (Java Virtual Machine) | JRE (Java Runtime Environment) |
|---|---|---|
| Definition | JVM is a virtual machine that executes Java bytecode into machine code | JRE is a runtime environment that provides libraries and JVM to run Java programs |
| Purpose | JVM is responsible for executing Java programs | JRE provides environment to run Java applications |
| Purpose | JVM is responsible for executing Java programs | JRE provides environment to run Java applications |
| Components | Includes class loader, execution engine, and garbage collector | Includes JVM, core libraries, and supporting files |
21. What is Thread in Java?
Ans:
Thread is a lightweight unit of execution in Java. It is used for performing multiple tasks simultaneously. Threads run independently within a process. It can be created using Thread class or Runnable interface. It helps improve application performance. It shares memory with other threads. It is a key part of multithreading. Threads reduce execution time in programs. It enables parallel processing. It improves CPU utilization. It is widely used in real-time systems. It supports concurrent execution of tasks. It enhances responsiveness in applications.
22. What is Synchronization in Java?
Ans:
Synchronization is used to control access to shared resources. It prevents thread interference and data inconsistency. It ensures one thread accesses resource at a time. It uses synchronized keyword. It can be applied to methods or blocks. It is used in multithreaded applications. It prevents race conditions. It ensures thread safety. It improves data integrity. It may reduce performance due to locking. It is essential for shared data handling. It ensures consistency in concurrent execution. It avoids unpredictable thread behavior.
23. What is Collection Framework in Java?
Ans:
Collection Framework is a set of classes and interfaces. It is used to store and manipulate data. It includes List, Set, and Queue interfaces. It provides ready-made data structures. It improves programming efficiency. It is part of java.util package. It supports dynamic storage. It reduces programming complexity. It provides sorting and searching support. It is highly optimized. It is widely used in real applications. It standardizes data handling in Java. It improves code reusability.
24. What is List in Java Collections?
Ans:
List is an ordered collection in Java. It allows duplicate elements. It maintains insertion order. It is part of Collection Framework. It includes ArrayList, LinkedList, Vector. It supports index-based access. It is dynamic in size. It allows easy data manipulation. It is widely used in applications. It provides flexible data storage. It is useful for sequential data handling. It allows positional access of elements. It supports easy iteration.
25. What is ArrayList in Java?
Ans:
ArrayList is a resizable array implementation. It is part of java.util package. It allows dynamic memory allocation. It supports fast random access. It is not synchronized. It allows duplicate elements. It grows automatically when needed. It is widely used in applications. It is better than arrays in flexibility. It uses index-based storage. It is efficient for reading operations. It provides dynamic resizing capability. It improves collection handling.
26. Write A Program To Find The Largest Number In An Array?
Ans:
This program finds the largest element in an array using a loop. It compares each element with the current maximum value. If a larger value is found, it updates the maximum number. This question is frequently asked in Google Java interviews for freshers. It tests array handling, loops, and comparison logic. It also improves problem-solving and coding skills.
- int arr[] = {10, 45, 22, 89};
- int max = arr[0];
- for(int i = 1; i < arr.length; i++)
- {
- if(arr[i] > max)
- max = arr[i];
- }
- System.out.println(max);
27. What is HashSet in Java?
Ans:
HashSet stores unique elements only. It does not allow duplicates. It does not maintain order. It is part of Set interface. It uses hashing mechanism. It provides constant-time performance. It allows null value. It is not synchronized. It is used for fast lookup operations. It is widely used in data processing. It ensures uniqueness of elements. It improves performance for search operations. It is useful in removing duplicates.
28. What is TreeSet in Java?
Ans:
- TreeSet stores elements in sorted order. It does not allow duplicates. It is part of Set interface. It uses Red-Black Tree structure. It provides ascending order storage.
- It is slower than HashSet. It does not allow null values. It is useful for sorting data. It supports navigation methods. It is used in ordered data handling.
- It ensures natural ordering. It provides automatic sorting of elements. It is useful in range-based operations.
29. What is HashMap in Java?
Ans:
HashMap stores data in key-value pairs. Keys are unique while values can duplicate. It does not maintain order. It allows one null key. It provides fast retrieval. It is not synchronized. It uses hashing technique. It is part of java.util package. It is widely used in caching. It offers constant-time performance. It is highly efficient for lookups. It improves data retrieval speed. It supports quick insertion operations.
30. What is TreeMap in Java?
Ans:
- TreeMap stores key-value pairs in sorted order. It is based on Red-Black Tree. It does not allow null keys. It maintains ascending order of keys.
- It is slower than HashMap. It is part of SortedMap interface. It provides navigation methods. It is useful for sorted data storage.
- It ensures ordered key management. It is used in real-time sorting applications. It improves data organization. It supports range-based queries. It ensures automatic key sorting.
31. What is Queue in Java?
Ans:
Queue is a linear data structure. It follows FIFO (First In First Out). It is part of Collection Framework. It supports insertion and deletion. It is used in scheduling tasks. It includes PriorityQueue and LinkedList. It is useful for processing order. It is widely used in systems. It supports real-time processing. It improves task management. It is efficient for sequential operations. It ensures ordered processing of elements. It is used in job scheduling systems.
32. What is PriorityQueue in Java?
Ans:
PriorityQueue orders elements based on priority. It does not follow FIFO strictly. It is part of java.util package. It uses heap data structure. It stores elements in sorted order. It does not allow null values. It is not synchronized. It is used in scheduling systems. It improves task prioritization. It is efficient for priority-based processing. It is widely used in algorithms. It ensures highest priority execution first. It supports efficient heap operations.
33. What is Stack in Java?
Ans:
Stack follows LIFO principle. It stands for Last In First Out. It is part of java.util package. It supports push and pop operations. It is used in recursion and undo operations. It extends Vector class. It stores elements vertically. It allows access to top element only. It is useful in expression evaluation. It supports memory stack operations. It is widely used in programming. It helps in backtracking algorithms. It manages function call execution.
34. What is Exception in Java?
Ans:
Exception is an event that disrupts program flow. It occurs during runtime. It can be handled using try-catch. It prevents program crash. It is part of java.lang package. It includes checked and unchecked types. It improves program reliability. It helps in error handling. It can be custom or predefined. It ensures smooth execution. It is essential for robust applications. It improves fault tolerance. It ensures controlled error handling.
35. What is Checked Exception?
Ans:
Checked exceptions are compile-time exceptions. They must be handled explicitly. They are checked by compiler. Examples include IOException, SQLException. They use try-catch or throws keyword. They ensure error handling at compile time. They improve program safety. They are predictable errors. They force developers to handle exceptions. They are part of Java exception hierarchy. They ensure reliable code execution. They improve application stability. They reduce runtime failures.
36. What is Unchecked Exception?
Ans:
Unchecked exceptions occur at runtime. They are not checked by compiler. Examples include NullPointerException, ArithmeticException. They extend RuntimeException class. They occur due to programming errors. They do not require handling. They are difficult to predict. They cause program crash. They are avoided using proper logic. They are part of runtime issues. They require careful coding practices. They indicate logical mistakes. They are detected during execution.
37. What is try-catch block?
Ans:
Try-catch block is used for exception handling. try block contains risky code. catch block handles exceptions. It prevents program termination. Multiple catch blocks are allowed. It improves program stability. It handles runtime errors. It ensures smooth execution. finally block can be used. It is essential for error handling. It improves reliability of programs. It separates error handling logic. It improves debugging process.
38. What is finally block in Java?
Ans:
finally block executes always. It runs whether exception occurs or not. It is used for cleanup activities. It is used after try-catch. It closes resources like files. It ensures resource release. It improves memory management. It is optional but recommended. It executes even after return statement. It guarantees execution of code. It is part of exception handling. It ensures proper resource handling. It avoids memory leaks.
39. What is throw keyword in Java?
Ans:
Throw keyword is used to explicitly throw exception. It is used inside method. It throws a single exception. It is followed by exception object. It is used for custom errors. It transfers control to catch block. It improves error handling control. It is used in validation. It helps enforce rules. It is part of exception mechanism. It is used for manual exception generation. It allows custom error reporting. It improves control over exceptions.
40. What is throws keyword in Java?
Ans:
- Throws keyword declares exceptions in method signature. It indicates possible exceptions. It is used for checked exceptions. It shifts responsibility to caller.
- It improves method transparency. It allows multiple exceptions. It is used in method declaration. It helps in compile-time handling.
- It is part of exception handling. It avoids immediate handling. It improves code structure. It separates error responsibility. It improves API clarity.
41. What is File Handling in Java?
Ans:
File handling is used to work with files. It allows reading and writing data. It uses classes like File, FileReader, FileWriter. It is part of java.io package. It helps store persistent data. It supports text and binary files. It is used in real-world applications. It enables data storage. It improves data management. It supports file manipulation. It is essential for storage operations. It enables permanent data storage. It supports external file interaction.
42. What is File Class in Java?
Ans:
File class represents file and directory path. It is used for file operations. It does not read or write data. It provides file metadata. It is part of java.io package. It supports create, delete, rename operations. It checks file existence. It manages directory structure. It is used for file management. It improves file handling operations. It is widely used in Java IO. It provides file path abstraction. It simplifies file operations.
43. Write A Program To Reverse A String
Ans:
This program reverses a string by reading characters from the end to the beginning. The reversed characters are stored in another string variable. String manipulation questions are very common in technical interviews. This question checks knowledge of loops, strings, and character operations. It is important for beginners preparing for coding interviews. It also helps in understanding indexing concepts in Java.
- String str = “Google”;
- String rev = “”;
- for(int i = str.length()-1; i >= 0; i–)
- {
- rev = rev + str.charAt(i);
- }
- System.out.println(rev);
44. What is FileWriter in Java?
Ans:
FileWriter is used to write character data. It writes data into files. It is part of java.io package. It is used for text output. It can overwrite existing files. It supports append mode. It throws IOException. It is used for file creation. It simplifies file writing. It is widely used in logging. It helps store output data. It enables file writing operations. It supports sequential writing.
45. What is BufferedReader in Java?
Ans:
BufferedReader reads text efficiently. It reads data line by line. It improves reading performance. It is part of java.io package. It uses buffering mechanism. It is faster than FileReader. It supports readLine method. It is used in large file reading. It reduces I/O operations. It improves efficiency. It is widely used in Java IO. It reduces system calls. It improves input performance.
46. What is BufferedWriter in Java?
Ans:
BufferedWriter writes text efficiently. It uses buffering mechanism. It improves performance of writing. It reduces number of I/O operations. It is part of java.io package. It supports newLine method. It is used for large file writing. It is faster than FileWriter. It stores data in buffer. It improves file writing efficiency. It is widely used in applications. It reduces disk access. It improves output speed.
47. What is Serialization in Java?
Ans:
Serialization converts object into byte stream. It is used to save object state. It helps in file storage and networking. It uses ObjectOutputStream class. It requires Serializable interface. It enables object persistence. It supports object transmission. It improves data storage. It is used in distributed systems. It allows object reconstruction. It is important for data transfer. It enables object saving. It supports system communication.
48. What is Deserialization in Java?
Ans:
- Deserialization converts byte stream into object. It restores object state. It uses ObjectInputStream class. It is reverse of serialization.
- It reconstructs saved objects. It requires Serializable interface. It is used in file reading. It helps retrieve stored data. It is used in networking.
- It improves data recovery. It is important for object reconstruction. It enables object restoration. It supports data retrieval.
49. What is Wrapper Class in Java?
Ans:
Wrapper classes convert primitives into objects. Examples include Integer, Double, Character. They are part of java.lang package. They support collections framework. They provide utility methods. They enable autoboxing and unboxing. They improve object handling. They allow null values. They are used in generic programming. They help in data conversion. They improve flexibility. It enables object-based operations. It supports Java collections
50. What is Autoboxing in Java?
Ans:
Autoboxing converts primitive to object automatically. It is done by compiler. Example: int to Integer. It simplifies coding. It is part of wrapper classes. It improves readability. It reduces manual conversion. It is used in collections. It supports seamless integration. It is opposite of unboxing. It improves Java efficiency. It simplifies developer effort. It reduces boilerplate code.
51. What is Unboxing in Java?
Ans:
Unboxing converts object to primitive. It is automatic process. Example: Integer to int. It is handled by compiler. It improves performance. It simplifies coding. It is reverse of autoboxing. It is used in arithmetic operations. It supports wrapper classes. It reduces complexity. It improves code efficiency. It enables direct operations. It improves execution speed.

52. What is Comparable Interface?
Ans:
Comparable interface is used for sorting objects. It defines natural ordering. It uses compareTo method. It is part of java.lang package. It allows object comparison. It is used in sorting collections. It is implemented in class. It supports single sorting logic. It improves sorting behavior. It is widely used in TreeSet. It helps in ordered data. It defines default sorting logic. It improves collection ordering.
53. What is Comparator Interface?
Ans:
Comparator interface is used for custom sorting. It defines compare method. It is part of java.util package. It allows multiple sorting logic. It is used externally to class. It supports flexible sorting. It is used in collections sorting. It improves sorting control. It supports lambda expressions. It is useful in advanced sorting. It enhances flexibility. It enables dynamic sorting logic. It supports multiple criteria sorting.
54. What is Lambda Expression in Java?
Ans:
Lambda expression is a short block of code. It is used in functional programming. It simplifies anonymous classes. It is introduced in Java 8. It improves code readability. It works with functional interfaces. It reduces boilerplate code. It uses arrow notation. It is used in streams. It improves modern Java programming. It enhances code simplicity. It supports concise coding. It improves functional style programming.
55. What is Stream API in Java?
Ans:
Stream API is used for processing collections. It supports functional programming. It allows filtering and mapping. It is introduced in Java 8. It improves data processing. It does not modify original data. It supports parallel processing. It uses pipelines. It improves performance. It simplifies collection operations. It is widely used in modern Java. It enables declarative programming. It improves readability of logic.
56. Write A Program To Check Whether A Number Is Prime?
Ans:
This program checks whether a number is prime or not. A prime number is divisible only by 1 and itself. The loop checks divisibility from 2 to the given number minus one. If divisible, the program marks it as not prime. This is a popular interview question asked in Google and other top companies. It tests loops, conditions, and mathematical logic.
- int num = 7;
- boolean prime = true;
- for(int i = 2; i < num; i++)
- {
- if(num % i == 0)
- {
- prime = false;
- break;
- }
- }
- if(prime)
- System.out.println(“Prime”);
- else
- System.out.println(“Not Prime”);
57. What is Enum in Java?
Ans:
Enum represents fixed set of constants. It is a special data type. It improves type safety. It is used for predefined values. It is part of java.lang package. It can have methods and variables. It improves code readability. It is used in switch statements. It is memory efficient. It replaces static final constants. It is widely used in applications. It ensures fixed value sets. It improves program structure.
58. What is Inner Class in Java?
Ans:
Inner class is a class inside another class. It improves encapsulation. It has access to outer class members. It is useful for logical grouping. It can be static or non-static. It improves code readability. It helps in better organization. It reduces class clutter. It is used in event handling. It improves modularity. It supports better structure. It enhances code encapsulation. It improves logical grouping.
59. What is Static Keyword in Java?
Ans:
- Static keyword is used for memory management. It belongs to class not object. It is used for variables and methods.
- It allows shared data among objects. It is loaded once in memory. It improves performance. It can be accessed without object.
- It is used in utility methods. It belongs to class level. It reduces memory usage. It is widely used in Java. It enables shared resources. It improves efficiency
60. Difference Between throw and throws in Java?
Ans:
| Feature | throw | throws |
|---|---|---|
| Definition | throw is used to explicitly throw an exception | throws is used to declare exceptions in method signature |
| Usage | Used inside method body | Used in method declaration |
| Number of Exceptions | Can throw only one exception at a time | Can declare multiple exceptions |
| Type of Exception | Used for both checked and unchecked exceptions | Mainly used for checked exceptions |
61. What is ClassLoader in Java?
Ans:
ClassLoader is a subsystem of JVM used to load classes. It loads class files into memory. It follows delegation hierarchy model. It includes Bootstrap, Extension, and Application ClassLoader. It loads classes dynamically at runtime. It helps in modular application design. It prevents duplicate class loading. It improves security of Java applications. It is part of JVM architecture. It manages class loading process. It supports runtime flexibility. It is essential for Java execution.
62. What is JVM Memory Structure?
Ans:
JVM memory is divided into Heap, Stack, and Method Area. Heap stores objects and runtime data. Stack stores method calls and local variables. Method area stores class-level information. Each thread has its own stack. Heap is shared among threads. Garbage collection works on heap. It ensures efficient memory usage. It prevents memory leaks. It supports dynamic allocation. It is managed by JVM automatically. It is critical for performance.
63. What is Heap in Java?
Ans:
Heap is memory area used for object storage. It is shared among all threads. It is managed by garbage collector. It stores runtime objects and arrays. It is divided into Young and Old generation. It supports dynamic memory allocation. It is slower than stack. It is essential for object creation. It may cause memory leaks if misused. It is automatically managed. It is key part of JVM memory. It supports runtime object management.
64. What is Stack Memory in Java?
Ans:
Stack memory stores method execution details. It contains local variables and method calls. Each thread has its own stack. It follows LIFO principle. It is automatically managed. It is faster than heap memory. It stores temporary data. It is cleared after method execution. It prevents memory overhead. It supports execution flow. It is essential for function calls. It is critical for runtime execution.
65. What is Garbage Collector in Java?
Ans:
- Garbage Collector removes unused objects. It automatically frees heap memory. It improves memory management. It is part of JVM.
- It runs in background. It uses algorithms like Mark and Sweep. It prevents memory leaks. It optimizes performance.
- It cannot be controlled directly. System.gc() requests GC. It improves application stability. It is essential for Java runtime.
66. What is Deep Copy vs Shallow Copy?
Ans:
- Shallow copy copies object references. Deep copy creates independent objects. Shallow copy shares memory. Deep copy duplicates entire object structure.
- Shallow copy is faster. Deep copy is memory expensive. Shallow copy affects original object. Deep copy does not affect original.
- Shallow copy is default behavior. Deep copy requires manual implementation. It is important in object cloning. It affects data integrity
67. What is Object Cloning in Java?
Ans:
Object cloning creates copy of object. It uses clone() method. It is defined in Object class. It requires Cloneable interface. It can be shallow or deep. It improves object duplication. It avoids constructor usage. It is used in object replication. It may throw CloneNotSupportedException. It is faster than manual copying. It is used in design patterns. It is useful in performance optimization.
68. What is Dependency Injection in Java?
Ans:
Dependency Injection provides object dependencies externally. It reduces tight coupling. It improves code flexibility. It is used in Spring Framework. It supports constructor and setter injection. It improves testability. It promotes loose coupling. It separates object creation. It enhances maintainability. It is widely used in enterprise apps. It improves design structure. It supports scalable architecture. It enables inversion of control concept.
69. What is Tight Coupling?
Ans:
Tight coupling means classes depend heavily on each other. Changes in one class affect others. It reduces flexibility. It makes testing difficult. It increases code dependency. It is not recommended in design. It reduces reusability. It makes maintenance hard. It violates modular design. It is opposite of loose coupling. It increases system complexity. It should be avoided. It makes systems rigid and hard to extend.
70. What is Loose Coupling?
Ans:
Loose coupling means minimal dependency between classes. It improves flexibility and maintainability. It uses interfaces for abstraction. It supports independent modules. It makes testing easier. It is used in modern design. It improves scalability. It reduces system complexity. It supports dependency injection. It is widely used in frameworks. It improves code reusability. It is best practice in Java. It supports modular software architecture.
71. What is Singleton Class?
Ans:
Singleton class allows only one object. It provides global access point. It uses private constructor. It uses static instance. It ensures single instance creation. It saves memory. It is used in logging systems. It is used in configuration classes. It is thread-safe in advanced versions. It is design pattern. It controls object creation. It improves resource management. It ensures controlled instance creation.

72.Write A Program To Find The Factorial Of A Number?
Ans:
This program calculates the factorial of a number using a loop. Factorial means multiplying all numbers from 1 to the given number. For example, factorial of 5 is 120. This question is commonly asked in fresher interviews to test loop concepts and arithmetic operations. It also helps interviewers understand logical implementation skills. It is a basic but important coding problem in Java.
- int num = 5;
- int fact = 1;
- for(int i = 1; i <= num; i++)
- {
- fact = fact * i;
- }
- System.out.println(fact);
73. What is Abstract Class in Java?
Ans:
Abstract class cannot be instantiated. It may contain abstract and concrete methods. It is used for partial abstraction. It is extended using extends keyword. It provides base class structure. It supports code reuse. It can have constructors. It is used in inheritance. It is part of OOP. It defines common behavior. It improves code organization. It is widely used in design. It provides template for subclasses.
74. Abstract Class vs Interface?
Ans:
- Abstract class can have implemented methods. Interface has only abstract methods (before Java 8). Abstract class supports constructors.
- Interface does not support constructors. Abstract class supports single inheritance. Interface supports multiple inheritance. Abstract class is partially abstract.
- Interface is fully abstract. Abstract class is faster. Interface is more flexible. Both support abstraction. Both are used in design. Both help achieve abstraction differently.
75. What is Marker Interface?
Ans:
Marker interface has no methods. It is used for signaling purpose. Example: Serializable interface. It provides metadata to JVM. It enables special behavior. It is used in serialization. It improves type safety. It is part of design. It does not contain logic. It is a tagging interface. It is used in Java frameworks. It marks class capabilities. It helps JVM identify special behavior.
76. What is Reflection in Java?
Ans:
Reflection allows runtime inspection of classes. It can access private members. It is part of java.lang.reflect package. It is used in frameworks. It allows dynamic class loading. It improves flexibility. It is used in testing tools. It can modify behavior at runtime. It is powerful but slow. It breaks encapsulation. It is used in Spring framework. It supports runtime analysis. It enables dynamic code inspection.
77. What is Garbage Collection Tuning?
Ans:
GC tuning improves memory performance. It adjusts heap size. It selects GC algorithms. It reduces pause time. It improves application speed. It is used in large systems. It optimizes JVM performance. It prevents memory issues. It is used in production systems. It requires JVM arguments. It improves scalability. It is advanced JVM optimization. It helps fine-tune memory behavior.
78. What is Race Condition?
Ans:
Race condition occurs in multithreading. Multiple threads access shared data. It causes inconsistent results. It happens without synchronization. It leads to unpredictable behavior. It affects data integrity. It is a concurrency problem. It is fixed using synchronization. It is hard to debug. It is common in parallel systems. It reduces reliability. It must be avoided. It leads to unstable application behavior.
79. What is Deadlock in Java?
Ans:
Deadlock occurs when threads wait forever. Each thread holds resource and waits. It blocks program execution. It happens in multithreading. It causes system freeze. It is difficult to detect. It occurs due to poor locking. It reduces performance. It requires careful design. It can be avoided using ordering. It is critical issue in concurrency. It must be prevented. It stops system progress completely.
80. What is Thread Pool?
Ans:
Thread pool manages multiple threads. It reuses existing threads. It improves performance. It reduces thread creation overhead. It is part of Executor framework. It is used in server apps. It manages tasks efficiently. It improves scalability. It controls resource usage. It prevents system overload. It is widely used in Java. It enhances multithreading performance. It optimizes resource utilization.
81. What is Executor Framework?
Ans:
Executor framework manages thread execution. It separates task submission and execution. It provides thread pool management. It improves concurrency handling. It is part of java.util.concurrent. It simplifies multithreading. It supports asynchronous tasks. It improves performance. It reduces complexity. It is used in real systems. It replaces manual thread management. It is modern Java approach. It improves structured concurrency handling
82. What is Callable vs Runnable?
Ans:
Runnable does not return result. Callable returns result. Runnable cannot throw checked exception. Callable can throw exception. Runnable uses run method. Callable uses call method. Runnable is simpler. Callable is advanced. Runnable used in threads. Callable used in ExecutorService. Callable supports Future object. It is more powerful. Callable supports return-based execution.
83. What is Future in Java?
Ans:
- Future represents result of async computation. It is used with Callable. It stores pending result. It allows checking completion.
- It supports cancellation. It blocks until result available. It improves async programming. It is part of concurrency package. It provides get() method.
- It handles background tasks. It improves performance. It is used in thread pools. It enables asynchronous result handling.
84. What is volatile keyword?
Ans:
Volatile ensures visibility across threads. It prevents caching issues. It ensures latest value access. It is used in multithreading. It does not provide atomicity. It avoids stale data. It is lighter than synchronization. It improves thread communication. It is used in flags. It ensures memory consistency. It is JVM feature. It improves reliability. It ensures thread visibility guarantees.
85. What is Atomic Class in Java?
Ans:
Atomic classes provide thread-safe operations. They use lock-free mechanism. Example: AtomicInteger. They improve performance. They are in java.util.concurrent.atomic. They ensure atomic updates. They avoid synchronization overhead. They are used in counters. They improve concurrency. They are highly efficient. They prevent race conditions. They support atomic operations. They enable lock-free programming.
86. Write A Program To Check Whether A String Is Palindrome?
Ans:
This program checks whether a string is a palindrome. A palindrome reads the same forward and backward. The program first reverses the string and then compares it with the original string. If both are equal, it prints “Palindrome”. This is one of the most asked Java interview questions for freshers in Google interviews. It tests string handling, loops, and comparison methods in Java.
- String str = “madam”;
- String rev = “”;
- for(int i = str.length()-1; i >= 0; i–)
- {
- rev = rev + str.charAt(i);
- }
- if(str.equals(rev))
- System.out.println(“Palindrome”);
- else
- System.out.println(“Not Palindrome”);
87. What is Fail-Safe Iterator?
Ans:
Fail-safe iterator does not throw exception. It works on cloned collection. It is thread-safe. It is used in concurrent collections. It does not reflect changes immediately. It uses copy mechanism. It is slower than fail-fast. It avoids ConcurrentModificationException. It is used in CopyOnWriteArrayList. It improves safety. It is used in multithreading. It ensures stability. It supports safe concurrent iteration.
88. What is CopyOnWriteArrayList?
Ans:
CopyOnWriteArrayList is thread-safe list. It creates copy on modification. It is part of concurrent package. It allows safe iteration. It is slower for writes. It is fast for reads. It avoids locking. It is used in multithreading. It prevents concurrency issues. It is fail-safe. It is used in real-time systems. It improves thread safety. It ensures safe read-heavy operations.
89. What is ConcurrentHashMap?
Ans:
ConcurrentHashMap is thread-safe map. It allows concurrent access. It improves performance. It uses segment locking. It does not allow null keys. It is part of concurrent package. It is faster than HashMap. It supports multithreading. It avoids full locking. It improves scalability. It is widely used. It ensures thread safety. It supports high concurrency access.
90. What is BlockingQueue?
Ans:
- BlockingQueue supports thread-safe queue. It blocks when full or empty. It is used in producer-consumer.
- It is part of concurrent package. It supports FIFO ordering. It prevents data loss. It improves synchronization. It supports multithreading.
- It includes ArrayBlockingQueue. It is widely used in systems. It improves task handling. It ensures safe communication. It supports thread coordination.
91. What is Producer-Consumer Problem?
Ans:
Producer-consumer is concurrency problem. Producer generates data. Consumer consumes data. It uses shared buffer. It requires synchronization. It uses BlockingQueue solution. It avoids data inconsistency. It is classic threading problem. It improves resource sharing. It prevents race conditions. It is used in real systems. It improves coordination. It models real-world data flow.
92. What is JVM Internals?
Ans:
JVM internals include class loader, memory, execution engine. It converts bytecode to machine code. It manages runtime memory. It handles garbage collection. It ensures platform independence. It executes Java programs. It manages threads. It optimizes performance. It provides security. It is core of Java. It supports runtime execution. It is essential component. It defines Java runtime behavior.
93. What is Just-In-Time Compiler?
Ans:
JIT compiler improves performance. It converts bytecode to native code. It works at runtime. It reduces execution time. It is part of JVM. It optimizes repeated code. It improves speed. It uses runtime profiling. It enhances efficiency. It is used in execution engine. It is key JVM feature. It boosts performance. It dynamically optimizes execution.
94. What is String Pool?
Ans:
String pool stores string literals. It saves memory. It is part of heap memory. It avoids duplicate objects. It improves performance. It is immutable storage. It is managed by JVM. It reuses strings. It reduces memory usage. It improves efficiency. It is widely used. It optimizes string handling. It enables memory optimization for strings.
95. What is Heap Dump?
Ans:
Heap dump is snapshot of memory. It shows object allocation. It is used for debugging. It detects memory leaks. It is generated by JVM. It helps in analysis. It is used in performance tuning. It stores heap state. It is used in production issues. It is analyzed using tools. It improves debugging. It is critical for optimization. It helps identify memory problems.
96. What is Memory Leak in Java?
Ans:
- Memory leak occurs when objects not freed. It consumes heap memory. It reduces performance.
- It causes OutOfMemoryError. It happens due to references. It is hard to detect. It affects applications. It slows system.
- It is prevented by GC awareness. It is serious issue. It impacts scalability. It must be avoided. It degrades long-running applications.
97. What is OutOfMemoryError?
Ans:
- OutOfMemoryError occurs when heap is full. JVM cannot allocate memory. It stops application execution. It is runtime error.
- It occurs due to leaks. It affects performance. It requires memory tuning. It is critical issue. It happens in large apps.
- It is hard to recover. It needs debugging. It requires optimization. It indicates JVM memory exhaustion.
98. What is Microservices in Java?
Ans:
Microservices break application into services. Each service runs independently. It improves scalability. It is used in modern systems. It uses REST APIs. It supports cloud deployment. It improves flexibility. It allows independent updates. It reduces complexity. It is widely used in industry. It supports distributed systems. It improves maintainability. It enables scalable system design.
99. What is Spring Boot (basic concept)?
Ans:
Spring Boot simplifies Java development. It reduces configuration. It provides auto-configuration. It is used for microservices. It includes embedded server. It improves productivity. It is part of Spring ecosystem. It supports REST APIs. It reduces boilerplate code. It is widely used. It improves deployment speed. It supports production-ready apps. It accelerates enterprise application development.
100. Why Java is used in Google-level companies?
Ans:
Java is platform independent and scalable. It supports large distributed systems. It has strong memory management. It supports multithreading. It is secure and stable. It has rich libraries. It supports high performance systems. It is used in backend services. It integrates with cloud systems. It is widely adopted in enterprises. It is reliable for large scale apps. It ensures maintainability and performance. It powers enterprise-grade backend systems.
LMS
