Core Java interview questions with only advanced questions (no basics) 👇 1. How does JVM memory model work (Heap, Metaspace, Stack, PC, Native)? 2. Explain GC algorithms: G1 vs ZGC vs CMS – when to use what? 3. What is the hashCode()–equals() contract and how does it affect HashMap? 4. How does ConcurrentHashMap achieve thread-safety internally? 5. Difference between synchronized, ReentrantLock, and StampedLock? 6. What happens internally during a thread context switch? 7. Explain Java Memory Model (JMM) and the volatile keyword. 8. How does CompletableFuture work compared to Future? 9. Internal working of Java Streams – lazy evaluation & short-circuiting. 10. How does Optional help in avoiding NPE and when not to use it? 11. Type erasure in Generics – limitations and runtime impact. 12. Reflection: performance cost and real-world use cases. 13. Serialization vs Externalization – differences and risks. 14. JDBC connection pooling – why and how it improves performance? 15. How does Spring use Dependency Injection at runtime? 16. Singleton implementation pitfalls in multithreaded environments. 17. Factory vs Abstract Factory – real backend use case? 18. How does Java handle OutOfMemoryError and GC tuning? 19. Stack vs Heap memory – impact on performance and scalability. 20. How do you debug a production memory leak in Java? Skipping basics. Focusing on real interview questions. #Java #CoreJava #InterviewPrep #Backend #SoftwareEngineer
Advanced Java Interview Questions: JVM, GC, Concurrency, and More
More Relevant Posts
-
Java Interview Topic: Stack vs Heap Memory 🔹 Stack Memory: ✔ Stores method calls and local variables ✔ Memory allocation is fast ✔ Works in LIFO (Last In, First Out) order ✔ Thread-safe (each thread has its own stack) Example: void calculate() { int x = 10; // stored in stack } 🔹 Heap Memory: ✔ Stores objects and instance variables ✔ Shared across threads ✔ Managed by Garbage Collector ✔ Slower than stack but more flexible Example: User user = new User(); // object stored in heap 🔹 Key Differences: ✔ Stack → short-lived, method-level data ✔ Heap → long-lived objects ✔ StackOverflowError → deep recursion ✔ OutOfMemoryError → heap exhaustion Understanding stack vs heap helps debug memory issues and write efficient Java applications. #Java #JavaInterview #MemoryManagement #BackendDevelopment
To view or add a comment, sign in
-
1. How does JVM memory model work (Heap, Metaspace, Stack, PC, Native)? 2. Explain GC algorithms: G1 vs ZGC vs CMS – when to use what? 3. What is the hashCode()–equals() contract and how does it affect HashMap? 4. How does ConcurrentHashMap achieve thread-safety internally? . . . . . Read “Core Java interview questions with only advanced questions (no basics)“ by Ajit on Medium: https://lnkd.in/gJ7yUPMy
To view or add a comment, sign in
-
#day16 #FunctionalInterfaces A functional interface in Java is an interface that has only one abstract method, making it suitable for use with lambda expressions and method references (introduced in Java 8). a. Use @FunctionalInterface to ensure only one abstract method (annotation is optional). b. Enable clean, concise code using lambdas and method references. #@FunctionalInterface Annotation @FunctionalInterface annotation ensures that an interface cannot have more than one abstract method. If multiple abstract methods are present, the compiler throws an “Unexpected @FunctionalInterface annotation” error. #Types of Functional Interfaces in Java Java 8 introduced four main functional interface types under the package java.util.function. These are widely used in Stream API, collections and lambda-based operations. 1. Consumer -: Consumer interface of the functional interface is the one that accepts only one argument. It is used for performing an action, such as printing or logging. There are also functional variants of the Consumer DoubleConsumer, IntConsumer and LongConsumer. 2. Predicate :- Predicate interface represents a boolean-valued function of one argument. It is commonly used for filtering operations in streams. There are also functional variants of the Predicate IntPredicate, DoublePredicate and LongPredicate. 3. Function:- The function interface takes one argument and returns a result. It is commonly used for transforming data. Several variations exist: Bi-Function: Takes two arguments and returns a result. Unary Operator: Input and output are of the same type. Binary Operator: Like BiFunction but with same input/output type. 4. Supplier:- Supplier functional interface is also a type of functional interface that does not take any input or argument and yet returns a single output. The different extensions of the Supplier functional interface hold many other suppliers functions like BooleanSupplier, DoubleSupplier, LongSupplier and IntSupplier. #leetcode #gfg #interviewbit #Consistency #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
final vs finally vs finalize in Java These three look similar, but they are very different. This is a classic interview question. 🔹 final Used to restrict modification. final variable → value cannot change final method → cannot be overridden final class → cannot be inherited 👉 Used at compile time 🔹 finally Used in exception handling. Always executes Runs whether exception occurs or not Used for cleanup (closing files, DB connections) 👉 Part of try-catch-finally 🔹 finalize() Used by Garbage Collector. Called before object is destroyed Not reliable Rarely used in modern Java 👉 Managed by JVM, not developers 🧠 Quick Tip Control code → final Handle cleanup → finally JVM memory cleanup → finalize() Understanding small differences like this shows strong Core Java fundamentals. 🚀 #Java #CoreJava #JavaInterview #ProgrammingConcepts #BackendDevelopment #JavaDeveloper #LearningInPublic #DevelopersCommunity
To view or add a comment, sign in
-
-
🔓 Unlock the Power of Java String Methods Java Strings look simple — but they quietly power 90% of real-world backend logic. If you truly understand Strings, your Java code becomes: ✅ Cleaner ✅ Faster ✅ Interview-ready 🚀 Must-Know Java String Capabilities 🔹 Manipulation: substring(), charAt(), length() 🔹 Comparison: equals(), equalsIgnoreCase() (never use ==) 🔹 Search & Match: contains(), indexOf(), startsWith() 🔹 Transformation: trim(), replace(), toUpperCase() 🧠 Advanced Concepts Interviewers Love ✔ String immutability & String Pool ✔ StringBuilder vs StringBuffer ✔ Regex with Strings ✔ Performance & memory optimization 💡 Why this matters Strings dominate APIs, logs, validations, data processing, and system design discussions. Master Strings → Master Java fundamentals. #Java #JavaDeveloper #BackendDevelopment #DSA #SystemDesign #Programming #SoftwareEngineering #TechCareers #InterviewPreparation
To view or add a comment, sign in
-
-
🧠 var Keyword in Java — Type Inference Explained #️⃣ var keyword in Java Introduced in Java 10, var allows local variable type inference. 👉 The compiler automatically determines the variable type. 🔹 What is var? var lets Java infer the type from the assigned value. Instead of writing: String name = "Vijay"; You can write: var name = "Vijay"; The compiler still treats it as String. 👉 var is NOT dynamic typing 👉 Type is decided at compile-time 🔹 Why was var introduced? Before var: ⚠ Long generic types ⚠ Repeated type declarations ⚠ Verbose code ⚠ Reduced readability Example: Map<String, List<Integer>> data = new HashMap<>(); With var: var data = new HashMap<String, List<Integer>>(); Cleaner and easier to read. 🔹 Rules of using var ✔ Must initialize immediately ✔ Only for local variables ✔ Cannot use without value ✔ Cannot use for fields or method parameters ✔ Type cannot change after assignment Invalid: var x; // ❌ compile error 🔹 Where should we use var? Use var when: ✔ Type is obvious from right side ✔ Long generic types ✔ Stream operations ✔ Loop variables ✔ Temporary variables Avoid when: ❌ It reduces readability ❌ Type becomes unclear 🧩 Real-world examples var list = List.of(1, 2, 3); var stream = list.stream(); var result = stream.map(x -> x * 2).toList(); Perfect for modern functional style. 🎯 Interview Tip If interviewer asks: Is var dynamically typed? Answer: 👉 No. Java is still statically typed. 👉 var only removes repetition. 👉 Type is fixed at compile-time. 🏁 Key Takeaways ✔ Introduced in Java 10 ✔ Local variable type inference ✔ Reduces boilerplate ✔ Improves readability ✔ Not dynamic typing ✔ Use wisely #Java #Java10 #VarKeyword #ModernJava #JavaFeatures #CleanCode #ProgrammingConcepts #BackendDevelopment #JavaDeepDive #TechWithVijay #VFN #vijayfullstacknews
To view or add a comment, sign in
-
-
final vs finally vs finalize in Java These three terms look similar, but they serve very different purposes in Java. This is a classic interview question and an important Core Java concept. 🔹 final Used to restrict modification. final variable → value cannot change final method → cannot be overridden final class → cannot be inherited 🔹 finally Used in exception handling. Always executes Runs whether an exception occurs or not Commonly used for cleanup (closing files, DB connections) 🔹 finalize() Used by the Garbage Collector. Called before an object is destroyed Not guaranteed to run Rarely used in modern Java 🧠 Quick takeaway Control code → final Handle cleanup → finally JVM memory cleanup → finalize() Clear on this? You’ve covered an important interview favorite. 🚀 #Java #CoreJava #JavaInterview #ProgrammingConcepts #BackendDevelopment #JavaDeveloper #LearningInPublic #DevelopersCommunity
To view or add a comment, sign in
-
-
🚨 Most Java performance issues start with ONE wrong choice. String. StringBuffer. StringBuilder. They look similar… but behave very differently under the hood. This visual breaks it down without code overload, so you can choose right every time 👇 🔹 String — Immutable by Design ✔ Thread-safe by default ✔ Secure & predictable ❌ Creates new objects on every modification 📌 Best for: constants, read-only values ⚠️ Avoid when strings change frequently (loops, concatenation) 🔹 StringBuffer — Mutable + Thread-Safe ✔ Safe in multithreaded environments ✔ Synchronized internally ❌ Slower due to locking overhead 📌 Best for: legacy or concurrent environments where safety > speed 🔹 StringBuilder — Mutable + Fast ✔ Fastest for string operations ✔ No synchronization overhead ❌ Not thread-safe 📌 Best for: single-threaded logic, loops, data processing 🧠 One Line That Wins Interviews String is immutable. StringBuffer is synchronized. StringBuilder is fast. Choose based on: 🔒 Immutability 🧵 Thread safety ⚡ Performance 📌 Pro Tip: If you’re doing string concatenation inside a loop and using String… you’re silently creating performance debt. 💬 Interview question for you: 👉 When would you intentionally choose StringBuffer over StringBuilder? Drop your answer below 👇 Save this for revision ⭐ Share it with someone preparing for Java interviews 🔁 #Java #String #StringBuilder #StringBuffer #JavaInterview #BackendDevelopment #PerformanceOptimization #CleanCode #SoftwareEngineering #SpringBoot
To view or add a comment, sign in
-
-
🚨 Most Java performance issues start with ONE wrong choice. String. StringBuffer. StringBuilder. They look similar… but behave very differently under the hood. This visual breaks it down without code overload, so you can choose right every time 👇 🔹 String — Immutable by Design ✔ Thread-safe by default ✔ Secure & predictable ❌ Creates new objects on every modification 📌 Best for: constants, read-only values ⚠️ Avoid when strings change frequently (loops, concatenation) 🔹 StringBuffer — Mutable + Thread-Safe ✔ Safe in multithreaded environments ✔ Synchronized internally ❌ Slower due to locking overhead 📌 Best for: legacy or concurrent environments where safety > speed 🔹 StringBuilder — Mutable + Fast ✔ Fastest for string operations ✔ No synchronization overhead ❌ Not thread-safe 📌 Best for: single-threaded logic, loops, data processing 🧠 One Line That Wins Interviews String is immutable. StringBuffer is synchronized. StringBuilder is fast. Choose based on: 🔒 Immutability 🧵 Thread safety ⚡ Performance 📌 Pro Tip: If you’re doing string concatenation inside a loop and using String… you’re silently creating performance debt. 💬 Interview question for you: 👉 When would you intentionally choose StringBuffer over StringBuilder? Drop your answer below 👇 Save this for revision ⭐ Share it with someone preparing for Java interviews 🔁 #Java #String #StringBuilder #StringBuffer #JavaInterview #BackendDevelopment #PerformanceOptimization #CleanCode #SoftwareEngineering #SpringBoot
To view or add a comment, sign in
-
-
🚀 Day 10 – Core Java | Data Types, Literals & Type Casting Good afternoon everyone. Today’s session focused purely on core Java fundamentals that are frequently tested in technical aptitude and interviews. 🔑 Topics Covered: ✔ Integer Literals in Java Decimal → 45 Octal → 045 Hexadecimal → 0x45 Binary → 0b100 👉 Regardless of the literal type, output is always printed in decimal ✔ Octal & Hexadecimal Conversion Prefix 0 → Octal Prefix 0x → Hexadecimal Conversion flow: Literal → Binary → Decimal ✔ Binary Grouping Rules Octal → 3-bit grouping Hexadecimal → 4-bit grouping ✔ Type Casting in Java Implicit Type Casting (Widening) byte → short → int → long → float → double Explicit Type Casting (Narrowing) Manual casting required, data loss possible ✔ Real Number Behavior Real number literals are double by default Use suffix f or explicit cast for float ✔ Character & Boolean char → 2 bytes (Unicode) boolean size is JVM-dependent 🎯 Outcome: Clear understanding of how Java stores, converts, and casts data internally, helping avoid mistakes in output-based and logic questions. #Day10 #CoreJava #JavaBasics #TypeCasting #DataTypes #JavaProgramming #InterviewPreparation
To view or add a comment, sign in
Explore related topics
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