#Interview-137: Java - What's the difference between final, finally and finalize? The difference between final, finally, and finalize is mainly about their purpose — one is a keyword, one is a block, and one is a method. final (Keyword): restrict something from being changed. • Final variable → value cannot be changed (constant) • Final method → cannot be overridden • Final class → cannot be inherited finally (Block): used in exception handling, and it always executes whether an exception occurs or not. • Used with try-catch • Typically used for cleanup (closing files, DB connections) finalize() (Method): was used for garbage collection cleanup before an object is destroyed. Deprecated in modern Java (Java 9+) In modern Java, instead of finalize(), we prefer using try-with-resources or explicit cleanup methods because finalize() is unreliable and deprecated. #interviewprep #interview #testing #qajobs #jobs #jobsearch #jobseekers #hiring #hiringnow #lookingforjob #manualtesting #testautomation #bdd #cucumber #testng #etltesting #performance #apitesting #softwaretesting #manualtester #qatester
Java final, finally, and finalize differences
More Relevant Posts
-
#Interview-154: Java - Explain method overloading vs method overriding Method Overloading (Compile-time polymorphism) happens when we have multiple methods with the same name but different parameters within the same class. The difference can be in: Number of parameters, Type of parameters, Order of parameters. The method to execute is decided at compile time, so it’s faster and doesn’t involve inheritance. Method Overriding (Runtime polymorphism) happens when a child class provides its own implementation of a method that already exists in the parent class. Same method name + Same parameters + Requires inheritance. The method call is resolved at runtime based on the object type (dynamic binding). #interviewprep #interview #testing #qajobs #jobs #jobsearch #jobseekers #hiring #hiringnow #lookingforjob #manualtesting #testautomation #bdd #cucumber #testng #etltesting #performance #apitesting #softwaretesting #manualtester #qatester
To view or add a comment, sign in
-
#Interview-143: Java - Can you create an object of an interface? Why or Why not? No, we cannot directly create an object of an interface in Java. An interface is just a blueprint, not a complete implementation. It only contains method declarations (at least conceptually), and doesn’t provide the full behaviour needed to create an object. We can create a reference of an interface, but the actual object will be of a class that implements that interface. Can we ever “create” an interface object? Indirectly, yes. We can use: Anonymous classes OR Lambda expressions (for functional interfaces). #interviewprep #interview #testing #qajobs #jobs #jobsearch #jobseekers #hiring #hiringnow #lookingforjob #manualtesting #testautomation #bdd #cucumber #testng #etltesting #performance #apitesting #softwaretesting #manualtester #qatester
To view or add a comment, sign in
-
#Interview-146: Java - What is String Constant Pool? String Constant Pool in Java is a special memory area inside the heap where Java stores string literals. Whenever we create a string like: String s1 = "Hello"; String s2 = "Hello"; Java doesn’t create two separate objects. Instead, it checks the String Constant Pool, and if the value already exists, it reuses the same object. So here, both s1 and s2 actually point to the same memory location. It’s mainly for memory optimization. Since strings are widely used and are immutable in Java, reusing them saves memory and improves performance. Now compare this with using new: String s3 = new String("Hello"); In this case, Java creates a new object in heap memory, even if "Hello" already exists in the pool. So: • "Hello" → goes to String Pool • new String("Hello") → creates a separate object outside the pool Important concept: immutability - Strings in Java are immutable, which means once created, their value cannot be changed. That’s what makes pooling safe—because no one can modify the shared string. #interviewprep #interview #testing #qajobs #jobs #jobsearch #jobseekers #hiring #hiringnow #lookingforjob #manualtesting #testautomation #bdd #cucumber #testng #etltesting #performance #apitesting #softwaretesting #manualtester #qatester
To view or add a comment, sign in
-
Java Developer Interview (3–4 Years Experience) – Here’s a concise list of questions I was asked along with one-liner answers -- Java 17 Features LTS version with features like records, sealed classes, pattern matching, and improved performance. -- what changes done in Java 17 for GC -- Java 8 Features Introduced lambda, streams, functional interfaces, Optional, and new Date-Time API. -- Functional Interface An interface with exactly one abstract method, used for lambda expressions. -- Static Method Use Cases Used for utility methods, shared logic, and when no object state is required. -- Method Reference Shorthand for lambda expressions using :: to directly refer to methods. -- Ways to Create Thread Thread class, Runnable, Lambda, Callable + Future, CompletableFuture. -- CompletableFuture Used for asynchronous programming and combining independent tasks. -- Stream API (Intermediate vs Terminal) Intermediate → lazy transformations; Terminal → triggers execution and gives result. -- map vs flatMap map = one-to-one transformation; flatMap = one-to-many + flattening. -- Memory Issues in Java 8 Heap OOM, Metaspace OOM, memory leaks, GC overhead, stack overflow. -- YAML vs Properties YAML is hierarchical and readable; properties are flat key-value pairs. -- Externalized Configuration (Spring Boot) Store config outside code using properties, YAML, env variables, or command-line. -- Circuit Breaker Prevents cascading failures by stopping calls to failing services and using fallback. -- Orchestration vs Choreography Orchestration = central control; Choreography = event-driven decentralized flow. -- Transaction Propagation Defines how transactions behave when one method calls another (e.g., REQUIRED, REQUIRES_NEW). -- Merging Arrays (Java 8) Use Stream/CompletableFuture to combine arrays cleanly. #java #interviewexperience ##interviewexperience #springboot #backenddeveloper #careergrowth #experiencedhire #javadeveloper
To view or add a comment, sign in
-
🧠 Java Developers — Can you answer this without running the code? ```java public class Test { public static void main(String[] args) { String a = "Java"; String b = "Java"; String c = new String("Java"); System.out.println(a == b); System.out.println(a == c); System.out.println(a.equals(c)); } } ``` What is the output? 👇 🔘 true / true / true 🔘 true / false / true 🔘 false / false / true 🔘 false / false / false ━━━━━━━━━━━━━━━━ 💡 Hint: Think about String Pool vs Heap Memory! ━━━━━━━━━━━━━━━━ Comment your answer below with explanation 👇 Let's see how many real Java developers are in my network! 🚀 Tag a Java developer who should know this! 👨💻 #Java #JavaDeveloper #SpringBoot #CodingChallenge #JavaInterview #Programming #SoftwareEngineering #TechQuiz #LinkedInPoll #Pakistan
To view or add a comment, sign in
-
🚀 Java Interview Series – Day 22 What is an Interface in Java? An interface in Java is a contract that defines what a class should do, but not how it should do it. It contains method declarations (by default public and abstract) that implementing classes must define. 🔹 Key characteristics: • Cannot have concrete method implementations (before Java 8) • Supports multiple inheritance • Helps achieve abstraction • Promotes loose coupling Why is this important? ✔ Enables flexible and scalable system design ✔ Allows multiple implementations of the same contract ✔ Makes code easier to test and maintain 💡 Example: A Payment interface can define a method pay(). Different classes like CreditCardPayment, UPIPayment, and NetBankingPayment implement it differently. ⚡ Key Insight: Modern Java (8+) allows: default methods (with implementation) static methods inside interfaces This makes interfaces more powerful than before. 💬 Interview Tip: Always mention: Interface = contract Multiple inheritance Real-world use case Java 8 enhancements Interfaces are at the heart of frameworks like Spring and are heavily used in building scalable and loosely coupled systems. #Java #JavaDeveloper #OOP #Interface #Abstraction #SoftwareEngineering #BackendDevelopment #CleanCode #TechInterview #CodingInterview #SystemDesign #Developers #LearningInPublic #CareerGrowth #IndiaJobs #USJobs #UKJobs #AustraliaJobs
To view or add a comment, sign in
-
-
Ever faced a bug in production where everything looked fine in code review, but failed because of one small issue? Java Bug Fix Interview Question: A payment service is getting duplicate transactions even though the API is called only once. Question: What is the bug in this code and how would you fix it? The code is not thread-safe. If two threads enter "processPayment()" at the same time, both can see "isProcessing = false" and process duplicate payments. Possible Fixes: - synchronized method - ReentrantLock - AtomicBoolean - Distributed lock for microservices This type of question is very common for backend, Java, multithreading, and production support interviews. #Java #Backend #Multithreading #InterviewQuestions #SpringBoot #JavaDeveloper #Concurrency #CodingInterview
To view or add a comment, sign in
-
-
What is immutable (Java)? In Java, immutability means an object cannot be changed after it is created. A good example is String. When you modify a string, you are not changing the original object, you are creating a new one. Why this matters: If you call a method like concat() and don’t store the result, nothing changes. So even though it looks like you’re modifying the value, Java keeps the original object unchanged. #java #interview #immutable #certification
To view or add a comment, sign in
-
-
💻 Interview Experience – Java Developer (Technical Round) I recently attended a technical interview for a Java Developer role and wanted to share my experience. 🔹 Topics Covered: Core Java concepts (OOPs, Collections, Exception Handling) Difference between List, Set, and Map Java 8 features (Streams, Lambda expressions) Writing programs like prime numbers and sorting Basics of Spring Boot and REST API development SQL queries (joins, normalization basics) 🔹 Coding Questions: Print prime numbers from 1 to 100 Count occurrences of elements using Stream API Simple logic-based problem-solving 💡 Key Takeaways: Strong understanding of Core Java is essential Practice coding regularly, especially logic building Be confident while explaining your approach Focus on real-time use cases, not just theory Overall, it was a good learning experience and helped me understand where I need to improve. #Java #TechnicalInterview #Coding #SpringBoot #DeveloperJourney
To view or add a comment, sign in
-
💻 Interview Experience – Java Developer (Technical Round) I recently attended a technical interview for a Java Developer role and wanted to share my experience. 🔹 Topics Covered: Core Java concepts (OOPs, Collections, Exception Handling) Difference between List, Set, and Map Java 8 features (Streams, Lambda expressions) Writing programs like prime numbers and sorting Basics of Spring Boot and REST API development SQL queries (joins, normalization basics) 🔹 Coding Questions: Print prime numbers from 1 to 100 Count occurrences of elements using Stream API Simple logic-based problem-solving 💡 Key Takeaways: Strong understanding of Core Java is essential Practice coding regularly, especially logic building Be confident while explaining your approach Focus on real-time use cases, not just theory Overall, it was a good learning experience and helped me understand where I need to improve. #Java #TechnicalInterview #Coding #SpringBoot #DeveloperJourney
To view or add a comment, sign in
More from this author
-
Interview #443: Can you explain API chaining with an example?
Software Testing Studio | WhatsApp 91-6232667387 9h -
What is Agentic QA
Software Testing Studio | WhatsApp 91-6232667387 1d -
Interview #442: Postman - How do you manage different environments like QA, UAT, and Production?
Software Testing Studio | WhatsApp 91-6232667387 2d
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