Java interview questions and Answers
Java is a computing platform as well as a programming language. You can download it for free. An object-oriented language, Java is a fast, secure and easily extendible language. Java is said to be more dynamic than C or C++ language because of its adaptable design. Unlike many other programming languages, Java is a platform-independent and Architecture-neutral language. Our massive collection of java interview questions will definitely help you find a great job.
Most Frequently Asked Java interview questions
Similar to class, an interface in Java is a reference type. An interface contains abstract methods, constants, static methods, default methods and nested types.
A class implements an interface and inherits the abstract methods of the same interface. Writing an interface is like writing a class.
It is a class that is declared with an abstract keyword. An abstract class can have both abstract and non-abstract methods and needs to be extended. In this class, the method must be implemented and cannot be instantiated.
Hashmap | Hashtable | |
---|---|---|
1. | Nonsynchronized | Synchronized |
2. | Not thread safe | Thread-safe |
3. | Cannot be shared between threads without synchronization code | Can be shared with many threads |
4. | Allows null key and multiple null values | Does not allow null key or value |
HashSet | TreeSet | |
---|---|---|
1. | Offers constant time cost | Offers log time cost |
2. | Does not maintain the order of elements | By default sorts elements in ascending order. |
3. | Implemented using a hash table | Implemented using Binary Search Tree |
A Collection in Java is a group of individual objects that are represented as a single unit. The Collection Framework in Java defines classes and interfaces that represent a group of objects as a single unit.
The two main root interfaces are Collection interface and Map interface.
By being platform independent, we mean that the java source code can be run on all OS. The presence of a machine independent code called Byte Code, which once compiled, can be run on any platform, makes Java platform independent.
The compiler feature in Java converts or translates the high-level language into a common format understood by all the machines. The only requirement is the availability of JVM.
Heap space | Stack Memory | |
---|---|---|
1. | Used to allocate memory | Used for execution of the thread |
2. | Instance variables are created | Local variables are created |
3. | Contains Objects and reference variables | Contains methods and local variables |
Interface | Abstract class | |
---|---|---|
1. | Can only have abstract methods | Can have abstract, non-abstract methods |
2. | Variables are by default final. | May contain non-final variables. |
3. | Only has static and final variables | Can have non-final, final, non-static and static variables |
This is a Java programming class that runs on Java-enabled server or application server and extends the capabilities of servers that host applications.
A servlet possesses all the features of Java such as platform independence, portability, security and database connectivity.
JIT compiler is a component of JRE that improves the performance of applications.
JIT compiler improve the performance of JVM by compiling bytecode into machine code at runtime. Choosing the right compiler is one of the first and biggest decisions to be made when you are running a Java application.
Development History of Java Programming Language
Sun Microsystems released its first version in 1995 as a core component of its platform. Majority of candidates are asked this information in advanced java interview questions.
Latest Version: The latest version is Java SE 11 (18.9 LTS), which was released in September 2018. This information is critical if you are preparing for Java interview questions.
Advantages of Java
- Simple and easy to learn
- Robust and multithreaded
- Enables high performance
- Follows WORA (write once, run anywhere) approach