List of Java Interview Questions
Here is the list of Java Interview Questions. Answers are also given below so you can answer the Interviewers’ Questions.
- What is Java?
- Explain about Java Virtual Machine?
- What is an Object?
- Define classes in Java
- What is the JIT compiler?
- Explain Typecasting?
- Which Java IDE to use, and why?
- Java is a platform-independent language. Why?
- What are the default values for local variables?
- What gives Java its “write once and run anywhere” nature?
- Why Java is not 100% Object-oriented?
- What is a Map in Java?
- What is the Platform?
- What are the main differences between Java Platforms and Other Platforms?
- What is classloader?
Java Interview Questions and Answers
What is Java?
Answer: Java is an object-oriented, high-level, general-purpose programming language that was originally designed by James Gosling and further developed by the Oracle Corporation. It is one of the most popular programming languages in the world.
Explain about Java Virtual Machine?
Answer: JVM is a program that interprets the intermediate Java byte code and generates the desired output. It is because of byte code and JVM that programs written in Java are highly portable.
Take a Look at this post: A Complete Guide To Become A Perfect Full-Stack Web Developer.
What is an Object?
Answer: 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.
Define classes in Java?
Answer: 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.
What is the JIT compiler?
Answer: JIT compiler runs after the program is executed and compiles the code into a faster form, hosting 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.
Answer: The concept of assigning a variable of one data type to a variable of another data type. It is not possible for the boolean data type.
It is of two types:
Which Java IDE to use, and why?
Answer: A Java IDE is software that allows Java developers to easily write as well as debug Java programs. It is 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.
Java is a platform-independent language. Why?
Answer: Java programming language 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 Java needs a runtime environment, i.e., JRE, which is a set of tools used for developing Java applications.
What are the default values for local variables?
Answer: The local variables are not initialized to any default value, neither primitives nor object references.
What gives Java its “write once and run anywhere” nature?
Answer: The bytecode. Java compiler converts the Java programs into the class file (Byte Code) which is the intermediate language between source code and machine code. This bytecode is not platform-specific and can be executed on any computer.
Why Java is not 100% Object-oriented?
Answer: Java is not 100% Object-oriented because it makes use of eight primitive data types such as boolean, byte, char, int, float, double, long, short which are not objects.
What is a Map in Java?
Answer: In Java, Map is an interface of Util package which maps unique keys to values. The Map interface is not a subset of the main Collection interface and thus it behaves a little different from the other collection types.
What is the Platform?
A Platform is a hardware or software environment in which a piece of software is executed. There are two types of platforms, Software-based and Hardware-based. Java provides the Software-based Platform.
What are the main differences between Java Platforms and Other Platforms?
There are the following differences between the Java platform and other platforms.
- Java is the Software-based platform whereas other platforms may be Hardware-based or Software-based Platforms
- Java is executed on top of other hardware platforms whereas other platforms can only have the hardware components.
What is a classloader?
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded first by the classloader. There are three built-in classloaders in Java.
- Bootstrap ClassLoader: This is the first classloader which is the superclass of the Extension classloader. It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java.util package classes, java.io package classes, java.sql package classes, etc.
- Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System classloader. It loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
- System/Application ClassLoader: This is the child classloader of the Extension classloader. It loads the class files from the classpath. By default, the classpath is set to the current directory. You can change the classpath using the “-cp” or “-classpath” switch. It is also known as the Application classloader.