Java interview questions for freshers

JAVA INTERVIEW QUESTIONS : Java is one of the most important programming language for every software engineer. Indore is hub of Major IT Companies like TCS (Tata Consultancy Services), Infosys, DXC (Former CSC: Computer Science Corporation), FIS (Former Worldpay), Impetus Infotech India Pvt Ltd, Yash Technologies, Cleartrail (Impetus subsidiary), Intellicus (Impetus subsidiary), Infobeans, Diaspark etc. All these companies recruit computer science professionals for java.

Let’s start with first JAVA INTERVIEW QUESTIONS

Q #1) What is JAVA?

Ans: Java is  a platform independent  language. We write classes in Java such that data is hidden, ideas are abstracted and code is re-usable….

 There are a lot of applications that are developed using Java e.g..

1)  Desktop Applications such as MediaPlayer,Antivirus etc.

 2) Web Applications such as, etc.

3) Enterprise Application such as Banking applications.

4) Mobile Applications.

5)  Embedded System.

6) SmartCards.

7) Robotics.

8) Games   etc.

Q #2) What are the features in JAVA? Why Java Is Important ?

Ans: Features of Java:

  • Oops concepts
    • Object-oriented : Java application is designed by declaring classes, creating objects from them, and interactions between these objects.

Classes, fields, methods, constructors, and objects are the basic building blocks of object-oriented Java applications.

  • Inheritance : IS-A relationship means “one object is type of another”. Inheritance is capability of inheriting properties(fields and methods) from one class to another.
    • Encapsulation :  encapsulation is a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.

