Java - Interview Questions

Java - Object Oriented ProgrammingJava - Objects & ClassesJava - Data TypesJava - VariablesJava - StringsJava - ArraysJava - CollectionsJava - ReflectionJava - Lambda ExpressionsJava - StreamsJava - GenericsJava - ExceptionsJava - IOJava - ThreadsJava - ConcurrencyJava - JDBCJava - NetworkingJava - SecurityJava - JVM InternalsJava - PerformanceJava - New in Java 8Java - New in Java 9Java - New in Java 10

Top ranked courses to help you master Java skills.
Java Programming Masterclass


Offered By - Tim Buchalka
Platform - Udemy
Rating - * * * * *
Students Enrolled - 575,000 +

Behaviorial Interview
Top resource to prepare for behaviorial and situational interview questions.

STAR Interview Example
Java - Performance - Interview Questions

What are the key areas that impact the performance of Java programs?


A lot of factors can impact the performance of an application developed in Java programming language. At a high level following areas can be optimized to improve Java application performance.


  • JVM Optimizations
  • Garbage Collection Optimizations
  • Memory Optimizations

Java program

  • Program logic optimizations
  • Algorithm and collection usage optimizations
  • Multi-threading and synchronization optimizations.

Connectivity optimizations

  • Network connectivity
  • Database connectivity

What are the benefits and dis-advantages of garbage collector?



  • Garbage collector automatically manages the JVM memory by deleting objects that are no longer referenced and used. A Java developer can concentrate on program logic instead of worrying about object deletion and memory management.
  • The garbage collector has inbuilt efficient algorithms which determine when to run the garbage collector.


  • There is a possibility that during garbage collection process the application performance may be impacted. In certain situations, called 'stop the world', the application process is completely stopped while the garbage collection process takes place.
  • You can indicate to the JVM to run the garbage collector, but it is not guaranteed. So as a developer you do not know when the garbage collection process happens.

What is 'Stop The World'?


During garbage collection process, the JVM may stop all the application process threads from execution. This freezing of application processes is termed as 'Stop The World'

What do you understand by generational structure of Java heap?


Java heap is structured into following sections, also called as generations.

New Generation - All new objects created by a Java program are put into the new generation section of the heap. Garbage collection runs on the new generation and removes all short-lived objects.

New generation section is further split into two sections. Eden space and Survivor space.

  • Eden Space - All new objects are put into eden space. When the eden space fills up, garbage collection runs and removes all objects that have no references. All objects that still have references are promoted to the survivor space.
  • Survivor space - Every garbage collection run in the new generation section, will remove the objects from Survivor space if the objects no longer is referenced. If the object is still referenced, it will increment the age of that object. After the increment reaches a certain number, usually starting at 15 depending on the JVM implementation, the object will be promoted to the old generation section.

Old Generation - Objects that survive the survivor section of the new generation section are promoted to the old generation section. The old generation section is much larger than the new generation. A separate garbage collection process, also called as FullGC, happens in the Old generation section.

PermGen - JVM uses PermGen to store the meta-data about classes.

What are the different garbage collection algorithms? Which algorithm is better?


Following are some of the algorithms available for garbage collection

Serial GC - Designed for single CPU machines. Stops all application processes during garbage collection. Goes through all objects, marks objects for garbage collection, removes them.

Parallel GC - Similar to Serial, except used multiple threads for garbage collection.

Concurrent Mark Sweep - Concurrent Mark Sweep does most of the garbage collection concurrently with the application processes. Hence, the amount of time that all application process are completely stopped are greatly reduced.

G1GC (Garbage first garbage collector) - ...

*** See complete answer in the Java Interview Guide

Java Interview Guide has over 250 REAL questions from REAL interviews. Get the guide for $15.00 only.

What does the finalize() method do?


The finalize() method is called by the garbage collector on an object before it releases the object from memory. The garbage collector releases an object ...

*** See complete answer in the Java Interview Guide

What are the common flags that you can use to optimize the JVM and garbage collector?


Following are some common flags you would set to tune JVM

  • -Xms512m - Sets the initial heap size to 512m
  • -Xmx1024m - Sets the maximum heap size to 1024m

*** See complete answer in the Java Interview Guide

What are memory leaks? How do you diagnose memory leaks?


Memory leaks in a Java program happen when references to objects are not released. This fills up the heap space and ...

*** See complete answer in the Java Interview Guide

Important Keywords to Remember

Garbage Collector
Stop the World
Generational Structure Of Heap
New Generation
Eden Space
Survivor Space
Old Generation
Garbage collection algorithms
Serial GC
Parallel GC
Concurrent Mark Sweep
Java Interview Guide


  SSL Secure Payment
Java Interview Quesiuons - Secure Payment
Java Interview Guide


  SSL Secure Payment
Java Interview Quesiuons - Secure Payment

Earn income using your skills and hobbies that you are passioniate about.

Earn Side Income with Photos
Earn Side Income with Writing

Transition out of you full-time job by creating businesses that you are passioniate about.