Top Advanced Java Interview Questions and Answers

    11 Votes

11) What is meant by JVM ?

JVM(Java Virtual Machine) is a run time environment for the compiled java class files. Main function of JVM is to convert byte code(.class file) to machine code and send appropriate commands to underlying machine for execution.

12) What is the difference between interpreter and compiler in Java ?
CompilerInterpreter:
Compiler translates source code to JVM byte code. Executes the byte code by running the program.
Compiling happens when programmers invoke compiler after the program is writtem. Interpretation happens at run time
For compilation, use command "javac Employee.java". Compilation of java file will generate class file (ex: Employee.class). Command java Employee, executes the class file (i.e Employee.class)


13)  Can abstract class implements another interface ?

Yes. It's just a special case of implementation by which subclasses are forced to implement the methods.


14) Can abstract class extend another abstract class?

Yes. It is perfectly valid for an abstract class to extend another abstract class.

15) Can a interface extend another interface?

Yes. An interface can extend another interface in Java.

16) What Is Stack?

  • Each Java thread have a private JVM stack, created along with thread.
  • Stack stores frames. Frames are used for storing data (Variable and Object Data as well as partial results) and to perform operations such as
    • Dynamic linking
    • Dispatch exceptions when error occurs
    • Return values when methods are invoked. Since the stack can't be accessed directly, it push and pop frames.
  • It is not mandatory that the Java virtual machine stack had to be continuous.
  • JVM throws StackOverflowError, if any computation inside a thread needs larger JVM stack than allocated .


17) What Is Heap?

  • When JVM starts, heap is created
  • Heap is the runtime data area of the JVM
  • It is shared by all the threads inside the JVM
  • It allocates memory for all class instances and arrays
  • Heap storage for objects is reclaimed by garbage collector when it is not used.
  • JVM throws OutOfMemoryError, If a computation needs more heap than what can be supplied by the automatic storage management system.


18) Can you explain about Upcasting and Downcasting in Java ?

  • Upcasting : Casting a Sub class to Super class. Upcasting is called as widening.
  • Downcasting : Casting a Super class to Sub class. Downcasting is called as narrowing.


19) Can you explain about Implicit and Explicit type casting ?


Implicit casting (widening conversion)
:

When JVM encounters a data type of lower size which occupies less memory, it is assigned to a data type of higher size implicitly by the JVM. This is also known as automatic type conversion. For Example

int i = 1; // 4 bytes
double d = i; // 8 bytes


Explicit casting:


When a data type of higher size which occupies more memory, needs to be assigned to a data type of lower size, it is called explicit casting. This type of casting won't be done implicitly by the JVM. This casting operation should be performed by the programmer. For example 

double d = 1.0; 
int i = (int) d;


20) Can you explain about markable interface in Java ?

Interfaces with no methods are known as Marker interface. Some of the markable interfaces are

 java.lang.Cloneable
java.io.Serializable
java.util.EventListener
Page 2 of 6

Popular Videos

communication

How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

Java OOPS Interview Questions and Answers
Java Interview Questions
Java Collections Interview Questions and Answers
Java Thread Interview Questions and Answers