Q1. JVM stands for: A. Java Vendor Machine B. Java Virtual Machine C. Just Virtual Module D. Java Verified Mode
Show Answer
Q2. JDK compared with JRE includes: A. Only a runtime B. Compiler and development tools C. Only a browser plugin D. Only a garbage collector
Show Answer
Q3. String s1 = "hi"; String s2 = "hi"; s1 == s2 is usually: A. false always B. true because of the string pool C. a compile error D. true only after new
Show Answer
Q4. s.equals(t) compares: A. Only hash codes B. Character content (when overridden) C. Object identity only D. Thread ids
Show Answer
Q5. Java String objects are: A. Mutable by default B. Immutable C. Always on the stack D. Primitive types
Show Answer
Q6. Which is a checked exception? A. NullPointerException B. IOException C. ArithmeticException D. ArrayIndexOutOfBoundsException
Show Answer
Q7. A checked exception must be: A. Ignored silently B. Handled or declared (throws) C. Thrown only from main D. Caught only in finally
Show Answer
Q8. Interface vs abstract class — interfaces (Java 8+) can have: A. Instance fields B. Default and static methods C. Constructors D. Only private constructors
Show Answer
Q9. An abstract class can have: A. No constructors B. Constructors, fields, and concrete methods C. Only static methods D. No subclasses
Show Answer
Q10. HashMap allows: A. No null keys B. One null key and many null values C. Duplicate keys D. Only String keys
Show Answer
Q11. ArrayList provides: A. O(1) random access B. O(n) random access only C. No iterators D. Fixed size only
Show Answer
Q12. LinkedList is typically better than ArrayList for: A. Random get(i) B. Frequent insert/remove at ends C. Memory compactness D. Binary search
Show Answer
Q13. HashSet stores: A. Duplicates in order B. Unique elements, no guaranteed order C. Key–value pairs D. A fixed array only
Show Answer
Q14. t.start() vs t.run() — start(): A. Calls run() on the current thread B. Creates a new thread that then runs run() C. Stops the thread D. Is the same as join()
Show Answer
Q15. Generics give you: A. Runtime new primitive types B. Compile-time type safety (with erasure) C. Faster GC always D. Checked exceptions
Show Answer
Q16. A static method can access: A. Instance fields directly B. Only static members of the class C. this always D. super.instance fields
Show Answer
Q17. final on a class means: A. It is abstract B. It cannot be subclassed C. It has no methods D. It must be an interface
Show Answer
Q18. final on a variable means: A. It is static B. It can be assigned only once C. It is volatile D. It is garbage-collected immediately
Show Answer
Q19. Overloading is resolved at: A. Runtime B. Compile time C. Class-load never D. GC time
Show Answer
Q20. Overriding is resolved at: A. Compile time only B. Runtime (dynamic dispatch) C. Link time only D. Preprocessor time
Show Answer
Q21. Default (package) access is visible to: A. The whole world B. The same package C. Subclasses in any package D. Only the class
Show Answer
Q22. Java source compiles to: A. .exe only B. Bytecode (.class) C. Machine code only D. HTML
Show Answer
Q23. int vs Integer: A. They are identical B. int is primitive; Integer is a wrapper object C. int lives only on the heap D. Integer cannot be null
Show Answer
Q24. Autoboxing converts: A. String to int always B. int ↔ Integer automatically C. Thread to Runnable D. File to Path only
Show Answer
Q25. StringBuilder is preferred over String when: A. You need immutability B. You build a string in a loop C. You compare with == D. You intern literals
Show Answer
Q26. Which collection is a Map? A. ArrayList B. HashMap C. HashSet D. Stack
Show Answer
Q27. HashMap average get/put is: A. O(1) B. O(log n) always C. O(n²) D. O(n log n)
Show Answer
Q28. TreeMap keys must be: A. Unhashable B. Comparable (or given a Comparator) C. Only Integers D. Mutable always
Show Answer
Q29. fail-fast iterators throw ConcurrentModificationException when: A. The JVM is idle B. The collection is structurally modified during iteration (same thread, non-concurrent) C. You only call get() D. You use for-each on an array
Show Answer
Q30. equals and hashCode must: A. Be ignored for HashMap B. Stay consistent: equal objects share a hashCode C. Always return 0 D. Use == only
Show Answer
Q31. Comparable vs Comparator: A. They are identical B. Comparable is natural order; Comparator is external C. Comparator is only for Strings D. Comparable is for Maps only
Show Answer
Q32. synchronized on a method locks: A. The Class object for static; this for instance B. Every object in the heap C. Only the calling thread D. The file system
Show Answer
Q33. volatile guarantees: A. Atomic compound updates B. Visibility of writes across threads (not full atomicity of i++) C. Fair locking D. No GC
Show Answer
Q34. wait() must be called: A. Outside any lock B. While holding the object’s monitor C. Only from main D. On a primitive
Show Answer
Q35. join() on a thread: A. Starts it B. Waits for that thread to finish C. Makes it daemon D. Interrupts it
Show Answer
Q36. A deadlock happens when: A. GC runs B. Threads wait forever for each other’s locks C. A method is static D. A list is empty
Show Answer
Q37. throw vs throws: A. They are the same B. throw raises an exception; throws declares it C. throws creates an object D. throw is only for Error
Show Answer
Q38. finally runs: A. Never after return B. Almost always, even after return (unless JVM exits) C. Only on success D. Only for checked exceptions
Show Answer
Q39. Java supports multiple inheritance of: A. Classes B. Interfaces (not classes) C. Constructors D. static fields only
Show Answer
Q40. this refers to: A. The Class object always B. The current instance C. The superclass only D. A static context
Show Answer
Q41. super() in a constructor: A. Must be last B. Must be the first statement if present C. Is illegal D. Creates a thread
Show Answer
Q42. Method hiding applies to: A. Instance methods B. static methods with the same signature in a subclass C. Constructors D. Fields only in interfaces
Show Answer
Q43. Object’s default equals compares: A. Field-by-field B. Reference identity (==) C. hashCode only D. toString
Show Answer
Q44. Garbage collection reclaims: A. Stack frames only B. Unreachable heap objects C. All static fields nightly D. Native OS processes
Show Answer
Q45. Stack vs heap in Java: A. Objects always live on the stack B. Locals/frames on the stack; objects on the heap C. Primitives never use the stack D. The heap holds only strings
Show Answer
Q46. A functional interface has: A. Zero methods B. Exactly one abstract method C. Only default methods D. A constructor
Show Answer
Q47. Optional is meant to: A. Replace all nulls in fields always B. Wrap a maybe-absent return value C. Store many values D. Lock a thread
Show Answer
Q48. Stream operations like map/filter are: A. Always eager and parallel B. Lazy until a terminal operation C. Only for files D. Checked exceptions
Show Answer
Q49. The entry point of a Java application is: A. init() B. public static void main(String[] args) C. constructor of Object D. finalize()
Show Answer
Q50. Interview-safe definition of polymorphism: A. Only loops B. One interface, many forms (compile-time or runtime) C. Only files D. Only GC
Show Answer