

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the importance of Runtime class in Java?
The java.lang.Runtime class is a subclass of Object class, can provide access to various information about the environment in which a program is running. The Java run-time environment creates a single instance of this class that is associated with a program. The Runtime class does not have any public constructors, so a program cannot create its own instances of the class. A program must call the getRuntime() method to get a reference to the current Runtime object. The important methods of Runtime class are addShutdownHook(), exec(), exit(), freeMemory(), gc(), halt() and load().
Syntax
public class Runtime extends Object
Example
public class RuntimeTest { static class Message extends Thread { public void run() { System.out.println(" Exit"); } } public static void main(String[] args) { try { Runtime.getRuntime().addShutdownHook(new Message()); System.out.println(" Program Started..."); System.out.println(" Wait for 5 seconds..."); Thread.sleep(5000); System.out.println(" Program Ended..."); } catch(Exception e) { e.printStackTrace(); } } }
Output
Program Started... Wait for 5 seconds... Program Ended... Exit
- Related Questions & Answers
- What is the purpose of Runtime class in Java?
- What is the importance of Boolean class in Java?
- What is the importance of SwingUtilities class in Java?
- What is the importance of JViewport class in Java?
- What is the importance of JSeparator class in Java?
- What is the importance of the GridBagConstraints class in Java?
- What is the importance of the CardLayout class in Java?
- What is the importance of the Container class in Java?
- What is the importance of a Cursor class in Java?
- What is the importance of a SwingWorker class in Java?
- What is the importance of the Throwable class and its methods in Java?
- What is the importance of OverlayLayout in Java?
- Importance of StringReader class in Java?
- What is the Java Runtime Environment (JRE)?
- What is the importance of a StringWriter in Java?
Advertisements