Java Core Concepts: Memory Management, String Pool, Functional Interfaces, Collections, Serialization

𝐒𝐭𝐫𝐞𝐧𝐠𝐭𝐡𝐞𝐧𝐢𝐧𝐠 𝐂𝐨𝐫𝐞 𝐉𝐚𝐯𝐚 🔹 Q1: What is the difference between Java stack and heap memory? Answer: Stack memory: Stores method calls and local variables. LIFO structure, automatically cleared after method execution. Heap memory: Stores objects and instance variables. Managed by Garbage Collector. Example: Stack = your desk (temporary work). Heap = storage room (long-term storage). 🔹 Q2: What is the difference between String Pool and normal String object? Answer: String Pool: Stores unique literals to save memory. New String objects: Stored in heap, independent of the pool. Example: String Pool = shared dictionary. New String = your personal notebook with the same words. 🔹 Q3: What are functional interfaces in Java? Answer: An interface with a single abstract method. Used in Java 8 for lambda expressions. Example: Runnable, Comparator. Real-life Example: Like a single-purpose tool, e.g., a screwdriver — one function, extremely focused. 🔹 Q4: What is the difference between HashMap, LinkedHashMap, and TreeMap? Answer: HashMap: Unordered, fast access. LinkedHashMap: Maintains insertion order. TreeMap: Sorted order (Red-Black tree). Example: HashMap = random box of items. LinkedHashMap = items in the order you added. TreeMap = items arranged alphabetically on a shelf. 🔹 Q5: What is Java serialization and why is it used? Answer: Serialization = convert object to byte stream for storage or transmission. Deserialization = restore it back to object. Example: Compressing a file to send via email and decompressing it on the recipient side. #Java #CoreJava #JavaInterviewQuestions #JavaDeveloper #BackendDeveloper #SoftwareEngineer #TechCareers #DailyLearning

To view or add a comment, sign in

Explore content categories