Java Interview Questions
इस list को कैसे इस्तेमाल करें
ये वो सवाल हैं जो freshers के Java interviews में सबसे अक्सर आते हैं। हर एक के पीछे का विचार समझिए, और एक छोटा, साफ़ जवाब एक-line उदाहरण के साथ देने को तैयार रहिए। क्यों जानना interviewers के लिए रट्टे से कहीं ज़्यादा मायने रखता है।
Basics और OOP
Q1. Java क्या है? Platform-independent, object-oriented language; code bytecode में compile होता है जो JVM पर चलता है।
Q2. JDK बनाम JRE बनाम JVM? JVM bytecode चलाता है; JRE = JVM + libraries; JDK = JRE + compiler tools।
Q3. OOP के चार स्तंभ क्या हैं? Encapsulation, inheritance, polymorphism, abstraction।
Q4. Overloading बनाम overriding? Overloading = वही नाम, अलग parameters (compile time); overriding = child parent method फिर define करता है (runtime)।
Q5. Abstract class बनाम interface? Abstract में code है और extend होती है (एक); interface contract है और कई implement हो सकती हैं।
Strings और types
Q6. == बनाम equals()? == references तुलना; equals() content तुलना करता है।
Q7. Strings immutable क्यों? सुरक्षा, string pool में caching, और predictable व्यवहार को।
Q8. String बनाम StringBuilder? String immutable; StringBuilder mutable और text बनाने को तेज़।
Q9. Autoboxing क्या है? Java द्वारा primitive (int) को उसके wrapper (Integer) में और वापस अपने-आप बदलना।
Q10. final keyword? Variable को constant, method को non-overridable, या class को non-extendable बनाता है।
Collections
Q11. List बनाम Set बनाम Map? List order और duplicates रखती है; Set unique items; Map key-value pairs।
Q12. ArrayList बनाम LinkedList? ArrayList = तेज़ index access; LinkedList = बीच में तेज़ insert/remove।
Q13. HashMap बनाम Hashtable? HashMap तेज़ और thread-safe नहीं; Hashtable thread-safe पर धीमी और legacy।
Q14. HashSet बनाम TreeSet? HashSet का कोई order नहीं और तेज़; TreeSet items sorted रखती है।
Q15. Comparable बनाम Comparator? Comparable एक natural order (compareTo); Comparator custom orders (compare) देता है।
Exceptions और अन्य
Q16. Checked बनाम unchecked exceptions? Checked catch या declare करनी ज़रूरी; unchecked (RuntimeException) ज़रूरी नहीं।
Q17. final बनाम finally बनाम finalize? final = keyword; finally = block जो हमेशा चलता है; finalize = deprecated method।
Q18. Thread क्या है? Execution का अलग रास्ता; multithreading कई एक साथ चलाता है।
Q19. Singleton pattern क्या है? सिर्फ़ एक object वाली class, private constructor और getInstance() से।
Q20. Garbage collection क्या है? Java द्वारा अब referenced न रहे objects की memory अपने-आप मुक्त करना।
Interview tips
- क्यों समझाइए। सिर्फ़ feature क्या करता है नहीं, कब और क्यों इस्तेमाल करें बताइए।
- एक-line उदाहरण दीजिए। एक छोटा snippet असली समझ दिखाता है।
- OOP और collections का ज़िक्र कीजिए। ये ज़्यादातर Java interviews का दिल हैं।
- ईमानदार रहिए। न पता हो तो बताइए कैसे पता करेंगे — यह भी अच्छा संकेत है।
सारांश
- मुख्य तुलनाएँ जानिए:
==बनामequals(), overloading बनाम overriding। - OOP के चार स्तंभ उदाहरणों के साथ साफ़ समझाइए।
- Collections में सहज रहिए: List, Set, Map और उनकी classes।
- Exceptions, threads, Singleton और garbage collection समझिए।
- सिर्फ़ definitions नहीं, "क्यों" और एक छोटे उदाहरण के साथ जवाब दीजिए।
अपने interview से पहले inheritance और collections के topics दोहराइए।
अक्सर पूछे जाने वाले प्रश्न (FAQ)
Java में == और equals() में क्या अंतर है?
== references तुलना करता है (दो variables एक ही object की ओर इशारा करते हैं या नहीं), जबकि equals() असली content तुलना करता है। strings और objects को, values तुलना करने को equals() इस्तेमाल कीजिए।