In this Article, we have covered Top 12 Java Interview Questions And Answers for Fresher candidates.
This post on JAVA Interview Questions is prepared to help you understand the basic concepts of Java programming for interview purposes. All the important JAVA concepts are explained here.
As per my experience, interviewers hardly planned to ask any particular question during your interview, normally in a technical interview, questions start with some basic concept of the subject and later they continue based on further discussion and what you answer so always be ready to tackle any type of question-based on the subject.
Q1. What do you understand by Java?
Ans: Java is a programming computer language. Java is designed by Mr. James Gosling in the year of 1991. It follows the OOPs concept (object-oriented programing language). In Java, everything is an object except the primitive java type. It follows automatic memory management, it automatically allocates memory to a newly created object and automatically realizes the memory when an object is not in use or object is destroyed.
Q2. what are the difference between Java and C++?
Java is platform-independent.
C++ is platform-dependent.
Java doesn’t support multiple inheritances through the class. Although we can achieve multiple inheritances with the help of interface in java
C++ supports multiple inheritances.
Java doesn’t support operator overloading.
|C++ supports operator overloading|
|Java has restricted the pointer support. You cannot write a program with the pointer in java. Although internally it uses a pointer.|
C++ supports pointers. You can write a program with the pointer in C++.
|Java supports call by value only.|
C++ supports both calls by value and call by reference.
|Java doesn’t support structures and unions.|
C++ supports structures and unions.
|Java has built-in thread support.|
C++ doesn’t have built-in support for threads.
|Java is an object-oriented language. However, everything (except fundamental types) is an object in Java.|
C++ is also an object-oriented language. However, in C language, a single root hierarchy is not possible.
Q3. What are the features of the Java programming language?
Ans: There are the following features in Java Programming Language.
- Simple: Java is easy to learn. The syntax of Java is easier alike C++ to write the program in it.
- Object-Oriented: Java follows the object-oriented programming, which allows us to maintain our code as the combination of different type of objects.
- Portable: Java supports read-once-write-anywhere approach. You can run the Java program on every machine.
- Platform Independent: Java is a platform independent programming language. It is different from other programming languages like C and C++ As C and C++ require a platform to be executed. Java has its own platform on which its code is executed.
- Secured: Java programming language is secured because it doesn’t use explicit pointers. It also provides the concept of ByteCode and Exception handling which makes it more secure than other languages.
- Robust: Java is a strong programming language as it uses strong memory management. It follows automatic memory management, it automatically allocates memory to a newly created object and automatically realizes the memory when an object is not in use or object is destroyed. make it more robust.
- Architecture Neutral: Java is architectural neutral as it is not dependent on the architecture. As the size of the data types of java does vary with respect to the architecture (32 or 64 bit).
- Interpreted: Java language uses the Just-in-time (JIT) interpreter and also the compiler for the program execution.
- High Performance: Java is much faster than other programming languages because Java bytecode is “close” to native code. Although java is a little slower than c++ language.
- Multithreaded: Java programs can deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn’t occupy memory for each thread. It shares a common memory area.
- Distributed: Java language is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are used for creating distributed applications. This feature of Java makes us able to access files by calling the methods from any machine on the internet.
- Dynamic: Java language is a dynamic language. It supports dynamic loading of classes. It means classes are loaded when they are needed or on demand. It also supports functions from its native languages, i.e., C and C++.
Q4. what is compiler in java and what it does?
Ans: Compiler in Java is a program with a name of javac .exe. It is mainly responsible for two things
1) checking the syntax of a language.
2) If there is no mistake in code then it generate the .class file.
Q5. What do you understand by JVM?
Ans: JVM stands for java virtual machine which provides the platform-independent execution environment. It is a virtual machine that enables the computer to run the Java program.JVM is responsible for compiling the java code and convert it to the Bytecode.
Q6. What is JDK?
Ans: JDK stands for the Java development kit. It comes in different version according to the SUN or Oracle release.
These are the following Java version:-
- JDK 1.2 (Playground)
- JDK 1.4 (Merline)
- JDK 1.5 (Tiger)
- JDK 1.6 (Mustang)
- JDK 1.7 (Dolphins)
- JDK 1.8 (Spider)
- JDK 1.9 (Jigsaw)
JDK provides different tools and library in order to compile and run or in order to develop the java application. JDK is platform dependent which will be different for the different platforms.
Q7. What is JRE?
Ans: Java runtime environment provide all the library and all other resources in order to run the java program.
Q8 What is Interpretation?
Ans: It is also a program with a name of java.exe, which is responsible to convert byte code to native code line to line. It is time taking process
Q9. What is JIT Compiler in java?
Ans: Stands for ‘JUST IN TIME’ compiler which reads byte code at a time and convert to the native code at a time. It is the faster process in comparison to the Interpretation.
Internally, this uses the V-Table concept to store the information about byte code and native code. Under that V-Table, it maintains two information one for byte code and the second one is for the native code.
Q10. What do you understand by platform?
Ans: A platform is an environment where software is executed. The platform is of two type Hardware and Software-based platform.Java provides us the software-based platform.
Q11. Why Java is platform-independent?
Ans: When we are writing any java based program, that must be saved with the dot java (.java) extension. After successfully compiling that java program it generates a .class file or byte code. When we are trying to run the program that byte code will get converted to native code, that native code will internally communicate with windows operating system.
There is no physical extension of native code in java. As byte code is platform independent we can use this byte code on any other platform, only JDK(java developer kit) must be available on that machine. So, Java is called as platform-independent.
Q12 State whether following is either True or false!
- Java program is platform independent?
- C program are platform independent?
- C program are platform dependent?
- JDK is platform dependent?
- Byte code is platform independent?
- The native code or .exe is platform independent?
This article, will help you with the java top basic interview question and answer for the freshers. Read the article carefully, I believe this article is going to help a lot to the fresher to tackle the question fired by the interviewer. Stay tuned! for the more interview question. Happy Learning! All the best!
Recommended interview questions:
- Important Interview Questions on OOPS
- Important Interview Question On Java Classes
- Core Java Interview Questions on Constructors
- Top 30+ Important Interview Questions On Inheritance