💡 Most Asked Core Java Interview Questions • What is the difference between HashMap and ConcurrentHashMap? • What is the difference between == and equals()? • Explain final, finally, and finalize() • Difference between String, StringBuilder, and StringBuffer • What is the difference between JVM, JRE, and JDK? • What are Functional Interfaces? • What is the difference between List, Set, and Map? • What is immutability? Why is String immutable? • What is method overloading vs method overriding? • What is the difference between checked and unchecked exceptions? • What is the difference between ArrayList and LinkedList? • What is the difference between HashSet and TreeSet? • What are streams in Java 8? • What is Optional in Java 8? • What is multithreading and how does synchronization work? • What is the difference between Runnable and Callable? • What is ExecutorService? • What is deadlock? • What are Java memory areas (Heap, Stack, etc.)? • What is garbage collection? #Java #CoreJava #InterviewPreparation #BackendDevelopment
Core Java Interview Questions and Answers
More Relevant Posts
-
💡 Most Asked Core Java Interview Questions • What is the difference between HashMap and ConcurrentHashMap? • What is the difference between == and equals()? • Explain final, finally, and finalize() • Difference between String, StringBuilder, and StringBuffer • What is the difference between JVM, JRE, and JDK? • What are Functional Interfaces? • What is the difference between List, Set, and Map? • What is immutability? Why is String immutable? • What is method overloading vs method overriding? • What is the difference between checked and unchecked exceptions? • What is the difference between ArrayList and LinkedList? • What is the difference between HashSet and TreeSet? • What are streams in Java 8? • What is Optional in Java 8? • What is multithreading and how does synchronization work? • What is the difference between Runnable and Callable? • What is ExecutorService? • What is deadlock? • What are Java memory areas (Heap, Stack, etc.)? • What is garbage collection? #Java #CoreJava #InterviewPreparation #BackendDevelopment
To view or add a comment, sign in
-
Before Java 8 — HashMap used an array of LinkedLists for collision handling. Worst case lookup was O(n) — if many keys hashed to the same bucket, you'd traverse the entire chain. Java 8+ — Still starts with LinkedLists, but when a bucket has ≥ 8 nodes, it automatically converts to a Red-Black Tree (TreeNode). This drops worst-case lookup to O(log n). It reverts back to a list if nodes fall to ≤ 6. The critical thresholds to remember for interviews: TREEIFY_THRESHOLD = 8 → list becomes tree UNTREEIFY_THRESHOLD = 6 → tree reverts to list MIN_TREEIFY_CAPACITY = 64 → table must also have ≥ 64 buckets before treeifying #java
To view or add a comment, sign in
-
-
How does memory work in java? This was one of the key questions in my last interview — and honestly, one I wasn’t expecting to explain so deeply. In simple terms, Java memory is divided into two main areas: the Stack and the Heap. The Stack stores primitive variables (int, char, double, etc.) and references (pointers) to objects, while the Heap is where the actual objects live. The JVM also optimizes memory usage through mechanisms like the Integer Cache (-127 to 128), which reuses Integer instances, and the String Pool, which avoids duplicating identical strings. On top of that, the Garbage Collector (GC) automatically cleans up the Heap by removing objects that are no longer referenced.
To view or add a comment, sign in
-
-
📘 Follow me for daily Java, Spring Boot, SQL & System Design MCQs to crack MNC interviews 🚀 ✅ Correct Answer: C) [A, B, C] This question tests how LinkedHashSet behaves with duplicates and insertion order in the Java Collections Framework. Set<String> set = new LinkedHashSet<>(); set.add("A"); set.add("B"); set.add("C"); set.add("A"); System.out.println(set); 🧠 Key Rules of LinkedHashSet It implements the Set concept → no duplicate elements allowed. It maintains insertion order. If you try to add a duplicate, it is ignored silently (no error). ▶ Step-by-step Execution set.add("A"); → [A] set.add("B"); → [A, B] set.add("C"); → [A, B, C] set.add("A"); → Duplicate, ignored → [A, B, C] 📌 Final Output [A, B, C] #JavaMCQ #CodingMCQ #InterviewPreparation #MNCInterview #CodeAnalysis #ConceptClarity #JavaLearning #ServletJSP #JDBC #OracleDB #DeveloperMindset #PracticeCoding
To view or add a comment, sign in
-
-
🚀 Day 2 – Subtle Java Behavior That Can Surprise You Today I explored the difference between "==" and ".equals()" in Java — and it’s more important than it looks. String a = "hello"; String b = "hello"; System.out.println(a == b); // true System.out.println(a.equals(b)); // true Now this: String c = new String("hello"); System.out.println(a == c); // false System.out.println(a.equals(c)); // true 👉 "==" compares reference (memory location) 👉 ".equals()" compares actual content 💡 The catch? Because of the String Pool, sometimes "==" appears to work correctly… until it doesn’t. This small misunderstanding can lead to tricky bugs, especially while working with collections or APIs. ✔ Rule I’m following: Always use ".equals()" for value comparison unless you explicitly care about references. #Java #BackendDevelopment #JavaBasics #LearningInPublic
To view or add a comment, sign in
-
Java Interview Question That Confuses Almost Everyone (Including Me) “Is Java pass by value or pass by reference?” Here’s the clarity I finally reached: Java is ALWAYS pass by value. No exceptions. But the confusion begins when we deal with objects. What actually happens with objects? When you pass an object to a method: Java passes a copy of the reference (address) Both references point to the same object in memory Two key scenarios: ✔ Modify object data → Changes are visible outside void modify(Test t) { t.x = 50; } Because both references point to the same object. ❌ Change the reference → No effect outside void change(Test t) { t = new Test(); t.x = 100; } Because now only the copied reference points to a new object. The mental model that clicked for me: Change object data → visible Change reference → no impact outside Final takeaway: Java is pass by value — but for objects, the value being passed is a reference. A huge thanks to PW Institute of Innovation and Syed Zabi Ulla sir for explaining this concept so thoroughly and clearly. #Java #SoftwareEngineering #Coding #ProgrammingConcepts #JavaDeveloper #TechInterviews#Java #Programming #SoftwareDevelopment #JavaDeveloper #CodingTips #Tech #BackendDevelopment #LearnToCode
To view or add a comment, sign in
-
-
☕ Java Interview Question 📌 Why can’t we create a generic array in Java? In Java, generic arrays are restricted because arrays and generics handle type information differently. 🔹 Key Reason: ✔ Arrays are Reified • Arrays store and check their element type at runtime ✔ Generics use Type Erasure • Generic type information is removed during compilation ✔ Type Safety Conflict • Runtime cannot verify the actual generic type inside an array 🔹 What Problem Can Occur? • It may allow invalid assignments at runtime • Can lead to ArrayStoreException or unsafe behavior 🔹 Example: • new T[10] is not allowed because T is unknown at runtime 💡 In Short: Java prevents generic array creation to maintain type safety between compile-time generics and runtime array checks. 👉For Java Course Details Visit : https://lnkd.in/gwBnvJPR . #Java #JavaInterview #Generics #TypeErasure #Programming #InterviewPreparation #CoreJava#ashokit
To view or add a comment, sign in
-
-
🔥 Day 11: Comparable vs Comparator (Java) One of the most important concepts for sorting in Java — especially for interviews 👇 🔹 1. Comparable 👉 Definition: Defines the natural (default) sorting of objects inside the class itself. ✔ Found in java.lang ✔ Uses compareTo() method ✔ Only one sorting logic per class 🔹 2. Comparator 👉 Definition: Defines custom sorting logic outside the class. ✔ Found in java.util ✔ Uses compare() method ✔ Supports multiple sorting logics 🔹 When to Use? ✔ Comparable → when class has natural/default order ✔ Comparator → when you need multiple or dynamic sorting 💡 Real-Life Analogy: Comparable = Default rule 📏 Comparator = Custom rule 🎯 📌 Final Thought: "Comparable gives you one way to sort, Comparator gives you many." #Java #Comparable #Comparator #Programming #JavaDeveloper #Coding #InterviewPrep #Day11
To view or add a comment, sign in
-
-
This Java code looks fine… but crashes 👇 List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); for (String s : list) { if (s.equals("A")) { list.remove(s); } } 💥 Throws: "ConcurrentModificationException" Why? You can't modify a list while iterating using a for-each loop. ✅ Fix: Use "Iterator" Iterator<String> it = list.iterator(); while (it.hasNext()) { if (it.next().equals("A")) { it.remove(); } } Classic interview question 🔥 #Java #Collections #BugFix
To view or add a comment, sign in
-
🤯 Every Java developer uses HashMap… But do you really know what happens when you call map.put("key", "value")? Let’s break it down 👇 ⚙️ Step 1 — Hashing Java calls hashCode() on the key, converting it into an integer. ⚙️ Step 2 — Bucket Calculation That hash is used to determine the index of the bucket (array slot): index = hashCode % array.length ⚙️ Step 3 — Storage The key-value pair is stored in that bucket as a Node. 🚨 What about collisions? When multiple keys map to the same bucket, a collision occurs. 👉 Before Java 8: Entries are stored using a LinkedList 👉 Java 8 and later: If entries exceed 8, it converts into a Red-Black Tree 🌳 for better performance 💡 Why this matters: ✔️ Average time complexity for get() and put() is O(1) ✔️ Not thread-safe (use ConcurrentHashMap in multi-threaded scenarios) ✔️ Always override hashCode() and equals() for custom key objects 🔑 Key Rule: If two objects are equal, they must have the same hashCode(). But the same hashCode() does not guarantee equality. This is one of the most commonly asked Java interview questions—and a fundamental concept every backend developer should truly understand. Have you faced this question in an interview? 👇 #Java #JavaDeveloper #BackendDevelopment #SpringBoot #JavaInterview #Programming #Coding #SoftwareEngineering
To view or add a comment, sign in
-
Explore related topics
- Backend Developer Interview Questions for IT Companies
- Java Coding Interview Best Practices
- Best Questions to Ask at End of Interview
- Final Questions to Ask in Teacher Interviews
- Key Questions to Ask in an Internal Interview
- Common Algorithms for Coding Interviews
- Common Interview Questions Beyond the Basics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development