PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Runtime class

← All stacks

Theory

123/270

Runtime class

Garbage collection frees heap objects that nothing points to anymore. You don’t call free() like C++. The JVM decides when to collect.

You can hint with System.gc() but you cannot force it. Unreachable objects become eligible. Memory leaks still happen if you keep unwanted references (static lists, caches).

Don’t say “Java has no memory problems”. GC helps, it does not make leaks impossible.

Let's take this on the board with one tiny Main class — no extra files. Output: Asha scored 72 then Pass. Real Main. Swap marks/name to show one idea from Runtime class. Start from main, go line by line, and stop at each print. That output is the proof for Runtime class.

Exam tip

Explain Runtime class as: definition → why → one code idea.

Example

// Runtime
public class Main {
  public static void main(String[] args) {
    int marks = 72;
    String name = "Asha";
    System.out.println(name + " scored " + marks);
    if (marks >= 40) System.out.println("Pass");
  }
}

Output: Asha scored 72 then Pass. Real Main. Swap marks/name to show one idea from Runtime class.

Short notes

  • DefGC frees heap objects that nothing points to.
  • RuleYou don’t free() yourself. JVM decides when.
  • RememberSystem.gc() is only a hint, not a force.
  • TrapKeeping unwanted references → leak even with GC.

Questions

1

What is Runtime class?

2

Why do we use Runtime class in Java?

3

Write one small example of Runtime class.

4

What mistake do beginners make with Runtime class?

5

Where is Runtime class used in a real program?

Previous← Garbage Collection in JavaNextSynchronization in Java →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.