Q1. What is Java?
Answer: Java is a high-level, object-oriented, platform-independent programming language developed by Sun Microsystems (now owned by Oracle Corporation). It follows the principle of “Write Once, Run Anywhere” (WORA) because Java programs are compiled into bytecode, which can run on any system that has a Java Virtual Machine (JVM).
Q2. What are the main features of Java?
Answer: Java provides several important features:
- Object-Oriented
- Platform Independent
- Secure
- Robust
- Multithreaded
- Distributed
- High Performance (with JIT compiler)
Q3. What is JVM?
Answer: JVM (Java Virtual Machine) is a virtual machine that runs Java bytecode. It converts bytecode into machine-specific instructions and provides memory management, security, and garbage collection.
Q4. What is JDK and JRE?
Answer:
- JDK (Java Development Kit): Contains tools required to develop Java applications (compiler, debugger, etc.).
- JRE (Java Runtime Environment): Contains JVM and libraries required to run Java applications.
Q5. What is Bytecode?
Answer: Bytecode is the intermediate code generated by the Java compiler (.class file). It is platform-independent and executed by the JVM.
Q6. What is Object-Oriented Programming?
Answer: OOP is a programming paradigm based on objects and classes. It includes four main principles: Encapsulation, Abstraction, Inheritance, and Polymorphism.
Q7. What is a Class?
Answer: A class is a blueprint or template used to create objects. It defines properties (variables) and behaviors (methods).
Q8. What is an Object?
Answer: An object is an instance of a class. It contains real values and can call methods defined in the class.
Q9. What is Encapsulation?
Answer: Encapsulation is the process of wrapping data and methods into a single unit (class). It is achieved using private variables and public getter/setter methods.
Q10. What is Inheritance?
Answer: Inheritance allows one class to acquire properties and methods of another class using the extends keyword. It promotes code reuse.
Q11. What is Polymorphism?
Answer: Polymorphism allows methods to perform different tasks based on the object. It is of two types:
- Compile-time Polymorphism (Method Overloading)
- Runtime Polymorphism (Method Overriding)
Q12. What is Abstraction?
Answer: Abstraction hides implementation details and shows only essential features. It is achieved using abstract classes and interfaces.
Q13. What is Method Overloading?
Answer: Method overloading means defining multiple methods with the same name but different parameters within the same class.
Q14. What is Method Overriding?
Answer: Method overriding occurs when a subclass provides a specific implementation of a method already defined in the parent class.
Q15. What is the difference between Overloading and Overriding?
Answer:
- Overloading: Same method name, different parameters, same class.
- Overriding: Same method signature, different implementation, parent-child relationship.
Q16. What is the use of ‘static’ keyword?
Answer: The static keyword is used for memory management. Static variables and methods belong to the class rather than objects.
Q17. What is the use of ‘final’ keyword?
Answer:
- Final variable: Cannot change value.
- Final method: Cannot be overridden.
- Final class: Cannot be inherited.
Q18. What is the use of ‘this’ keyword?
Answer: The ‘this’ keyword refers to the current object of the class.
Q19. What is the use of ‘super’ keyword?
Answer: The ‘super’ keyword refers to the parent class object. It is used to access parent class methods and constructors.
Q20. What is a Constructor?
Answer: A constructor is a special method used to initialize objects. It has the same name as the class and does not have a return type.
Q21. What is String in Java?
Answer: String is a class used to store sequences of characters. Strings are immutable in Java.
Q22. What is the difference between String, StringBuffer, and StringBuilder?
Answer:
- String: Immutable
- StringBuffer: Mutable and thread-safe
- StringBuilder: Mutable and not thread-safe (faster)
Q23. What is an Array?
Answer: An array is a collection of similar data types stored in contiguous memory locations.
Q24. What is Multidimensional Array?
Answer: A multidimensional array is an array of arrays (e.g., 2D array).
Q25. What is the difference between == and equals()?
Answer:
- == compares references (memory address).
- equals() compares actual content.
Q26. What is an Exception?
Answer: An exception is an unwanted event that disrupts normal program flow.
Q27. What is the difference between Checked and Unchecked exceptions?
Answer:
- Checked: Checked at compile-time (e.g., IOException).
- Unchecked: Checked at runtime (e.g., ArithmeticException).
Q28. What is try-catch block?
Answer: It is used to handle exceptions and prevent program termination.
Q29. What is finally block?
Answer: The finally block executes whether an exception occurs or not.
Q30. What is throw and throws?
Answer:
- throw: Used to explicitly throw an exception.
- throws: Declares exceptions in method signature.
Q31. What is a Thread?
Answer: A thread is a lightweight process that allows concurrent execution of code.
Q32. How to create a Thread?
Answer:
- By extending Thread class
- By implementing Runnable interface
Q33. What is Synchronization?
Answer: Synchronization is used to control access of multiple threads to shared resources.
Q34. What is Deadlock?
Answer: Deadlock occurs when two threads wait for each other to release resources.
Q35. What is Thread Lifecycle?
Answer: New → Runnable → Running → Blocked/Waiting → Terminated
7. Collections Framework
Q36. What is Collection Framework?
Answer: It is a set of classes and interfaces used to store and manipulate groups of objects.
Q37. Difference between List and Set?
Answer:
- List: Allows duplicates
- Set: Does not allow duplicates
Q38. What is Map?
Answer: Map stores key-value pairs and does not allow duplicate keys.
Q39. Difference between ArrayList and LinkedList?
Answer:
- ArrayList: Faster for searching
- LinkedList: Faster for insertion/deletion
Q40. What is HashMap?
Answer: HashMap stores key-value pairs using hashing technique and allows one null key.
8. Miscellaneous
Q41. What is Garbage Collection?
Answer: Garbage Collection automatically removes unused objects from memory.
Q42. What is Wrapper Class?
Answer: Wrapper classes convert primitive data types into objects (e.g., int → Integer).
Q43. What is Interface?
Answer: An interface is a blueprint of a class that contains abstract methods.
Q44. Difference between Abstract Class and Interface?
Answer:
- Abstract class can have both abstract and concrete methods.
- Interface contains only abstract methods (before Java 8).
Q45. What is Serialization?
Answer: Serialization is the process of converting an object into byte stream.
Q46. What is Deserialization?
Answer: Deserialization is converting byte stream back to object.
Q47. What is Package in Java?
Answer: A package is a namespace that organizes classes and interfaces.
Q48. What is Access Modifier?
Answer: Access modifiers define visibility of class members (public, private, protected, default).
Q49. What is Java API?
Answer: Java API is a collection of pre-written classes and interfaces provided by Java.
Q50. Why Java is Platform Independent?
Answer: Java is platform independent because it compiles code into bytecode, which runs on JVM available for different operating systems.
Q51. What is Object Cloning in Java?
Answer: Object cloning is the process of creating an exact copy of an existing object. It is achieved using the Cloneable interface and clone() method of the Object class.
Q52. What is the difference between Shallow Copy and Deep Copy?
Answer:
- Shallow Copy: Copies object references, not actual objects.
- Deep Copy: Copies actual objects recursively.
Q53. Can we override static methods?
Answer: No. Static methods belong to the class, not objects. They can be hidden but not overridden.
Q54. Can constructors be inherited?
Answer: No. Constructors are not inherited, but a child class can call the parent constructor using super().
Q55. What is Covariant Return Type?
Answer: Covariant return type allows a subclass to override a method and return a subtype of the original method’s return type.
Q56. What are the main components of JVM memory?
Answer:
- Method Area
- Heap Area
- Stack Area
- Program Counter Register
- Native Method Stack
Q57. What is Heap Memory?
Answer: Heap memory stores objects and instance variables. It is shared among all threads.
Q58. What is Stack Memory?
Answer: Stack memory stores local variables and method calls. Each thread has its own stack.
Q59. What is Garbage Collector?
Answer: Garbage Collector automatically deletes unused objects to free heap memory.
Q60. What is OutOfMemoryError?
Answer: It occurs when JVM cannot allocate memory for an object due to insufficient heap space.
Q61. Why is String immutable?
Answer: String is immutable to ensure security, thread-safety, and performance (string constant pool optimization).
Q62. What is String Constant Pool?
Answer: It is a special memory area in heap where string literals are stored to avoid duplicate objects.
Q63. What is intern() method?
Answer: The intern() method places a string in the string constant pool if not already present.
Q64. Difference between new String() and String literal?
Answer:
new String()creates object in heap.- String literal creates object in String Pool.
Q65. What is StringTokenizer?
Answer: StringTokenizer is a legacy class used to break strings into tokens.
Q66. What is Comparable interface?
Answer: Comparable is used to sort objects naturally using compareTo() method.
Q67. What is Comparator interface?
Answer: Comparator is used to define custom sorting logic using compare() method.
Q68. Difference between HashMap and Hashtable?
Answer:
- HashMap is not synchronized; Hashtable is synchronized.
- HashMap allows one null key; Hashtable does not allow null key/value.
Q69. What is ConcurrentHashMap?
Answer: It is a thread-safe version of HashMap that allows concurrent access without locking the whole map.
Q70. What is Fail-Fast and Fail-Safe iterator?
Answer:
- Fail-Fast: Throws ConcurrentModificationException if collection is modified.
- Fail-Safe: Works on cloned collection and does not throw exception.
Q71. What is Custom Exception?
Answer: Custom exception is a user-defined exception created by extending Exception class.
Q72. What is finally vs finalize()?
Answer:
- finally: Block used for cleanup code.
- finalize(): Method called by garbage collector before object destruction.
Q73. Can we have multiple catch blocks?
Answer: Yes, multiple catch blocks can handle different exceptions.
Q74. What is try-with-resources?
Answer: It automatically closes resources like files and streams after execution.
Q75. What is the base class of all exceptions?
Answer: Throwable is the base class of all exceptions and errors.
Q76. What is Runnable vs Thread?
Answer:
- Runnable is an interface.
- Thread is a class.
- Runnable is preferred for multiple inheritance.
Q77. What is volatile keyword?
Answer: Volatile ensures that variable value is always read from main memory, not thread cache.
Q78. What is daemon thread?
Answer: A daemon thread runs in background and terminates when all user threads finish.
Q79. What is thread priority?
Answer: Thread priority determines the importance of a thread (1 to 10).
Q80. What is Executor Framework?
Answer: Executor framework simplifies thread management using thread pools.
Q81. What is Lambda Expression?
Answer: Lambda expression is a concise way to represent anonymous functions.
Q82. What is Functional Interface?
Answer: Functional interface has only one abstract method.
Q83. What is Stream API?
Answer: Stream API is used to process collections of objects in a functional style.
Q84. What is Optional class?
Answer: Optional is a container object used to avoid NullPointerException.
Q85. What are default methods?
Answer: Default methods allow method implementation inside interfaces.
Q86. What is Reflection API?
Answer: Reflection API allows inspection and modification of classes, methods, and fields at runtime.
Q87. What is Serialization UID?
Answer: It is a unique ID used during deserialization to verify class compatibility.
Q88. What is Marker Interface?
Answer: Marker interface is an empty interface (e.g., Serializable) used to mark classes.
Q89. What is Autoboxing and Unboxing?
Answer:
- Autoboxing: Primitive to Wrapper conversion.
- Unboxing: Wrapper to Primitive conversion.
Q90. What is Enum?
Answer: Enum is a special class used to define fixed constants.
Q91. What is SOLID principle?
Answer: SOLID principles are design principles for maintainable OOP code.
Q92. What is Singleton class?
Answer: Singleton class ensures only one instance of a class is created.
Q93. What is Immutable class?
Answer: Immutable class objects cannot be modified after creation.
Q94. What is Tight Coupling?
Answer: Tight coupling occurs when classes depend heavily on each other.
Q95. What is Loose Coupling?
Answer: Loose coupling reduces dependency between classes.
Q96. What is Dependency Injection?
Answer: Dependency Injection provides required dependencies externally rather than creating them inside class.
Q97. What is MVC Architecture?
Answer: MVC stands for Model-View-Controller. It separates application logic into three components.
Q98. What is JIT Compiler?
Answer: JIT (Just-In-Time) compiler improves performance by compiling bytecode into native machine code at runtime.
Q99. What is Platform Dependency?
Answer: Platform dependency means software runs only on a specific operating system.
Q100. Why is Java secure?
Answer: Java is secure because of bytecode verification, sandbox environment, no pointer arithmetic, and automatic memory management.
📢 Join Our WhatsApp Channel
💼 Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.
👉 Join WhatsApp Now📢 Join Our Telegram Channel
💼 Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!
👉 Join Telegram