Basic Java Programs Asked in Interview with Answers Pdf - 1

Question: 1

What is heap and stack?

The heap is the part of memory of JVM where all objects reside.

The stack is consisted of stack frames. When a thread invokes a method, the JVM pushes a new frame onto that thread’s Java stack.

Each stack frame is consisted of operand stack and the local variable array.

All arguments local variables, intermediate computations and return values if any are kept in the stack corresponding to the method.

The stack frame on the top of the stack is called the active stack frame, which is current place of execution.

When the method completes, the virtual machine pops and discards the frame for that method.

Question: 2

What is a java package and how is it used?

A Java package is a naming context for classes and interfaces.

A package is used to create a separate name space for groups of classes and interfaces.

Packages are also used to organize related classes and interfaces into a single.

API unit and to control accessibility to these classes and interfaces.

Question: 3

What are the types of data types in java?

  • byte
  • short
  • int
  • float
  • long
  • double
  • char and
  • boolean

Question: 4

What is an object?

Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data.

When an object is created using new operator, memory is allocated to it.

Question: 5

What are object and class classes used for?

The Objects class is the highest level class in the Java class hierarchy.

The Java Class class is used to represent the classes and interfaces that are located by a Java program.

Related Questions