Collection
Thursday, June 13, 2024 in Java Interview Questions
Collection A collection in Java is a framework that provides an architecture to store and manipulate a group of objects Collection Ordering Duplicates Null Values Key Characteristics ArrayList Ordered (index) Yes Yes Resizable array and good for …
final vs finally vs finalize
Thursday, June 13, 2024 in Java Interview Questions
final vs finally vs finalize final finally finalize Usage Prevents modification (variables), overriding (methods), or inheritance (classes) Use in try-catch-finally blocks Method invoked by the garbage collector before an object is reclaimed, used …
Garbage Collection
Thursday, June 13, 2024 in Java Interview Questions
Garbage Collection Garbage Collection (GC) in Java is a form of automatic memory management The garbage collector identifies which objects are no longer being used by the application
Stack vs Heap
Thursday, June 13, 2024 in Java Interview Questions
Stack vs Heap Stack Heap Store Method calls, primitive types, reference to objects Objects Management Automatic Manual or Automatic (Garbage Collector)
Abstraction
Thursday, June 13, 2024 in Java Interview Questions
Abstraction Hide complexity, show essentials abstract class vs interface abstract class interface Inheritance Supports single inheritance Supports multiple inheritances Subclass Use extends to inherit Use implements to inherit Instantiation Cannot be …
Polymorphism
Thursday, June 13, 2024 in Java Interview Questions
Polymorphism Same name, different execution Method Overloading Compile-Time Polymorphism Static binding Same method name, different parameter lists Different parameter lists are decided by different number/type/order of parameters Method Overriding …
Inheritance
Thursday, June 13, 2024 in Java Interview Questions
Inheritance Reusing code across classes (creating PARENT-CHILD relationship) extends Used in class declarations to create a subclass that inherits fields and methods from a superclass @Override Subclasses can override methods of the superclass to …
Encapsulation
Thursday, June 13, 2024 in Java Interview Questions
Encapsulation Protect and control access to data Access Modifiers Java provides several access modifiers to set access levels for classes, variables, and methods public Can be accessed from any other class protected Can be accessed from its own …
Constructor
Thursday, June 13, 2024 in Java Interview Questions
Constructor A special method used to initialize objects The constructor has the same name as the class It does not have a return type, not even void It can be overloaded to accept different parameters Type Default Constructor Automatically provided …
Object vs Class
Thursday, June 13, 2024 in Java Interview Questions
Object vs Class Class Object Definition Blueprint for creating objects Instance of a class public class Main { public static void main(String[] args) { Car myCar = new Car("Toyota", 2000); myCar.displayInfo(); // Make by Toyota in 2000 } } …