Java interview questions and answers for college students

Java interview questions and answers for final-year college students. Below we will discuss some important Java questions and answers with examples that will help college students to get clear the Java Interview.

Important Topics for Java Interview

  • Java is widely used in Desktop applications, web applications, mobile development, games, etc. so make sure you have a basic understanding what are the end-to-end uses of java.
  • Java is platform-independent and strongly secured programming language so we can develop enterprises application like banking applications.
  • Java is an object-oriented programming language. It follows all the oops concepts like Object, Class, polymorphism, Inheritance, Encapsulation, Abstraction, etc.
  • String Operation and all the classes and methods related to string.
  • Java Collection Interface and Collections classes.
  • Java Exceptions
  • Java is very simple to code easy syntax based on c++ and supports automatic garbage collection.

Billions of applications in the current market are running on Java technology. Java has its own benefits nowadays in mobile application development also using java programming example android application development.

From 1995 to the current date. sun team and now the Oracle team continues to launch their JDK versions or we can say java versions. and in every update, they provide an easy and strong way to program with java and update the feature. That is the reason for its high demand.

Java interview questions and answers

What is java in simple and in one line?

Java is a secured high-level object-oriented programming language.

When and Who developed java?

In 1995, developed by James Gosling.

Where do we use java or the scope of Java?

  • Web Applications.
  • Mobile Application.
  • Enterprise Application.
  • Robotics.
  • Gaming.

What are JDK and JRE in java?

Java development kit(JDK) is used to develop a java program that contains JRE and development tools.

JRE is a java runtime environment, It provides a run time environment for your java code It helps to run your java code.

What is Java virtual machine(JVM)?

JVM stands for Java Virtual Machine. It is a virtual machine. It provides a runtime environment for byte code to be executed.

The .class file(that contains the byte code) generated by Java Compiler is given to JVM as input. Then it’s JVM’s responsibility to load and execute the class file.

What is a Java Compiler?

The Java Compiler is a computer program for compiling Java programs. Here, the program that we write is called source code. Then this source code is input to Java Compiler i.e javac.exe. It will convert the .java file to the .class file which contains the byte code.

Example: to compile a Java file with command prompt: 

  • First, check, if is javac present
C:\Windows\system32>javac
  • Now, compile the Java code as shown below
C:\Windows\system32>javac hello.java

What is heap memory in Java?

As we know, JVM has a dedicated Run time data area. In that, we have a Heap Area where all the instance of the Java class and the array is allocated. There is one Heap Area per JVM.

Is Java platform-independent?

Yes, Java is platform-independent. By platform-independent we mean we can write a Java program on one platform and can run it on any other platform.

As we know, when we write a Java program it goes through the following stages:

  • First, the Java source code is written as a .java file.
  • Then this .java file is input to Java Compiler i.e javac.exe.
  • Now, it’s the compiler that converts the .java file to a .class file which is byte code.
  • This byte code is not the machine code so it is understandable by the OS. Now, due to this byte code, we say that Java is Platform Independent.
  • Now, to execute the byte code, we will need JVM. Now, its JVM responsibility is to convert the byte code to machine-specific code.

Note: Java is platform Independent. But JVM is not. We have different Java Virtual Machines for each platform.

What is IDE in java?

IDE stands for Integrated Development Environment. It is an application where we write Java Programs, compile it, execute it, and debug it.

We can use any IDE from the following:

  • Eclipse IDE
  • Spring STS
  • IntelliJ IDEA
  • NetBeans, etc.

What is J2ee in java?

J2EE stands for Java 2 Platform, Enterprise Edition. The J2EE is provided by the Sun Microsoft System and provides us the functionality of developing a multi-tier enterprise application. It consists of a set of services, APIs, and protocols.

For Example J2EE support pure HTML, Applets, EJB Server, and JDBC APIs.

What is J2se in java?

J2SE stands for Java 2 Platform, Standard Edition. It is our Core Java. It is the basic and standard version of Java. It consists of all the core concepts such as variables, primitive data types, and Arrays. Also, it is used for creating Desktop applications.

Can we develop a scalable enterprise application in Java?

Yes, because Scalability is one of the features of the Java programming language. It has lots of tools, frameworks, and libraries that can handle thousands of requests at once.

What is a JIT compiler?

JIT compiler stands for Just in time compiler. JIT compiler compiles byte code into executable code . JIT is a part of JVM. JIT cannot convert complete java programs into executable code it converts as and when it is needed during execution.

What is bytecode in java?

When a javac compiler compiles a class it generates a .class file. This .class file contains a set of instructions called byte code. Byte code is a machine-independent language and contains a set of instructions that are to be executed only by JVM. JVM can understand these byte codes.

What is a class?

Classes are the fundamental or basic units in Object Oriented Programming. A class is a kind of blueprint or template for objects. Class defines variables, and methods. A class tells what type of objects we are creating. For example, taking a Department class tells us we can create department-type objects. We can create any number of department objects.

All programming constructs in java reside in class. When JVM starts running it first looks for the class when we compile. Every Java application must have at least one class and one main method. Class starts with the class keyword. A class definition must be saved in a class file that has the same class name. The file name must end with .java extension.

public class FirstClass
{public static void main(String[] args)
{System.out.println(“My First Java class”);
}
}

If we see the above class when we compile JVM loads the FirstClass and generates a .class file(FirstClass.class). When we run the program we are running the class and then executing the main method.

What is an object?

An Object is an instance of the class. A class defines the type of object. Each object belongs to some class. Every object contains a state and behavior. The state is determined by the value of attributes and behavior is called the method. Objects are also called an instance. To instantiate the class we declare the class type.

public classFirstClass {public static voidmain(String[] args)
{
FirstClass f=new FirstClass();
}
}

To instantiate the FirstClass we use this statement
FirstClass obj=new FirstClass();
obj is used to refer to the FirstClass object. “obj” is just an object name it can be anything.

What is a method in java?

It contains the executable body that can be applied to the specific object of the class. The method includes the method name, parameters or arguments, and return type, and a body of executable code.

Syntax: type methodName(Argument List){ }

Example: public long add(int a, int b, int c)

Methods can have multiple arguments. Separate with commas when we have multiple arguments.

Core Java Interview Questions and Answers