top of page
Interesting Recent Posts :
Writer's pictureRohit chopra

30 important Java Interview Questions : Must Know




What do you think is more important concept in Java from interview perspective?

  • 0%Reflections

  • 0%Collections

  • 0%Inheritance/Polymorphism

  • 0%Concept of Strings



  1. What is the difference between an interface and an abstract class in Java? Answer: An interface is a contract that defines a set of methods without providing any implementation. An abstract class, on the other hand, can provide both abstract and concrete methods. A class can implement multiple interfaces but can extend only one abstract class.

  2. What is the difference between == and equals() method in Java? Answer: == is used to compare the references of two objects, whereas equals() method is used to compare the content of two objects.

  3. What is a singleton class in Java? Answer: A singleton class is a class that can have only one instance in the JVM. The instance is created once and reused throughout the application.

  4. What is the difference between static and non-static methods in Java? Answer: A static method belongs to the class and not to the instance of the class. A non-static method belongs to the instance of the class.

  5. What is the difference between static and non-static variables in Java? Answer: A static variable belongs to the class and not to the instance of the class. A non-static variable belongs to the instance of the class.

  6. What is a final class in Java? Answer: A final class is a class that cannot be subclassed.

  7. What is a final method in Java? Answer: A final method is a method that cannot be overridden by its subclasses.

  8. What is a final variable in Java? Answer: A final variable is a variable that can only be assigned a value once and cannot be changed thereafter.

  9. What is the difference between a public and a private constructor in Java? Answer: A public constructor can be accessed from anywhere in the application. A private constructor can only be accessed from within the class.

  10. What is the difference between an exception and an error in Java? Answer: An exception is a problem that can occur during the execution of a program and can be handled by the program. An error is a problem that occurs at the system level and cannot be handled by the program.

  11. What is the difference between a checked and an unchecked exception in Java? Answer: A checked exception is an exception that must be handled by the program. An unchecked exception is an exception that need not be handled by the program.

  12. What is the purpose of the finally block in Java? Answer: The finally block is used to execute code that must be executed irrespective of whether an exception occurs or not.

  13. What is the difference between a stack and a heap memory in Java? Answer: A stack is used to store primitive data types and object references. A heap is used to store objects.

  14. What is the purpose of the finalize() method in Java? Answer: The finalize() method is used to perform cleanup actions on an object before it is garbage collected.

  15. What is the difference between a thread and a process in Java? Answer: A thread is a lightweight unit of execution within a process. A process is an independent unit of execution that has its own memory space.

  16. What is the purpose of the synchronized keyword in Java? Answer: The synchronized keyword is used to prevent multiple threads from accessing the same code block or method simultaneously.

  17. What is a deadlock in Java? Answer: A deadlock occurs when two or more threads are blocked waiting for each other to release a resource.

  18. What is a race condition in Java? Answer: A race condition occurs when two or more threads access a shared resource simultaneously and the final result depends on the order of execution.

  19. What is the difference between a HashMap and a Hashtable in Java? Answer: A HashMap is not synchronized and allows null values and keys. A Hashtable is synchronized and does not allow null values and keys.

  20. What is the difference between a HashMap and a Hashtable in Java? Answer: A HashMap is not synchronized and allows null values and keys. A Hashtable is synchronized and does not allow null values and keys.

  21. What is the difference between an ArrayList and a LinkedList in Java? Answer: An ArrayList is implemented as an array and provides constant time access to its elements. A LinkedList is implemented as a linked list and provides constant time insertion and deletion of elements from the list.

  22. What is the difference between an inner class and a nested class in Java? Answer: An inner class is a non-static nested class that has access to the instance variables and methods of its outer class. A nested class can be either a static nested class or an inner class.

  23. What is the purpose of the @Override annotation in Java? Answer: The @Override annotation is used to indicate that a method in a subclass is intended to override a method with the same name and signature in its superclass.

  24. What is the purpose of the super keyword in Java? Answer: The super keyword is used to refer to the superclass of a class and can be used to call its constructors, methods, and instance variables.

  25. What is the purpose of the this keyword in Java? Answer: The this keyword is used to refer to the current object and can be used to access its instance variables and methods.

  26. What is polymorphism in Java? Answer: Polymorphism is the ability of an object to take on multiple forms. In Java, polymorphism can be achieved through method overloading and method overriding.

  27. What is method overloading in Java? Answer: Method overloading is the ability to define multiple methods with the same name in a class, but with different parameters.

  28. What is method overriding in Java? Answer: Method overriding is the ability of a subclass to provide its own implementation of a method that is already defined in its superclass.

  29. What is the purpose of the final keyword in Java? Answer: The final keyword can be used to declare a variable, method, or class as constant, or to prevent it from being overridden, or to prevent a subclass from being created.

  30. What is the purpose of the transient keyword in Java? Answer: The transient keyword is used to indicate that a variable should not be serialized when an object is written to a file or transmitted over a network.




 

Checkout these important concepts --






216 views

Recent Posts

See All

Comments


bottom of page