DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. Potential Java Garbage Collection Interview Questions

Potential Java Garbage Collection Interview Questions

What kind of interview questions can you expect about how Java uses memory?

Ram Lakshmanan user avatar by
Ram Lakshmanan
CORE ·
Apr. 01, 16 · Opinion
Like (15)
Save
Tweet
Share
24.30K Views

Join the DZone community and get the full member experience.

Join For Free

jvm-heap

Fig: Java Heap sizes generated from http://gceasy.io

What are the Different Regions in JVM Memory?

There are 5 regions:

  1. Eden
  2. Survivor 1
  3. Survivor 2
  4. Old (or Tenured) Generation
  5. Perm Generation (until Java 7). Since Java 8, Perm Generation has been replaced with Metaspace.

Note: Eden, Survivor 1 and Survivor 2 are collectively called the Young Generation.

Can You Explain the Purpose of Each Region in Java Memory?

Eden Generation: When an object is newly constructed it’s created in the Young Generation. In most of the applications, most of the objects are short-lived objects. i.e. they will die soon. Thus they will be collected as garbage within the Young Generation itself.

Survivor: Objects that survive Minor GC are not directly promoted to the Old Generation. They are kept in the Survivor region for a certain number of Minor GC collections. Only if they survive certain number of Minor GC collections can they be promoted to the Old Generation.

Old (or Tenured) Generation: Certain objects tend to be long-lived. Example: Application Context, HTTP Sessions, Caches, Connection Pools, etc. Those long-lived objects are promoted to old generation.

Perm Generation: This is the location where JVM objects such as Classes, Methods, String Interns, etc. are created.

Metaspace: Starting with Java 8, the perm generation has been replaced with Metaspace for performance reasons.

What are the Different Types of GC?

There are 3 types of garbage collection:

  1. Minor GC
  2. Major GC
  3. Full GC

Minor GC: It’s also called as Scavenge GC. This is the GC which collects garbage from the Young Generation.

Major GC: This GC collects garbage from the Old Generation

Full GC: This GC collects garbage from all regions i.e. Young, Old, Perm, Metaspace.

When Major or Full GC run all application threads are paused. It’s called a stop-the-world event. In Minor GCs, stop-the-world events occurs, but only momentarily.

What are the Different Types of GC Algorithms?

  1. Serial
  2. Parallel
  3. CMS
  4. G1

Serial: The serial collector uses a single thread to perform all garbage collection work. It is best-suited to single processor machines, because it cannot take advantage of multiprocessor hardware. It’s enabled with the option -XX:+UseSerialGC.

Parallel: The parallel collector (also known as the throughput collector) performs minor collections in parallel, which can significantly reduce garbage collection overhead. It is intended for applications with medium-sized to large-sized data sets that are run on multiprocessors or multithreaded hardware. It’s enabled with the option -XX:+UseParallelGC.

CMS: The mostly concurrent collector performs most of its work concurrently (for example, while the application is still running) to keep garbage collection pauses short. It is designed for applications with medium-sized to large-sized data sets in which response time is more important than overall throughput because the techniques used to minimize pauses can reduce application performance. It’s enabled with the option -XX:+UseConcMarkSweepGC.

G1: G1 is the latest garbage collector, targeted for multi-processor machines with large memories. It meets garbage collection (GC) pause time goals with high probability, while achieving high throughput. Whole-heap operations, such as global marking, are performed concurrently with the application threads. It’s enabled with the option -XX:+UseG1GC.

What are the Pros and Cons of Each GC Algorithm?

To see the Pros and Cons of each algorithm, refer to http://blog.tier1app.com/2015/04/19/which-gc-to-use/

What Tools are Used for Analyzing Garbage Collection Logs?

  1. http://gceasy.io
  2. IBM Pattern Modeling and Analysis Tool for Java Garbage Collector
  3. Oracle’s Visual GC, Java Mission Control

For more such interview questions please visit : http://gceasy.io

garbage collection Garbage (computer science) Java (programming language) application Interview (journalism)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Multi-Cloud Database Deep Dive
  • The Top 3 Challenges Facing Engineering Leaders Today—And How to Overcome Them
  • How to Rescue Your Magento 2 Project
  • Hackerman [Comic]

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: