🔥 Tricky Java String Interview Questions (That Confuse Even Experienced Devs!) If you think Strings are easy… think again 😏👇 🔹 1. Output? (String Pool vs Heap) String s1 = "java"; String s2 = "java"; String s3 = new String("java"); System.out.println(s1 == s2); System.out.println(s1 == s3); 👉 Answer: ✔ true ✔ false 💡 Why? "java" → stored in String Pool new String() → creates new object in heap 🔹 2. What will this print? String s1 = "hello"; String s2 = "he" + "llo"; String s3 = "he"; String s4 = s3 + "llo"; System.out.println(s1 == s2); System.out.println(s1 == s4); 👉 Answer: ✔ true ✔ false 💡 Why? Compile-time → "he" + "llo" → optimized to "hello" Runtime → s3 + "llo" → new object created 🔹 3. Immutable Trick String s = "java"; s.concat("8"); System.out.println(s); 👉 Answer: ✔ java 💡 Why? String is immutable concat() returns new object (not assigned) 🔹 4. Equals vs == String s1 = new String("test"); String s2 = new String("test"); System.out.println(s1 == s2); System.out.println(s1.equals(s2)); 👉 Answer: ✔ false ✔ true 💡 Why? == → reference comparison equals() → value comparison 🔹 5. Intern() Trick String s1 = new String("spring"); String s2 = s1.intern(); String s3 = "spring"; System.out.println(s2 == s3); 👉 Answer: ✔ true 💡 Why? intern() returns reference from String Pool 🔹 6. How many objects created? 🤯 String s = new String("java"); 👉 Answer: ✔ 2 objects 💡 Why? "java" → String Pool new String() → Heap 🔹 7. Performance Trap String s = ""; for(int i=0; i<1000; i++){ s += i; } 👉 Problem? ❌ Creates multiple objects → poor performance ✔ Better: StringBuilder sb = new StringBuilder(); for(int i=0; i<1000; i++){ sb.append(i); } 💡 Pro Interview Tips ✔ Always remember String Pool vs Heap ✔ Prefer equals() over == ✔ Use StringBuilder for loops ✔ Understand compile-time vs runtime concatenation 🔥 Save this before your next interview! #Java #String #InterviewQuestions #JavaDeveloper #Backend #Coding
Java String Interview Questions: Pool vs Heap, Equality, and Performance
More Relevant Posts
-
Java Strings — Part 2: String Constant Pool (SCP) Deep Dive 🔥 If you don’t understand String Pool, you’ll struggle with at least 30% of Java interview questions on Strings. Let’s break it down clearly 👇 ⸻ 🔹 What is String Constant Pool (SCP)? 👉 A special memory area inside the Heap where Java stores unique String literals String s1 = "abc"; String s2 = "abc"; 💡 Both s1 and s2 point to the same object in the String Pool ⸻ 🔹 Why String Pool exists? ✔ Memory optimization (no duplicate objects) ✔ Faster comparisons using references ✔ Improves performance ⸻ 🔹 Object Creation — Most Important Concept 🔥 ✅ Case 1: Using Literal String s1 = "hello"; String s2 = "hello"; 👉 Only 1 object created in SCP ⸻ ✅ Case 2: Using new keyword String s1 = new String("hello"); 👉 2 objects created: 1. One in SCP (“hello”) 2. One in Heap (new object) ⸻ ✅ Case 3: Combination String s1 = "hello"; String s2 = new String("hello"); 👉 Total objects: * 1 in SCP * 1 in Heap ⸻ 🔹 == vs .equals() (Interview Trap ⚠️) String s1 = "abc"; String s2 = "abc"; System.out.println(s1 == s2); // true String s3 = new String("abc"); System.out.println(s1 == s3); // false ✔ == → compares references ✔ .equals() → compares values ⸻ 🔹 intern() Method (Advanced 🔥) String s1 = new String("hello"); String s2 = s1.intern(); 👉 intern() forces the String into SCP 💡 Now s2 will point to SCP reference ⸻ 🔹 Tricky Interview Questions ⚠️ Q1: How many objects? String s = new String("xyz"); 👉 Answer: 2 objects ⸻ ⚠️ Q2: How many objects? String s1 = "a" + "b"; 👉 Answer: 1 object (compile-time optimization) ⸻ ⚠️ Q3: How many objects? String s1 = "a"; String s2 = s1 + "b"; 👉 Answer: 2 objects (runtime concatenation) ⸻ 🔹 Compile-Time vs Runtime Concatenation ✔ Compile-time → goes to SCP ✔ Runtime → creates new object in Heap ⸻ 🔥 Final Takeaway ✔ String Pool avoids duplicate objects ✔ Literals use SCP, new creates extra object ✔ == vs .equals() is a must-know ✔ intern() is an advanced optimization tool #Java #SDET #AutomationTesting #JavaInterview #StringPool #Programming #TechLearning :::
To view or add a comment, sign in
-
🚀 Top 5 Tough Java Full Stack Interview Questions Asked at Top MNCs If you're targeting companies like Google, Microsoft, Meta, Amazon, and Walmart — these are must-master 👇 🔥 TOP 5 QUESTIONS WITH DETAILED ANSWERS 1. HashMap vs ConcurrentHashMap (Concurrency + Performance) ✅ Answer: HashMap Not thread-safe → can lead to data inconsistency Faster in single-threaded environments ConcurrentHashMap Thread-safe using CAS + segment-level locking Allows multiple threads to read/write efficiently No null keys/values allowed 👉 Why asked? Tests deep understanding of multithreading & scalability 2. JVM Memory Model & Garbage Collection ✅ Answer: JVM memory is divided into: Heap → stores objects (Young Gen + Old Gen) Stack → method execution & local variables Method Area → class metadata 👉 Garbage Collection: Minor GC → cleans young generation Major GC → cleans old generation 👉 Real-world interviews focus on: Memory leaks GC tuning (G1, ZGC) Performance optimization 3. Coding: LRU Cache Implementation ✅ Code: Java class LRUCache { private final int capacity; private LinkedHashMap<Integer, Integer> map; public LRUCache(int capacity) { this.capacity = capacity; this.map = new LinkedHashMap<>(capacity, 0.75f, true); } public int get(int key) { return map.getOrDefault(key, -1); } public void put(int key, int value) { map.put(key, value); if(map.size() > capacity) { int firstKey = map.keySet().iterator().next(); map.remove(firstKey); } } } 👉 Concepts tested: Data structures Caching strategy System design basics 4. REST API Design Best Practices ✅ Answer: Use proper HTTP methods (GET, POST, PUT, DELETE) Keep APIs stateless Use correct status codes (200, 404, 500) Version APIs (/api/v1/) Secure with JWT/OAuth 👉 Evaluates backend architecture & real-world experience 5. Coding: Detect Cycle in Linked List ✅ Code: Java public boolean hasCycle(ListNode head) { ListNode slow = head, fast = head; while(fast != null && fast.next != null) { slow = slow.next; fast = fast.next.next; if(slow == fast) return true; } return false; } 👉 Uses Floyd’s Cycle Detection Algorithm 👉 Time: O(n), Space: O(1) 💡 WHAT TOP MNCs EXPECT ✔ Strong fundamentals ✔ Optimized solutions ✔ Clean & maintainable code ✔ Real-world system thinking ✔ Clear communication 📢 TAKE YOUR NEXT STEP 🚀 Want to crack top MNC interviews faster? 👉 Get expert help with: Resume Building Mock Interviews System Design Coding Preparation 👉 For more guidance on interviews, join Talent Latitude on Topmate #JavaDeveloper #FullStackDeveloper #CodingInterview #InterviewPreparation #MNCJobs #SystemDesign #SpringBoot #Microservices #TechCareers #SoftwareEngineer #CareerGrowth #AmazonJobs #GoogleCareers #MicrosoftCareers #MetaCareers #WalmartTech #TalentLatitude
To view or add a comment, sign in
-
Java basic Interview Questions solved with Advance Java Q1. Reverse a String ? //Reverse the String String reverseString = "Java Programming"; System.out.println(new StringBuilder(reverseString).reverse()); Q2. Find Duplicate Characters --> Input : “automation” --> Output: “a-2 t-2 o-2" //Find duplicate Character String duplicate = "automation"; getMapForOccurance(duplicate).entrySet().stream().filter(e -> e.getValue() > 1) .forEach(e -> System.out.println(e.getKey() + "-" + e.getValue())); public static Map < Character, Integer > getMapForOccurance(String abc) { Map < Character, Integer > map = new HashMap < Character, Integer > (); for (char c: abc.toCharArray()) { map.put(c, map.getOrDefault(c, 0) + 1); } return map; } Q3. Count Occurrence of Each Character Input : “test” Output : “ t=2, e=1, s=1” // Count occurrence of Each Character String occurrence = "test"; getMapForOccurance(occurrence).forEach((key, value) -> { System.out.println(key + "-" + value); }); Q4: Palindrome Check < Verify with enter list of numbers > “madam” -> true “Hello” -> false //Palindrom check Scanner sc = new Scanner(System.in); boolean flag = true; List < String > palindrom = new ArrayList < String > (); System.out.println("Enter all the strings to verify Palindrom./n type \"last\" for end the input"); while (flag) { String input = sc.nextLine(); if (input.equalsIgnoreCase("last")) { break; } palindrom.add(input); } palindrom.forEach((pal) -> { if (pal.equals(new StringBuilder(pal).reverse().toString())) { System.out.println(pal + " is Palindrom"); } }); Q5. Find Largest & Smallest in Array // Find largest & Smallest Array int[] values={5,2,9,1}; System.out.println("Largest Number :"+ Arrays.stream(values).max().getAsInt()); System.out.println("Smallest Number :"+ Arrays.stream(values).min().getAsInt()); Q6. Find Largest & Smallest in Collection // Find largest & Smallest Collections List<Integer> values=List.of(5,2,9,1); System.out.println("Largest Number :"+ Collections.max(values)); System.out.println("Smallest Number :"+ Collections.min(values)); Q7. Remove Duplicates from Array //Remove Duplicates from ArrayList int[] input = {1,2,2,3,4,4}; // Output : [1,2,3,4] Set<Integer> set= Arrays.stream(input).boxed() .collect(Collectors.toSet()); System.out.println(set); #AdvanceJava #Java #JavaInterviewQuestioins #QA #AutomationTesting
To view or add a comment, sign in
-
🚀 Top 3 Medium-Level HackerRank Problems (Java) Every Developer Should Practice If you're preparing for coding interviews, mastering medium-level problems is 🔑. They test your ability to apply DSA concepts in real scenarios. Here are 3 must-solve problems with clean Java solutions 👇 --- 1️⃣ Balanced Brackets 👉 Validate if brackets are properly matched Approach: Use Stack import java.util.*; public class Solution { public static String isBalanced(String s) { Stack<Character> stack = new Stack<>(); Map<Character, Character> map = new HashMap<>(); map.put(')', '('); map.put('}', '{'); map.put(']', '['); for (char ch : s.toCharArray()) { if (map.containsValue(ch)) { stack.push(ch); } else { if (stack.isEmpty() || stack.peek() != map.get(ch)) { return "NO"; } stack.pop(); } } return stack.isEmpty() ? "YES" : "NO"; } } --- 2️⃣ Two Strings 👉 Check if two strings share a common substring Approach: Use HashSet import java.util.*; public class Solution { public static String twoStrings(String s1, String s2) { Set<Character> set = new HashSet<>(); for (char c : s1.toCharArray()) { set.add(c); } for (char c : s2.toCharArray()) { if (set.contains(c)) { return "YES"; } } return "NO"; } } --- 3️⃣ Sherlock and Anagrams 👉 Count anagrammatic substring pairs Approach: Sort substrings + HashMap import java.util.*; public class Solution { public static int sherlockAndAnagrams(String s) { Map<String, Integer> map = new HashMap<>(); for (int i = 0; i < s.length(); i++) { for (int j = i + 1; j <= s.length(); j++) { char[] arr = s.substring(i, j).toCharArray(); Arrays.sort(arr); String key = new String(arr); map.put(key, map.getOrDefault(key, 0) + 1); } } int count = 0; for (int val : map.values()) { count += val * (val - 1) / 2; } return count; } } --- 💡 Pro Tip: Most medium problems rely on: ✔ Hashing ✔ Sorting ✔ Greedy logic ✔ Stack/Queue --- 🔥 Consistency > Intensity Solve 2–3 problems daily → You’ll start recognizing patterns quickly! #Java #HackerRank #CodingInterview #DataStructures #Algorithms #SoftwareDeveloper
To view or add a comment, sign in
-
Top 50 Java String Interview Questions Strings are one of the most commonly used data types in Java, and they play a critical role in interviews—from basic concepts to tricky edge cases. Here’s a carefully curated list of 50 essential String interview questions to help you prepare effectively: Beginner Level What is a String in Java? Why are Strings immutable in Java? Difference between String, StringBuilder, and StringBuffer? How are Strings stored in memory? What is the String Constant Pool? What is the difference between == and .equals()? How do you create a String object? What is intern() method? What is substring in Java? How to compare two strings? Intermediate Level How do you reverse a String? How to check if a String is palindrome? How to remove duplicate characters from a String? How to count occurrences of characters? How to find first non-repeating character? How to check if two Strings are anagrams? How to split a String? How to join Strings in Java? How to convert String to int and vice versa? Difference between trim() and strip()? How to replace characters in a String? How to check if String contains only digits? How to convert String to uppercase/lowercase? What is charAt() method? What is indexOf() and lastIndexOf()? Advanced Level How does String hashing work in Java? What is the role of hashCode() in Strings? Why String is final in Java? How does StringBuilder improve performance? What is lazy String concatenation? What is the difference between concat() and +? How to efficiently concatenate multiple Strings? What is regex in String operations? How to validate email using regex? How to tokenize a String? What are String APIs introduced in Java 8+? Difference between matches() and equals()? What is StringJoiner? What is format() method? What is Unicode and how Java handles it? Coding & Scenario-Based Write a program to reverse words in a sentence. Find the longest substring without repeating characters. Check if String rotations of each other. Find duplicate words in a sentence. Count vowels and consonants in a String. Remove white spaces from a String. Find all permutations of a String. Compress a String (e.g., aabcc → a2b1c2). Check if String contains only unique characters. Convert a sentence to title case. Mastering Strings not only helps in interviews but also improves your problem-solving and coding efficiency. If you found this helpful, feel free to like, share, and comment! 📩 Want the full PDF with answers? Comment “PDF” below and DM ME and I’ll share it with you! Let’s grow and learn together 💪 #Java #CodingInterview #DataStructures #Programming #SoftwareEngineering #JavaDeveloper
To view or add a comment, sign in
-
-
💡 Functional Interfaces in Java — Beyond the Basics If you think Functional Interfaces are just about Lambda expressions, you're only scratching the surface. Let’s go deeper 👇 🔹 Recap: What is a Functional Interface? An interface with exactly one abstract method, annotated optionally with "@FunctionalInterface" for clarity and compile-time safety. --- 🔹 Key Characteristics ✔ Can have multiple default and static methods ✔ Enables functional programming style in Java ✔ Works seamlessly with lambda expressions and method references --- 🔹 Custom Functional Interface Example @FunctionalInterface interface Calculator { int operate(int a, int b); } Usage: Calculator add = (a, b) -> a + b; System.out.println(add.operate(5, 3)); // 8 --- 🔹 Lambda vs Method Reference Lambda: (a, b) -> a + b Method Reference: Integer::sum 👉 Cleaner and more reusable when method already exists. --- 🔹 Where are Functional Interfaces Used? 🔥 1. Streams API list.stream() .filter(x -> x > 10) // Predicate .map(x -> x * 2) // Function .forEach(System.out::println); // Consumer 🔥 2. Multithreading new Thread(() -> System.out.println("Running thread")).start(); 🔥 3. Event Handling & Callbacks Used heavily in asynchronous and reactive programming. --- 🔹 Types of Functional Interfaces (Deep View) ✨ Predicate<T> → Boolean conditions Used for filtering data ✨ Function<T, R> → Transformation Convert one form of data to another ✨ Consumer<T> → Performs action Logging, printing, updating ✨ Supplier<T> → Generates data Lazy loading, object creation ✨ BiFunction / BiPredicate → Work with 2 inputs --- 🔹 Why Companies Care? (Interview Insight) ✔ Reduces boilerplate code ✔ Encourages clean architecture ✔ Essential for Spring Boot & Microservices ✔ Frequently used in real-world production code --- 🔹 Common Mistakes to Avoid ❌ Adding more than one abstract method ❌ Ignoring built-in functional interfaces ❌ Overusing lambdas (readability matters!) --- 🔹 Pro Tip for Freshers 🚀 When solving DSA or backend problems, try rewriting logic using: 👉 Lambda expressions 👉 Streams 👉 Built-in functional interfaces This shows modern Java proficiency in interviews. --- 💬 Final Thought: Functional Interfaces are not just a feature—they represent a shift in how Java developers think and write code. Master them, and your code becomes shorter, smarter, and more powerful ⚡ #Java #FunctionalProgramming #Java8 #BackendDeveloper #CodingJourney #SoftwareEngineering #InterviewPrep
To view or add a comment, sign in
-
✅ *Top Java Interview Questions with Answers: Part-4* ☕ *3️⃣1️⃣ What is the Stream API in Java 8?* Stream API allows functional-style operations on collections. Example: ```java List<String> names = list.stream() .filter(s -> s.startsWith("A")) .collect(Collectors.toList()); ``` It supports map, filter, reduce, sorted, etc., for better performance and readable code. *3️⃣2️⃣ What is Optional in Java 8?* A container to avoid `null`. Helps prevent `NullPointerException`. Example: ```java Optional<String> name = Optional.ofNullable(getName()); name.ifPresent(System.out::println); ``` *3️⃣3️⃣ What are default and static methods in interfaces?* - *Default*: Provide method implementation inside interface. - *Static*: Belongs to interface, not to instance. ```java default void show() { ... } static void log() { ... } ``` *3️⃣4️⃣ What is garbage collection in Java?* Automatic memory management. Unused objects are removed to free up memory. The JVM’s garbage collector handles it. *3️⃣5️⃣ What is the finalize() method?* A method called *before* an object is garbage collected. Deprecated in modern Java. ```java protected void finalize() { ... } ``` *3️⃣6️⃣ What are annotations?* Metadata used to provide information to compiler or runtime. Examples: `@Override`, `@Deprecated`, `@FunctionalInterface`. *3️⃣7️⃣ What is reflection in Java?* Used to inspect classes, methods, and fields at runtime. Example: ```java Class<?> cls = Class.forName("MyClass"); Method[] methods = cls.getDeclaredMethods(); ``` *3️⃣8️⃣ What is serialization and deserialization?* - *Serialization*: Converting an object to a byte stream - *Deserialization*: Reconstructing object from bytes Used for saving/transferring objects ```java implements Serializable ``` *3️⃣9️⃣ What is the transient keyword?* Prevents a field from being serialized. Used when sensitive or temporary data shouldn’t be saved. *4️⃣0️⃣ How does Java handle memory management?* Java uses heap and stack memory. - *Heap*: Stores objects (GC-managed) - *Stack*: Stores method calls and local variables Garbage collector reclaims unused memory automatically. 💬 *Tap ❤️ for Part-5*
To view or add a comment, sign in
-
🚀 One of the Most Complex Java Problems Asked in Top Tech Interviews 💡 Design a Thread-Safe LRU Cache with O(1) Operations --- 🧠 Problem Statement: Design and implement an LRU (Least Recently Used) Cache with the following operations: - "get(key)" → Returns value if present, else -1 - "put(key, value)" → Insert/update the value ⚡ Constraints: - Both operations must run in O(1) time - Must be thread-safe (handle concurrent access properly) --- 🔥 Why this is challenging? This problem tests: - Data Structures (HashMap + Doubly Linked List) - Concurrency (Locks, synchronization) - Real-world system design (cache eviction strategy) --- 🛠️ Approach: To achieve O(1): - Use a HashMap → Fast lookup - Use a Doubly Linked List → Maintain LRU order For Thread Safety: - Use ReentrantLock (better than synchronized for flexibility) --- 💻 Java Implementation: import java.util.*; import java.util.concurrent.locks.ReentrantLock; class LRUCache { class Node { int key, value; Node prev, next; Node(int k, int v) { key = k; value = v; } } private final int capacity; private Map<Integer, Node> map; private Node head, tail; private ReentrantLock lock = new ReentrantLock(); public LRUCache(int capacity) { this.capacity = capacity; this.map = new HashMap<>(); head = new Node(0, 0); tail = new Node(0, 0); head.next = tail; tail.prev = head; } public int get(int key) { lock.lock(); try { if (!map.containsKey(key)) return -1; Node node = map.get(key); remove(node); insert(node); return node.value; } finally { lock.unlock(); } } public void put(int key, int value) { lock.lock(); try { if (map.containsKey(key)) { remove(map.get(key)); } if (map.size() == capacity) { Node lru = tail.prev; remove(lru); map.remove(lru.key); } Node newNode = new Node(key, value); insert(newNode); map.put(key, newNode); } finally { lock.unlock(); } } private void remove(Node node) { node.prev.next = node.next; node.next.prev = node.prev; } private void insert(Node node) { node.next = head.next; node.prev = head; head.next.prev = node; head.next = node; } } --- ⚠️ Common Mistakes: - Forgetting to update order after "get()" - Not handling concurrency → leads to race conditions - Using only HashMap (misses LRU behavior) --- 📈 Follow-up Questions Asked in Interviews: - Can you make it lock-free? - How would you scale this in distributed systems? - What if capacity is millions? #Java #SystemDesign #CodingInterview #Concurrency #TechCareers
To view or add a comment, sign in
-
🙃 Java Interview Questions – Answers Explained Thank you for the great responses on my previous post! Here are the answers to the Java interview questions 👇 --- 🔹 Q1: What are the 4 pillars of OOP? Encapsulation, Abstraction, Inheritance, Polymorphism --- 🔹 Q2: Encapsulation vs Abstraction? Encapsulation → Hides data (security) Abstraction → Hides implementation (complexity) --- 🔹 Q3: Why no multiple inheritance in Java? Java doesn’t support multiple inheritance using classes due to ambiguity (diamond problem). It is achieved using interfaces. --- 🔹 Q4: Overloading vs Overriding? Overloading → Compile-time, same method name with different parameters Overriding → Runtime, child class provides its own implementation --- 🔹 Q5: List vs Set vs Map? List → Ordered, duplicates allowed Set → No duplicates Map → Key-value pairs --- 🔹 Q6: Why is HashMap fast? Uses hashing to directly access bucket → O(1) time complexity --- 🔹 Q7: hashCode() vs equals()? hashCode() → Finds bucket location equals() → Compares objects --- 🔹 Q8: What is collision? When two keys have same hashCode → stored in same bucket Handled using LinkedList (Java 7) or Tree (Java 8) --- 🔹 Q9: Why ArrayList slow for insertion? Requires shifting elements and resizing --- 🔹 Q10: Why String is immutable? For security, performance (string pool), and thread safety --- 🔹 Q11: Checked vs Unchecked exceptions? Checked → Compile-time (IOException) Unchecked → Runtime (NullPointerException) --- 🔹 Q12: Will finally always execute? No — it won’t execute if JVM stops (e.g., System.exit()) --- 🔹 Q13: What is race condition? When multiple threads modify shared data → inconsistent results --- 🔹 Q14: start() vs run()? start() → creates new thread run() → normal method call --- 🔹 Q15: Lambda expression? Short way to implement functional interface --- 🔹 Q16: map() vs filter()? map() → transforms data filter() → applies condition --- 💡 Consistently revising fundamentals to become interview-ready 🚀 #Java #JavaDeveloper #InterviewPrep #LearningInPublic #SoftwareEngineering #TechCareers
To view or add a comment, sign in
-
🚀 Most Asked Core Java Interview Questions (Part 1) Over the past few weeks, I’ve attended multiple interviews and noticed repeating patterns. Sharing some of the most asked questions 👇 🔹 HashMap Question 👉 What happens if hashCode() always returns same value and equals() always returns true? @Override public boolean equals(Object o) { return true; } @Override public int hashCode() { return 1; } map.put("abc", 123); map.put("xyz", 145); 🔹 Which display() method gets called? Is it compile-time or runtime? class A { public A() { System.out.println("A"); } public void display() { System.out.println("Display A"); } } class B extends A { public B() { System.out.println("B"); } public void display() { System.out.println("Display B"); } public static void main(String[] args) { A a = new B(); a.display(); } } 🔹 What will be the output? (String Pool vs Heap) class Main { public static void main(String[] args) { String s1 = "Hello"; String s2 = "Hello"; String s3 = new String("Good bye"); String s4 = new String("Hello").intern(); String s5 = new String("Hello"); System.out.println(s1.equals(s2)); System.out.println(s1.equals(s3)); System.out.println(s1==s4); System.out.println(s1==s5); System.out.println(s1==s2); System.out.println(s1.equals(args)); System.out.println(s1.equals(null)); } } 🔹 What happens when two interfaces have the same method and a class implements both? interface A { void fun(); } interface B { void fun(); } class C implements A, B { public void fun() { System.out.println("Implemented"); } } 🔹 What happens if both interfaces have default methods? interface A { default void fun() { System.out.println("A"); } } interface B { default void fun() { System.out.println("B"); } } 🔹 What will be the output? (Method Overloading Edge Case) class A { public void display(String str) { System.out.println("I am String"); } public void display(Integer in) { System.out.println("I am Integer"); } public static void main(String[] args) { A a = new A(); a.display(null); } } 🔹 Conceptual Questions Interface vs Abstract class Why abstract class has constructor OOP principles How exception works in method overriding 🔹 Java Memory & JVM Explain Java memory areas (Heap, Stack, Metaspace) Explain Java Memory Model solid principles design patterns 👉 Part 2 coming next (Multithreading + Collections + Advanced) #Java #CoreJava #InterviewQuestions
To view or add a comment, sign in
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