Encapsulation is a process of binding  data and codes that operates on the data into a single entity.

  • Polymorphism :  Polymorphism means “many forms”, and it occurs when we have many classes that are related to each other by inheritance.
    • Abstraction : Abstraction is a methodology of hiding the implementation of internal details and showing the functionality to the users.
  • Platform independent: The java code can run on multiple operating systems. Only to run a java program  on any machine we needs  JVM  to be present in the machine.
  • High Performance: (Just In Time compiler  enables high performance in Java. JIT converts the bytecode into machine language and then JVM starts the execution.
  • Multi-threaded: A thread is a different program that runs pararraly; this feature helps Java to handle multiple tasks simultaneously. The user can create multiple threads by extending the Thread class or by implementing Runnable interface.

Q #3) How does Java enable high performance?

Ans:  Java is a complied and interpreted language.Java enables high performance with the use of just-in-time compiler

Q #4) What are the Java IDE’s?

Ans:Java IDE enables users to more easily write and debug Java programs. IDEs provide features like syntax highlighting and code completion etc. Eclipse and NetBeans are the IDE’s of JAVA.

Q #5) Why java is platform independent?

Other then java, In any  programming language soruce code is compiled in to executable code (machine specific code,which is machine dependent), which is directly executable on a specific machine and operationg system. This cannot be run across all platforms. When a java program compiled by java compiler(javac), generated code  called byte code (.class file) and it is not machine specific code. Byte codes are interpreted only by JVM’s .

Since these JVM’s are made available across all platforms by Sun Microsystems, we can execute this byte code in any platform. This makes java platform independent.

Q #6) How  JIT compiler improves performance of the system?

JIT compiler stands for Just in time compiler.Internally Just In Time compiler maintains a separate count for every method whenever JVM come across any method call.

First then method will be interpreted normally by the interpreter and JIT compiler increments corresponding count variable.This process will be continued for every method.

If any method count reaches threshhold then JIT compiler idetnifies this method as repeatedly used method(hot spot).Immediatly Jit compiler compiles that method and generates corresponding Native code. Next time JVM come across that method call then JVM directly use Native code. So no need to interprete that method again. This imporove the performance.

Q #7) What is JAR?

JAR stands for Java ARchive. It’s a file format based on the popular ZIP file format and is used for aggregating many files into one.

JAR is:

  • the only archive format that is cross-platform
  • the only format that handles audio and image files as well as class files
  • an open standard, fully extendable, and written in java




Q #8) What is JNI?

JNI stands for Java Native Interface.JNI can be used to call functions which are written

in other languages from Java.


• we can use our existing library which was previously written in other language.

• we can call Windows API function.

• we can speed up execution time using JNI concept .

• we can calll API function of some server product which is in c or c++ from java



• we can’t say write once run anywhere.

• Difficult to debug runtime error in native code.

• Potential security risk.

Q #9) What is a compilation unit?

The smallest unit of source code that can be compiled, i.e. a .java file.

Q #10) Why java is not a 100% Object Oriented Programming language?

Because Java uses primitive types such as int, char, double etc. and java doesn’t support Multiple inheritance, Operator Overloading concepts.

Q #11) How .class file load by JVM and what is the process of JVM?


What is meant by class loader ? How many types are there? When will we use them ?

Loading means reading class files and store corresponding binary data in Method area.For each class file JVM will store following information in method area:

1. Fully qualified name of the loaded class or interface or enum

2. Fully qualified name of its immediate parent class.

3. Modifiers, Variables or Fields, method and constructor  etc.. information

After loading .class file immediately JVM will creates an object of type class Class to represent class level binary information.

Every class loader sub system contains following three class loaders:

1.Bootstrap class loader :

responsible to load classes from jdk/jre/lib folder. All core java API classes present rt.jar which is present

in this location only. Hence all API classes (like String, StringBuffer) will be loaded by Bootstrap class loader


2.Extension class loader :

               Responsible to load classes from Extension class path location jdk/jre/lib/ext.

3. Application class loader :

               Responsible to load classes from application class path (current working directory)                

Q #12) Explain how a program internally executes?

1.  Java programs are not compiled into executable files(machine specific code), they are compiled into bytecode( not machine specific code) .

 2. Byte code is converted into machine specific code by  JVM (Java Virtual Machine) and  then this code executes at runtime.

Javc compiler compiles Java source code into bytecode. The bytecode gets saved on the disk with the file extension .class. When the program is to be run, the bytecode is converted, using the just-in-time (JIT) compiler which part of JVM. The result is machine code which is then fed to the memory and is executed.

The Java classes/bytecode are compiled to machine code and loaded into memory by the JVM when needed the first time. This is different from other languages like C/C++ where programs are to be compiled to machine code and linked to create an executable file before it can be executed.



Q #13) What happens when we write Javac source code is converted into byte code by java compiler (javac) and generates Test.class file saved in curresnt directory.

Q #14) If in our program every thing is alright or if the compiler succeeds, what do we know?

  • The program was well formed—a meaningful program in whatever language.
  • It’s possible to start running the program. (The program might fail immediately, but at least we can try.)

Q #15) What are the inputs and outputs?

  • Input was the program being compiled, plus any header files, interfaces, libraries, or other that it needed to import in order to get compiled.
  • Output is hopefully assembly code or relocatable object code or even an executable program. Or if something goes wrong, output is a bunch of error messages(syntax error).

So compiler is not responsible to run the program. That’s why we could not get anything printed at compile time.

Q #16) Explain JDK & JRE & JVM?


  • Java Development Kit is the core component of Java Environment and provides all the tools, executables and binaries required to compile, debug and execute a Java Program.
  •  JDK is a platform specific software and thats why we have separate installers for Windows, Mac and Unix systems.
  • We can say that JDK is superset of JRE since it contains JRE with Java compiler, debugger and core classes. JVM


  • JVM is the heart of java programming language. When we run a program, JVM is responsible to converting Byte code to the machine specific code.
  • JVM is also platform dependent and provides core java functions like memory management, garbage collection, security etc.
  •  JVM is customizable and we can use java options to customize it, for example allocating minimum and maximum memory to JVM.
  •  JVM is called virtual because it provides a interface that does not depend on the underlying operating system and machine hardware.


  • JRE is the implementation of JVM, it provides platform to execute java programs.
  • JRE consists of JVM and java binaries and other classes to execute any program successfully.
  •  JRE doesn’t contain any development tools like java compiler, debugger etc.
  • If you want to execute any java program, you should have JRE installed but we don’t need JDK for running any java program.


Q #17) What is JAVAdoc utility?

Javadoc utility enables you to keep the code and the documentation in sync easily.

The javadoc utility lets you put your comments right next to your code, inside your “.java” source files.

All you need to do after completing your code is to run the Javadoc utility to create your HTML documentation automatically.

Q #18) What is the difference between C++ & Java?

•             Java does not support  Structures and Unions but supports classes.

•             Java does not support multiple inheritance or operator overloading

•             Java allows functions to be overloaded

•             In java, memory leaks are prevented by automatic garbage collection

•             C++ allows direct calls to be made to the native system libraries. On the other hand java calls these libraries trough java native interface.

•             In c++ parameters are passed by either value or pointers. In java, due to the absence of pointers, parameters are passed by value.



Q #19) Is Empty .java file a valid source file?

Yes, an empty .java file is a perfectly valid source file.

Q #20) Can a .java file contain more than one java classes?

Yes, a .java file contain more than one java classes, provided at the most one of them is a public class.

Q #21) Can a public class MyClass be defined in a source file named

No the source file name, if it contains a public class, must be the same as the public class name itself with a .java extension.

Defined in a source file named

No the source file name, if it contains a public class, must be the same as the public class name itself with a .java extension.

Q #22) What is the difference between procedural and object-oriented programs?  

Ans: The difference between procedural and object-oriented programs are

 a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code

b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.

Q #23) What is the use of bin and lib in JDK?

Ans: bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

Q #24) Why we do not get anything printed at compile time?

Copiler is not resposible to satisfy any invariants of java program. In fact, it needn’t be a well-formed program at all.

Q #25) What can go wrong at compile time:

  • Syntax errors
  • Type checking errors
  • (Rarely) compiler crashes

If you like our post JAVA INTERVIEW QUESTIONS please share it with your friends and like our facebook page

Leave a Reply