Basic Java Interview Question
Q1) Is the Java platform independent?
Yes. Java is a platform-independent language. We can write java code on one platform and run it
on another platform. For e.g. we can write and compile the code on windows and can run the
generated bytecode on Linux or any other supported platform. This is one of the main features of
java.
Q2) What all memory areas are allocated by JVM?
Classloader, Class area, Heap, Stack, Program Counter Register, and Native Method Stack
Q3) Java vs. C ++?
Here are the few differences between Java and C++:
Platform dependency – C++ is platform dependent while java is platform-independent
No goto support – Java doesn’t support the goto statement while C++ does.
Multiple inheritances – C++ supports multiple inheritances while java does not.
Multithreading – C++ does not have in-build thread support, on the other hand, java supports
multithreading
Virtual keyword – C++ has the virtual keyword, it determines if a member function of a class
can be overridden in its child class. In Java, there is no concept of the virtual keyword.
Q4) Explain public static void main(String args[])
Here the public is an access modifier, which means that this method is accessible by any class.
,Static – static keyword tells that this method can be accessed without creating the instance of the
class. Refer: Static keyword in java
Void – this main method returns no value.
Main – It is the name of the method.
String args[] – The args is an array of String types. This contains the command-line arguments
that we can pass while running the program.
Q5) What is Javac?
The javac is a compiler that compiles the source code of your program and generates bytecode.
In simple words, javac produces the java byte code from the source code written *.java file. JVM
executes the bytecode to run the program.
Q6) What is the class?
A class is a blueprint or template or prototype from which you can create the object of that class.
A class has a set of properties and methods that are common to its objects.
Q7) What is the base class of all classes?
Java.lang.Object is the base class (superclass) of all classes in java.
Q8) What is a wrapper class in Java?
A wrapper class converts the primitive data type such as int, byte, char, boolean, etc. to the
objects of their respective classes such as Integer, Byte, Character, Boolean, etc.
, Q9) What is a path and classPath in Java?
Path specifies the location of .exe files. Classpath specifies the location of bytecode (.class files).
Q10) Different Data types in Java.
Byte – 8 bit
Short – 16 bit
Char – 16 bit Unicode
Int – 32 bit (whole number)
Float – 32 bit (real number)
Long – 64 bit (Single precision)
Double – 64 bit (double precision)
Q11) What is Unicode?
Java uses Unicode to represent the characters. Unicode defines a fully international character set
that can represent all of the characters found in human languages.
Q12) What are Literals?
Any constant value that is assigned to a variable is called literal in Java. For example –
// Here 101 is a literal
Int num = 101
Q13) Dynamic Initialization?
Q1) Is the Java platform independent?
Yes. Java is a platform-independent language. We can write java code on one platform and run it
on another platform. For e.g. we can write and compile the code on windows and can run the
generated bytecode on Linux or any other supported platform. This is one of the main features of
java.
Q2) What all memory areas are allocated by JVM?
Classloader, Class area, Heap, Stack, Program Counter Register, and Native Method Stack
Q3) Java vs. C ++?
Here are the few differences between Java and C++:
Platform dependency – C++ is platform dependent while java is platform-independent
No goto support – Java doesn’t support the goto statement while C++ does.
Multiple inheritances – C++ supports multiple inheritances while java does not.
Multithreading – C++ does not have in-build thread support, on the other hand, java supports
multithreading
Virtual keyword – C++ has the virtual keyword, it determines if a member function of a class
can be overridden in its child class. In Java, there is no concept of the virtual keyword.
Q4) Explain public static void main(String args[])
Here the public is an access modifier, which means that this method is accessible by any class.
,Static – static keyword tells that this method can be accessed without creating the instance of the
class. Refer: Static keyword in java
Void – this main method returns no value.
Main – It is the name of the method.
String args[] – The args is an array of String types. This contains the command-line arguments
that we can pass while running the program.
Q5) What is Javac?
The javac is a compiler that compiles the source code of your program and generates bytecode.
In simple words, javac produces the java byte code from the source code written *.java file. JVM
executes the bytecode to run the program.
Q6) What is the class?
A class is a blueprint or template or prototype from which you can create the object of that class.
A class has a set of properties and methods that are common to its objects.
Q7) What is the base class of all classes?
Java.lang.Object is the base class (superclass) of all classes in java.
Q8) What is a wrapper class in Java?
A wrapper class converts the primitive data type such as int, byte, char, boolean, etc. to the
objects of their respective classes such as Integer, Byte, Character, Boolean, etc.
, Q9) What is a path and classPath in Java?
Path specifies the location of .exe files. Classpath specifies the location of bytecode (.class files).
Q10) Different Data types in Java.
Byte – 8 bit
Short – 16 bit
Char – 16 bit Unicode
Int – 32 bit (whole number)
Float – 32 bit (real number)
Long – 64 bit (Single precision)
Double – 64 bit (double precision)
Q11) What is Unicode?
Java uses Unicode to represent the characters. Unicode defines a fully international character set
that can represent all of the characters found in human languages.
Q12) What are Literals?
Any constant value that is assigned to a variable is called literal in Java. For example –
// Here 101 is a literal
Int num = 101
Q13) Dynamic Initialization?