Basic Java Interview Questions
Basic Java Interview Questions
It stands for
It stands for
Java
Java Runtime It stands for Java Virtual Machine.
Development
Environment.
Kit.
It is the tool JRE refers to a
necessary to runtime It is an abstract machine. It is a
compile, environment in specification that provides a run-time
document and which Java environment in which Java bytecode can
package Java bytecode can be be executed.
programs. executed.
It’s an
It contains JRE
implementation JVM follows three notations:
+
of the JVM which Specification, Implementation, and Ru
development
physically ntime Instance.
tools.
exists.
Q2. Explain public static void main(String args[]) in Java.
main() in Java is the entry point for any Java program. It is always written
as public static void main(String[] args).
Java is called platform independent because of its byte codes which can run
on any system irrespective of its underlying operating system.
Wrapper classes convert the Java primitives into the reference types
(objects). Every primitive data type has a class dedicated to it. These are
known as wrapper classes because they “wrap” the primitive data type into
an object of that class. Refer to the below image which displays different
primitive type, wrapper class and constructor argument.
Q7. What is singleton class in Java and how can we make a class
singleton?
Singleton class is a class whose only one instance can be created at any
given time, in one JVM. A class can be made singleton by making its
constructor private.
Q 8.What is JIT compiler?
Q10 What if I write static public void instead of public static void?
The program compiles and runs correctly because the order of specifiers
doesn't matter in Java.
The local variables are not initialized to any default value, neither primitives
nor object references.
In Java, access specifiers are the keywords which are used to define the
access scope of the method, class, or a variable. In Java, there are four
access specifiers given below.
Public :The classes, methods, or variables which are defined as public, can
be accessed by any class or method.
Default : Default are accessible within the package only. By default, all the
classes, methods, and variables are of default scope.
The Object is the real-time entity having some state and behavior. In Java,
Object is an instance of the class having the instance variables as the state
of the object and the methods as the behavior of the object. The object of a
class can be created by using the new keyword.
The constructor can be defined as the special type of method that is used to
initialize the state of an object. It is invoked when the class is instantiated,
and the memory is allocated for the object. Every time, an object is created
using the new keyword, the default constructor of the class is called. The
name of the constructor must be similar to the class name. The constructor
must not have an explicit return type.