Java Interview Questions for Freshers – Set 1

If you are planning to learn Core Java or any interview is scheduled in the coming days. As core java plays an important role in any Java interview, Java interview questions for freshers help you to prepare for Java-based interviews. In any Java-based interview, core Java is the favourite area for most interviewers and always considered to be the deciding factor of the interview.

In this article, we are trying to provide some of the important core java interview questions for freshers with answers which are to the point.

1. What are the key differences between C++ and Java?

Answer: C++ and Java both are object-oriented programming languages with some differences. The interviewer may ask the difference between the two and include this in the top Java interview questions for freshers to check your basic knowledge. The differences between C++ and Java are as follows –

1) C++ is platform dependent.1) Java is platform-independent.
2) C++  writes structural programs without using classes and objects.2) Java is a pure object-oriented language except for the primitive variables.
3) C++ doesn’t support documentation comments.3) Java supports documentation comment (/**…*/) to create documentation for java code.
4) C++ fully supports pointers.4) In Java, there is no concept of pointers.
5) C++ supports multiple inheritance.5) Java doesn’t support multiple inheritance.

2.  Explain the JVM architecture?

Answer: Java Virtual Machine is the abstract machine or specification that provides a runtime environment to execute the bytecode. JVM supports Java and many other languages known as JVM languages, the program written in these languages is compiled into the bytecode and then executed by the JVM. contains key components which are classloader, memory area, execution engine etc.

a) Classloader

It is a subsystem of JVM which load class files. Whenever a Java program is run, it is loaded by the classloader.

b) Class Area

Class Area holds class-level data of each class file such as metadata, constant run pool, and static variables.

c) Heap

It is the runtime data which is used for allocating objects.

d) Stack

The stack is used for storing temporary variable. This component has a stack frame which is allocated one frame to each thread and when the execution of the thread is completed then that frame is also gets destroyed.

e) Registers

This component contains the address of JVM instruction which currently being executed.

f) Native Method Stack

All the native method stack used in the application are stored in this.

g) Execution Engine

It contains:

  • A virtual processor
  • An interpreter that executes the instructions after reading the bytecode.
  • JIT compiler, used for improving the performance due to the slow execution. It compiles the similar part of the bytecode at the same time which reduces the total time needed for compilation.

h) Java Native Interface

It provides an interface which is needed for communicating with another application developed in another language like C, C++, C# etc.

For Regular off campus Job updates: Click here

3. What is the use of Classloader in Java?

Answer: A Java program is made up of a different number of custom classes and pre-defined classes. When a program is executed, JVM is used to load all the content of that needed class and through the use of Classloader JVM, it finds that class.

There are three types of Classloaders:

  • System Class Loader

It loads all the classes from the classpath.

  • Extension ClassLoader

It loads all the classes from the extension directory.

  • Bootstrap Class Loader

It loads all the pre-defined java classes.

4. Which class is a superclass of all classes?

Answer: Java.lang.The object is the root class for all the java classes and we don’t need to extend it. Every other java classes fall back under the object. All the different non-primitive types including arrays are inherited directly or indirectly from this class.

5. What is the static keyword?

Answer: The static keyword is used with a class level variable to make it global so all the objects will be able to share the same variable. It can also be used with methods. A static method can access only static variables of the class and invoke only a static method of the class.

The interview generally asks this question in the Java interview questions for freshers. Even if you are a fresher, you should have a good knowledge of the keywords in Java.

6. What are finally and finalize in Java?

Answer: Finally block is used with a try-catch block to put the code that you always want to get executed even the execution is thrown by the try-catch block.  Finally is just used for releasing the resources which were created by the try block.

Finalize() is a special method in Object class that we can override in our classes. Finalize() is called by the Garbage collector to collect the garbage value when the object is getting it. This method is generally overridden to release the system resources when garbage value is collected from the object.

Get Free Job Alerts via WhatsApp: Click Here

7. What is Type casting in Java?

Answer: Casting in Java is one of the top topics from where you can get questions in your interview. When we assign a value of one data type to a different data type then these two data types might not be compatible with each other and needs conversion. If data types are compatible with each other like, in case of the conversion of int value to long then automatic conversion is done by Java and doesn’t require typecasting. But if data types are not compatible with each other then they need to be cast for conversion.


dataType variablename = (dataType) variableToConvert;

8. What is the inner and anonymous inner class?

Answer: In Java, we can define a class inside a class and they are called nested classes. Any nested class which is non-static are known as inner class. Inner classes are associated with objects of the class and they can access all the variables and methods of the outer class.

Any local inner class without any name is known as an anonymous inner class. It is defined and instantiated in a single statement. Anonymous inner class always extend a class or implement an interface. Since an anonymous inner class doesn’t have any name, it is not possible to create its constructor.

9. What is break and continue statement?

Answer: In a while or do-while loop, we use break for a statement to terminate the loop. We use a break statement in a switch statement to exit the switch case. We can also use break statement for terminating the nested loop.

The continue statement is used for skipping the current iteration of a for, while or do-while loop. We can use the break statement with a label to skip the current iteration of the outermost loop.

The most basic programming question, not only related to the Java. If you have some knowledge of programming languages, you should know the answer to this question as it is among frequently asked Java interview questions for freshers.

10. What is an interface?

Answer: Interfaces are the core part of Java programming language used a lot in JDK, java design patterns, and most of the frameworks and tools. The interface provides a way to achieve abstraction in Java and used to define the contract for the subclasses to implement.

The interface is a good starting point to define the type and create a top-level hierarchy in your code. In Java, a class can implement multiple interfaces, it’s better to use interfaces as a superclass in most of the cases.

Get Free Job Alerts via WhatsApp: Click Here

For Regular off campus Job updates: Click here




Leave a Reply

Your email address will not be published. Required fields are marked *