Categories
Top 50 Java Interview Questions and Answers
Java is most widely used programming language in the current IT industry. One major reason for the vast number of beginners and professionals in the field of programming is the career potential that Java knowledge comes with. This article is dedicated to the same purpose. Here is a complete guide on how to help you crack the most frequently asked Core Java Interview questions.
1. What are the differences between C++ and Java?
Concept.
C++ is not platform-independent; the principle behind C++ programming is “write once, compile anywhere.”
In contrast, because the byte code generated by the Java compiler is platform-independent, it can run on any machine, Java programs are written once and run everywhere.
Languages Compatibility.
C++ is a programming language that is based on the C programming language. Most other high-level languages are compatible with C++.
Interaction with the library.
It can access the native system libraries directly in C++. As a result, it’s better for programming at the system level.
Java’s native libraries do not provide direct call support. You can use Java Native Interface or access the libraries.
Characteristics
C++ distinguishes itself by having features that are similar to procedural and object-oriented languages. The characteristic that sets Java apart is automatic garbage collection. Java doesn’t support destructors at the moment.
The semantics of the type.
Primitive and object types in C++ have the same kind of semantics. The primitive and object and classes of Java, on the other hand, are not consiste
In the context of Compiler and Interpreter.
Java refers to a compiled and interpreted language. In contrast, C++ is only a compiled language.
In Java, the source code is the compiled output is a platform-independent byte code.
In C++, the source program is compiled into an object code that is further executed to produce an output.
2. What is an Association?
3. What is the default value stored in Local Variables?
4. Will the program run if we write static public void main?
5. What are the differences between Heap and Stack Memory in Java?
6. What are the Memory Allocations available in Java?
1) Class Memory
2) Heap Memory
3) Stack Memory
4) Program Counter-Memory
5) Native Method Stack Memory
7. What is a ClassLoader?
Java has Bootstrap, Extension, and Application classloaders.
8. List the features of the Java Programming language?
Easy:
Java is a language that is considered easy to learn. One fundamental concept of OOP Java has a catch to understand.
Secured Feature:
Java has a secured feature that helps develop a virus-free and tamper-free system for the users.
OOP:
OOP stands for Object-Oriented Programming language. OOP signifies that, in Java, everything is considered an object.
Independent Platform:
Java is not compiled into a platform-specific machine; instead, it is compiled into platform-independent bytecode. This code is interpreted by the Virtual Machine on which the platform runs.
9. What do you get in the Java download file? How do they differ from one another?
JDK - Java Development Kit
JRE - Java Runtime Environment
10. What are the differences between JDK and JRE?
JDK | JRE |
Abbreviation for JavaDevelopment Kit | Abbreviation for Java Runtime Environment |
JDK is a dedicated kit for solely software development | JRE is a set of software and library designed for executing Java Programs |
Unlike JVM, JDK is Platform Dependent | Unlike JVM, JRE is also Platform Dependent |
JDK package is a set of tools for debugging and Developing | JRE Package is one that only supports files and libraries for a runtime environment |
JDK package will be provided with an installer file | JRE Package does not get an installer but has only a runtime environment |
11. Can you implement pointers in a Java Program?
12. Define package in Java.
13. What is a singleton class in Java? And How to implement a singleton class?
1) Make sure that the class has only one object
2) Give global access to that object
14. Define Wrapper Classes in Java.
15. What is an object-oriented paradigm?
16. Can Java be said to be the complete object-oriented programming language
17. What is Object Cloning?
18. What is a Marker Interface?
19. Define Copy Constructor in Java
20. What do you mean by aggregation?
21. What happens when the main() isn't declared as static?
22. What is the final keyword in Java?
23. What is an Exception?
24. Explain Java String Pool.
25. Differentiate between instance and local variables.
A local variable can be anywhere inside a method or a specific block of code. Also, the scope is limited to the code segment where the variable is declared.
26. What are the differences between constructor and method of a class in Java?
27. What is the difference between the program and the process?
28. What part of memory - Stack or Heap - is cleaned in the garbage collection process?
29. Why is the main method static in Java?
30. Why is Java a platform independent language?
31. How does an exception propagate in the code?
32. How do exceptions affect the program if it doesn't handle them?
33. Is it mandatory for a catch block to be followed after a try block?
34. Can you call a constructor of a class inside another constructor?
35. Contiguous memory locations are usually used for storing actual values in an array but not in ArrayList. Explain.
36. What happens if there are multiple main methods inside one class in Java?
37. Can we make the main() thread a daemon thread?
38. What happens if the static modifier is not included in the main method signature in Java?
39. Which among String or String Buffer should be preferred when there are a lot of updates required to be done in the data?
40. What are the differences between constructor and method of a class in Java?
41. What are Composition and Aggregation? State the difference.
42. Although inheritance is a popular OOPs concept, it is less advantageous than composition. Explain.
43. How does the size of ArrayList grow dynamically? And also state how it is implemented internally?
44. How many overloaded add() and addAll() methods are available in the List interface? Describe the need and uses.
The List interface contains two overloaded versions of the add() method:
The first add() method accepts a single argument of type E, the element to be added to the list.
The second add() method accepts a variable number of arguments of type E, which are the elements to be added to the list.
The List interface also contains two overloaded versions of the addAll() method:
The first addAll() method accepts a single argument of type Collection, which is the collection of elements to be added to the list.
The second addAll() method accepts a variable number of arguments of type E, which are the elements to be added to the list.