Top 7 Core Java Interview Questions and Answers (2022)
Updated: Jun 30, 2022
1) What is Java?
Java is the high-level, object-oriented, robust, secure, platform-independent, high performance, Multithreaded, and portable programming language.
It was released by Sun Microsystems in 1995.
2) Java Interpreter:
Java interpreter is a computer program (system software) that implements the JVM. It is responsible for reading and executing the program.
It is designed in such a way that it can read the source program and translate the source code instruction by instruction. It converts the high-level program into assembly language (machine language).
3) Interpreter and Compiler Difference:
It translates the code instruction by instruction.
Its execution is slower.
Its compile time is less.
It compiles the program until an error is found
It translates the entire program at once.
Its execution is faster.
It takes more time to compile the code.
All the errors show once at the end of the compilation.
4) Why is Java a platform independent language?
Java language was developed in such a way that it does not depend on any hardware or software due to the fact that the compiler compiles the code and then converts it to platform-independent byte code which can be run on multiple systems.
5) Why is Java not a pure object oriented language?
Because, Java supports primitive data types - byte, boolean, char, short, int, float, long, and double and hence it is not a pure object-oriented language.
6) Pointers are used in C/ C++. Why does Java not make use of pointers?
Pointers are quite complicated and unsafe to use by beginner programmers. Java focuses on code simplicity, and the usage of pointers can make it challenging. Pointer utilization can also cause potential errors. Moreover, security is also compromised if pointers are used because the users can directly access memory with the help of pointers.
7) What do you mean by data encapsulation?
Data Encapsulation is an Object-Oriented Programming concept of hiding the data attributes and their behaviours in a single unit.
It helps developers to follow modularity while developing software by ensuring that each object is independent of other objects by having its own methods, attributes, and functionalities.
It is used for the security of the private properties of an object and hence serves the purpose of data hiding.