GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing hackr.io — Top 80 Java Interview Questions and Answers [2026] To land the job, it helps to review common and challenging Java interview questions. After all, the class-based, general-purpose, object-oriented programming language is one of the most widely used programming languages in the world. We prepared these Java interview questions with answers from experts. Expect to cover the basics with beginner-friendly topics and much more advanced challenges with specific code to help professional Software Developers and Android Applications Developers. Remember that, with a plethora of great features, the programming language is preferred not only by seasoned experts but also by those new to the programming world. Our interview questions start with basic Java concepts and progress to much more difficult challenges. Whether you're seeking a new gig or hiring to expand your team, read on to review the best Java interview questions for 2025. Top Java Interview Questions and AnswersWe also recommend you brush up on your Java skills with this Java Cheat Sheet before starting your Java interview preparation. We have divided these interview questions into several sections. Check the breakdown below to review basic, advanced, OOPs, exception handling, and programming Java interview questions. We also have specific examples of code. Review the coding Java interview questions section for reference. Basic Java Interview Questions1. What is Java?Java is an object-oriented, high-level, general-purpose programming language originally designed by James Gosling and further developed by the Oracle Corporation. It is one of the most popular programming languages in the world. 2. What is the Java Virtual Machine?
JVM is a program that interprets the intermediate Java byte code and generates the desired output. It is because of bytecode and JVM that programs written in Java are highly portable. 3. What are the features of Java?The following are the various features of the Java programming language:
You may want to check out detailed explanations of Java features here. 4. How does Java enable high performance?In Just-in-Time compilation, the required code is executed at run time. Typically, it involves translating bytecode into machine code and then executing it directly. It allows for high performance. The JIT compiler is enabled by default in Java and gets activated as soon as a method is called. It then compiles the bytecode of the Java method into native machine code. After that, the JVM calls the compiled code directly instead of interpreting it. 5. What are the differences between JVM, JRE, and JDK?
6. What is the JIT compiler?JIT compiler runs after the program is executed and compiles the code into a faster form, hosting the CPU's native instructing set. JIT can access dynamic runtime information, whereas a standard compiler doesn't and can make better optimizations like inlining functions that are used frequently. 7. What are Java IDEs?A Java IDE is a software that allows Java developers to easily write as well as debug Java programs. It is basically a collection of various programming tools, accessible via a single interface, and several helpful features, such as code completion and syntax highlighting. Codenvy, Eclipse, and NetBeans are some of the most popular Java IDEs. 8. Java is a platform-independent language. Why?Java does not depend on any particular hardware or software because it is compiled by the compiler and then converted into byte code. Byte code is platform-independent and can run on multiple systems. The only requirement is that Java needs a runtime environment, i.e., JRE, which is a set of tools used for developing Java applications. 9. Explain Typecasting.The concept of assigning a variable of one data type to a variable of another data type. This is not possible for the boolean data type. There are two types: implicit and explicit. 10. What are the different types of typecasting?
The different types of typecasting are:
After execution, the variable i will contain only 3 and not the decimal portion.
long l = 123456789; byte b = (byte) l; // byte is of not the same range as long so there will be loss of data. 11. Explain access modifiers in Java.Access modifiers are predefined keywords in Java that are used to restrict the access of a class, method, constructor, and data member in another class. Java supports four access modifiers:
12. What are the default values for local variables?The local variables are not initialized to any default value, neither primitives nor object references. OOPs Java Interview Questions13. What is Object-Oriented Programming?OOPs is a programming paradigm centered around objects rather than functions. It is not a tool or a programming language, it is a paradigm that was designed to overcome the flaws of procedural programming. There are many languages that follow OOPs concepts — some popular ones are Java, Python, and Ruby. Some frameworks also follow OOPs concepts, such as Angular. 14. Explain the OOPs concepts.The following are the various OOPS Concepts:
Decision Making Java Interview Questions 15. Differentiate between break and continue.
Classes, Objects, and Methods Java Interview Questions16. What is an Object?An instance of a Java class is known as an object. Two important properties of a Java object are behavior and state. An object is created as soon as the JVM comes across the new keyword. 17. Define classes in Java.A class is a collection of objects of similar data types. Classes are user-defined data types and behave like built-in types of a programming language. Syntax of a class: Example of Class: 18. What are static methods and variables?A class has two sections: one declares variables, and the other declares methods. These are called instance variables and instance methods, respectively. They are termed so because every time a class is instantiated, a new copy of each of them is created. Variables and methods can be created that are common to all objects and accessed without using a particular object by declaring them static. Static members are also available to be used by other classes and methods. 19. What do you mean by Constructor?A constructor is a method that has the same name as that of the class to which it belongs. As soon as a new object is created, a constructor corresponding to the class gets invoked. Although the user can explicitly create a constructor, it is created on its own as soon as a class is created. This is known as the default constructor. Constructors can be overloaded. If an explicitly-created constructor has a parameter, then it is necessary to create another constructor without a parameter. 20. What are local variables and instance variables?Variables that are only accessible to the method or code block in which they are declared are known as local variables. Instance variables, on the other hand, are accessible to all methods in a class. While local variables are declared inside a method or a code block, instance variables are declared inside a class but outside a method. Even when not assigned, instance variables have a value that can be null, 0, 0.0, or false. This isn't the case with local variables that need to be assigned a value, where failing to assign a value will yield an error. Local variables are automatically created when a method is called and destroyed as soon as the method exits. For creating instance variables, the new keyword must be used. 21. What is Method Overriding?
Method overriding in Java allows a subclass to offer a specific implementation of a method that has already been provided by its parent or superclass. Method overriding happens if the subclass method and the Superclass method have:
22. What is Overloading?
Overloading is the phenomenon when two or more different methods (method overloading) or operators (operator overloading) have the same representation. For example, the + operator adds two integer values but concatenates two strings. Similarly, an overloaded function called Add can be used for two purposes
Unlike method overriding, method overloading requires two overloaded methods to have the same name but different arguments. The overloaded functions may or may not have different return types. 23. What role does the final keyword play in Java? What impact does it have on a variable, method, and class?The final keyword in Java is a non-access modifier that applies only to a class, method, or variable. It serves a different purpose based on the context where it is used.
Arrays, Strings and Vectors Java Interview Questions24. Draw a comparison between Array and ArrayList.An array necessitates stating the size during the time of declaration, while an array list doesn't necessarily require size as it changes size dynamically. To put an object into an array, there is the need to specify the index. However, no such requirement is in place for an array list. While an array list is parameterized, an array is not parameterized. 25. What are the differences between String, Stringbuilder, and Stringbuffer?String variables are stored in a constant string pool. With the change in the string reference, it becomes impossible to delete the old value. For example, if a string has stored a value "Old," then adding the new value "New" will not delete the old value. It will still be there, however, in a dormant state. In a Stringbuffer, values are stored in a stack. With the change in the string reference, the new value replaces the older value. The Stringbuffer is synchronized (and therefore, thread-safe) and offers slower performance than the StringBuilder, which is also a Stringbuffer but is not synchronized. Hence, performance is faster in Stringbuilder than the Stringbuffer. 26. What is the String Pool?The string pool is a collection of strings stored in the heap memory refers to. Whenever a new object is created, it is checked if it is already present in the string pool. If it is already present, then the same reference is returned to the variable, otherwise a new object is created in the string pool, and the respective reference is returned. Advanced Java Interview QuestionsInterfaces and Abstract Classes Java Interview Questions27. What do you know about Interfaces?A Java interface is a template that has only method declarations and not method implementations. It is a workaround for achieving multiple inheritances in Java. Some worth remembering important points regarding Java interfaces are:
28. How is an Abstract class different from an Interface?There are several differences between an Abstract class and an Interface in Java, summed up as follows:
29. Please explain Abstract class and Abstract method.An abstract class in Java is a class that can't be instantiated. Such a class is typically used for providing a base for subclasses to extend as well as implementing the abstract methods and overriding or using the implemented methods defined in the abstract class. To create an abstract class, it needs to be followed by the abstract keyword. Any abstract class can have both abstract as well as non-abstract methods. A method in Java that only has the declaration and not implementation is known as an abstract method. Also, an abstract method name is followed by the abstract keyword. Any concrete subclass that extends the abstract class must provide an implementation for abstract methods. 30. What is multiple inheritance? Does Java support multiple inheritance? If not, how can it be achieved?If a subclass or child class has two parent classes, that means it inherits the properties from two base classes; it has multiple inheritances. Java does not have multiple inheritances as in case the parent classes have the same method names. Then at runtime, it becomes ambiguous, and the compiler is unable to decide which method to execute from the child class. Packages Java Interview Questions31. What are packages in Java? State some advantages.
Packages are Java's way of grouping a variety of classes and/or interfaces together. The functionality of the objects decides how they are grouped. Packagers act as "containers" for classes. Enlisted below are the advantages of Packages:
Multithreading Java Interview Questions32. How do you make a thread in Java? Give examples.To make a thread in Java, there are two options:
A disadvantage of using the thread class is that it becomes impossible to extend any other classes. Nonetheless, it is possible to overload the run() method in the class
33. Why do we use the yield() method?The yield() method belongs to the thread class. It transfers the currently running thread to a runnable state and also allows the other threads to execute. In other words, it gives equal priority threads a chance to run. Because yield() is a static method, it does not release any lock. 34. Explain the thread lifecycle in Java.
The thread lifecycle has the following states and follows the following order:
35. When is the Runnable interface preferred over thread class and vice-versa?In Java, it is possible to extend only one class. Hence, the thread class is only extended when no other class needs to be extended. If it is required for a class to extend some other class than the thread class, then we need to use the Runnable interface. 36. Draw a comparison between notify() and notifyAll() methods.The notify() method is used for sending a signal to wake up a single thread in the waiting pool. Contrarily, the notifyAll() method is used for sending a signal to wake up all threads in a waiting pool. 37. How will you distinguish processes from threads?There are several fundamental differences between a process and a thread, stated as follows:
38. What is the join() method? Give an example.We use the join() method for joining one thread with the end of the currently running thread. It is a non-static method and has an overloaded version. Consider the example below: The main thread starts execution in the example mentioned above. As soon as the execution reaches the code t.start(), then the thread t starts its stack for execution. The JVM switches between the main thread and the thread there. Once the execution reaches the t.join(), then the thread t alone is executed and allowed to complete its task. Afterwards, the main thread resumes execution. 39. How do you make a thread stop in Java?There are three methods in Java to stop the execution of a thread:
Exception Handling Java Interview Questions40. What are the various types of exceptions? How do you handle them?Java has provision for two types of exceptions:
Exceptions in Java are handled in two ways: Declaring the throws keyword: We can declare the exception using throws keyword at the end of the method. For example: Using try/catch: Any code segment that is expected to yield an exception is surrounded by the try block. Upon the occurrence of the exception, it is caught by the catch block that follows the try block. For example: 41. Draw the Java Exception Hierarchy.
42. Is it possible to write multiple catch blocks under a single try block?Yes, it is possible to write several catch blocks under a single try block. However, the approach needs to be from specific to general. The following example demonstrates it: 43. How does the throw keyword differ from the throws keyword?While the throws keyword allows declaring an exception, the throw keyword is used to explicitly throw an exception. Checked exceptions can't be propagated with throw only, but throws allow doing so without the need for anything else. The throws keyword is followed by a class, whereas the throw keyword is followed by an instance. The throw keyword is used within the method, but the throws keyword is used with the method signature. Furthermore, it is not possible to throw multiple exceptions, but it is possible to declare multiple exceptions. 44. Explain various exceptions handling keywords in Java.There are two crucial exception handling keywords in Java, followed by the third keyword final, which may or may not be used after handling exceptions. try: If and when a code segment has chances of having an abnormality or an error, it is placed within a try block. When the exception is raised, it is handled and caught by the catch block. The try block must have a catch() or a final() or both blocks after it. catch: When an exception is raised in the try block, it is handled in the catch block. final: This block is executed regardless of the exception. It can be placed either after try{} or catch {} block. 45. Explain exception propagation.The method at the top of the stack throws an exception if it is not caught. It moves to the next method and goes on until caught. Example: The stack of the above code is: If an exception occurred in the add() method is not caught, then it moves to the method addition(). It is then moved to the main() method, where the flow of execution stops. It is called Exception Propagation. File Handling Java Interview Questions46. Is an empty file name with .java extension a valid file name?Yes, Java permits us to save our java file by .java only. It is compiled by javac and run by the java class name. Here’s an example: To compile: javac.java To run: Java Any Collections Java Interview Questions47. What are collections? What are their constituents?A group of objects in Java is known as collections. Java.util package contains, along with date and time facilities, internationalization, legacy collection classes, etc., the various classes and interfaces for collecting. Alternatively, collections can be considered as a framework designed for storing the objects and manipulating the design in which the objects are stored. You can use collections to perform the following operations on objects:
Following are the various constituents of the collections framework:
48. How do you differentiate HashMap and HashTable?HashMap in Java is a map-based collection class, used for storing key & value pairs. It is denoted as HashMap<Key, Value> or HashMap<K, V> HashTable is an array of a list, where each list is called a bucket. Values contained in a HashTable are unique and depend on the key. Methods are not synchronized in HashMap, while key methods are synchronized in HashTable. However, HashMap doesn't have thread safety, while HashTable has the same. For iterating values, HashMap uses an iterator and HashTable uses an enumerator. HashTable doesn't allow anything that is null, while HashMap allows one null key and several null values. In terms of performance, HashTable is slow. Comparatively, HashMap is faster. 49. What is a Map and what are the types?A Java Map is an object that maps keys to values. It can't contain duplicate keys, and each key can map to only one value. In order to determine whether two keys are the same or distinct, Map makes use of the equals() method. There are 4 types of Map in Java, described as follows:
50. What is a Priority Queue?A priority queue, like a regular queue, is an abstract data type, but it has a priority associated with each element contained by it. The element with the high priority is served before the element with low priority in a priority queue. Elements in a priority queue are ordered either according to the comparator or naturally. The order of the elements in a priority queue represents their relative priority. 51. What is a Set? Explain the types in Java Collections.In Java, a set is a collection of unique objects. It uses the equals() method to determine whether two objects are the same or not. The various types of set in Java Collections are:
52. What is ordered and sorted when it comes to collections?
Miscellaneous Java Interview Questions53. What are the various types of garbage collectors in Java?The Java programming language has four types of garbage collectors:
54. What do you understand by synchronization? What is its most significant disadvantage?If several threads try to access a single block of code, then there is an increased chance of producing inaccurate results. Synchronization is used to prevent this. Using the synchronization keyword makes a thread need a key to access the synchronized code. Simply, synchronization allows only one thread to access a block of code at a time. Each Java object has a lock, and every lock has only one key. A thread can access a synchronized method only if it can get the key to the lock of the object. The following example demonstrates synchronization: Note: It is recommended to avoid implementing synchronization for all methods. This is because when only one thread can access the synchronized code, the next thread needs to wait. Consequently, it results in slower performance of the program. 55. What is the difference between execute(), executeQuery(), and executeUpdate()?
Note: The execute() method needs to be used only in a scenario when there is no certainty about the type of statement. In all other cases, either use executeQuery() or executeUpdate() method. 56. Provide an example of the Hibernate architecture.
57. Could you demonstrate how to delete a cookie in JSP with a code example?The following code demonstrates deleting a cookie in JSP: 58. Write suitable code examples to demonstrate the use of final, final, and finalize.Final: The final keyword is used for restricting a class, method, and variable. A final class can't be inherited, a final method is disabled from overriding, and a final variable becomes a constant i.e., its value can't be changed. Finally: Any code inside the final block will be executed, irrespective of whether an exception is handled or not. Finalize: The finalize method performs the clean up just before the object is garbage collected. 59. What purpose does the Volatile variable serve?The value stored in a volatile variable is not read from the thread's cache memory but from the main memory. Volatile variables are primarily used during synchronization. 60. Please compare serialization and deserialization.Serialization is the process by which Java objects are converted into the byte stream. Deserialization is the exact opposite process of serialization where Java objects are retrieved from the byte stream. A Java object is serialized by writing it to an ObjectOutputStream and deserialized by reading it from an ObjectInputStream. 61. What is OutOfMemoryError?Typically, the OutOfMemoryError exception is thrown when the JVM is not able to allocate an object due to running out of memory. In such a situation, no memory could be reclaimed by the garbage collector. There can be several reasons that result in the OutOfMemoryError exception, of which the most notable ones are:
62. Explain public static void main(String args[ ]) in JavaThe execution Java program starts with public static void main(String args[ ]), also called the main() method.
Java Programming Masterclass Updated to Java 17 63. What are wrapper classes in Java?Wrapper classes are responsible for converting the Java primitives into the reference types (objects). A class is dedicated to every primitive data type. They are known as wrapper classes because they wrap the primitive data type into an object of that class. It is present in the Java.lang package. The table below displays the different primitive types and wrapper classes.
64. Explain the concept of boxing, unboxing, autoboxing, and auto unboxing.
65. Define the Singleton class. How can a class be made Singleton?A Singleton class allows only one instance of the class to be created. A class can be made singleton with the following steps:
66. What if the public static void is replaced by static public void, will the program still run?Yes, the program would compile and run without any errors as the order of the specifiers doesn't matter. 67. What is the difference between == and equals()?
68. Why don't we use pointers in Java?Pointers are considered to be unsafe, and increase the complexity of the program, adding the concept of pointers can be contradicting. Also, JVM is responsible for implicit memory allocation; thus, to avoid direct access to memory by the user, pointers are discouraged in Java. 69. What is the difference between this() and super()?
Java Coding Interview QuestionsApart from having good knowledge about concepts of Java programming, you are also tested for your skills in coding in Java programming language. The following are Java coding interview questions that are relevant for freshers and are quite popular amongst Java programming interviews. 70. Take a look at the two code snippets below. What is the important difference between the two?i. ii. Code snippet i. is an example of method overloading while the code snippet ii. demonstrates method overriding. 71. Write a program for string reversal without using an inbuilt function.72. Write a program to delete duplicates from an array.73. Write a program to reverse a number.74. Write a program that implements binary search.75. Write a program to check if a number is prime.76. Write a program to print Fibonacci series.77. Write a program to check if the given string is a palindrome.78. Write a program to print the following pattern.* * * * * * * * * * * * * * * Answer: 79. Write a program to swap two numbers.80. Write a program to check if the given number is an Armstrong number.SummaryThese core Java Interview Questions and Java Programming Interview Questions are a great way to prepare you for the interview. Review the answers, including the coding examples, and put your best foot forward. Please note that we also provided a PDF for your preparation so that you can download and learn and prepare on the go: Download Java Interview Questions PDF Prefer on-demand videos? Check out this course for further reading and preparation for a Java-based interview: Java Interview Guides: 200+ Interview Question and Answer Otherwise, we recommend this book to help you succeed in your future Java interviews: Elements of Programming Interviews in Java: The insider guide second edition Frequently Asked Questions1. What are the basic Java questions asked in an interview?There are several basic Java interview questions that can appear in an interview. Look at the ones we’ve listed above to get a sense of them. 2. How should I prepare for a Java interview?You should prepare for a Java interview by learning both the theory and practicing coding. There are several related questions above. 3. What are the advanced Java interview questions?Advanced Java interview questions can be of many kinds, including both theory and coding-based questions. Check out the list of Java programming questions above to see what they are like. People are also reading:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |