What is the difference between an object and a class in Java?
An object is an instance of a class. A class is a blueprint or template for creating objects.
What is the difference between a constructor and a method in Java?
A constructor is a special method that is used to initialize an object. It is called when an object is created, and it has the same name as the class. A method is a function that is used to perform a specific action. It can be called on an object at any time.
What is the difference between a static and non-static method in Java?
A static method is a method that can be called on a class, rather than an object. It does not have access to the object’s state. A non-static method is a method that can be called on an object, and it has access to the object’s state.
Learn Java with Real-Time Examples and Programs in English
Last Updated: 2022-04-21
Learn Java from scratch” covers all the essential programming techniques and concepts, that are required to build…
What is the difference between an interface and an abstract class in Java?
An interface is a collection of abstract methods that must be implemented by a class. An abstract class is a class that cannot be instantiated, and it can have both abstract and concrete methods.
What is the difference between a String and a StringBuilder in Java?
A String is an immutable object, meaning that its value cannot be changed once it is created. A StringBuilder is a mutable object, meaning that its value can be modified.
What is the difference between a HashMap and a Hashtable in Java?
A HashMap is not synchronized, while a Hashtable is synchronized. This means that multiple threads can access a HashMap at the same time, while a Hashtable can only be accessed by one thread at a time.
What is the difference between an Array and an ArrayList in Java?
An array is a fixed-size data structure, while an ArrayList is a dynamic data structure. An ArrayList can grow and shrink as needed, while an array has a fixed size that cannot be changed.
What is the difference between a for loop and a for-each loop in Java?
A for loop is used to iterate over an array or a collection, while a for-each loop is used to iterate over the elements of an array or a collection.
What is the difference between a try-catch block and a try-catch-finally block in Java?
A try-catch block is used to catch and handle exceptions, while a try-catch-finally block is used to catch and handle exceptions and to execute code regardless of whether an exception is thrown.
What is the difference between a public and a private method in Java?
A public method can be accessed by any other class, while a private method can only be accessed by the class that defines it.