0% found this document useful (0 votes)
30 views

Java Runtime Class

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
30 views

Java Runtime Class

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
2122122, 11°51 PM |nps:iwwwjavatpoin comijava-runtie-ass Java Runtime class -javatpoint 19 ‘2122, 11:51 PM Java Runtime class -javatpoint Java Runtime class Java Runtime class is used to interact with java runtime environment. Java Runtime class provides methods to execute a process, invoke GC, get total and free memory etc. There is only one instance of java.lang Runtime class is available for one java application. The Runtime.getRuntime() method returns the singleton instance of Runtime class. Important methods of Java Runtime class No. Method Description 1) public static Runtime getRuntimed) returns the instance of Runtime class. 2) public void exit(int status) terminates the current virtual machine. 3) public void addShutdownHook(Thread hook) registers new hook thread. 4) public Process exec(String command)throws executes given command in a separate 1OException process 5) public int availableProcessors) returns no. of available processors. 6) public long freeMemory) returns amount of free memory in JVM. 7) public long totalMemory() returns amount of total memory in JVM. Java Runtime exec() method public class Runtime1( public static void main(String args{))throws Exception( Runtime.getRuntime0.exect“notepad");//will open a new notepad ) ) |nps:iiwwjavatpoin comijava-runtime-ass ‘2122, 11:51 PM Java Runtime class -javatpoint How to shutdown system in Java You can use shutdown -s command to shutdown system. For windows OS, you need to provide full path of shutdown command e.g. «:\\Windows\System32\shutdown. Here you can use -s switch to shutdown system, -r switch to restart system and -t switch to specify time delay. public class Runtime2( public static void main(String args{))throws Exception( Runtime.getRuntime(..exec("shutdown -s -t 0"), } ) How to shutdown windows system in Java public class Runtime2( public static void main(String args{))throws Exception{ Runtime.getRuntime(.exect"c\\Windows\\System32\\shutdown -s -t 0"); ) ) |nps:iiwwjavatpoin comijava-runtime-ass a9 ‘2122, 11:51 PM Java Runtime class -javatpoint How to restart system in Java public class Runtime3{ public static void main(String args{))throws Exception( Runtime.getRuntime0.exect"shutdown -r -t 0"); ) ) Java Runtime availableProcessors() public class Runtimed( public static void main(String args{))throws Exception( System.out printIn(Runtime.getRuntime) availableProcessors(); ) } Java Runtime freeMemory() and totalMemory() method In the given program, after creating 10000 instance, free memory will be less than the previous free memory. But after gc() call, you will get more free memory. public class MemoryTest( public static void main(String args{])throws Exception{ Runtime r=Runtime.getRuntime); System.out printin("Total Memory: "+r.totalMemory()); System.out printin("Free Memory: "+rfreeMemory(); for(int i=0;i<10000;i++ new MemoryTest0); ) System.out printin("“After creating 10000 instance, Free Memory: “+rfreeMemory); System.gc0; |nps:iiwwjavatpoin comijava-runtie-ass 49 s21rain2, 11:51 PM Java Runtime class -javatpoint System.out.printin("After gc), Free Memory: "+r.reeMemory(); d d Total Memory Free Memory: 99474824 After c 88 instance, Free Memory: 99310552 ating 160 After ), Free Memory: 100182832 Youtube For Videos Join Our Youtube Channel: Join Now Feedback © Send your Feedback to feedback@javatpoint.com Help Others, Please Share |nps:iiwwjavatpoin comijava-runtime-ass 2122122, 11°51 PM Learn Latest Tutorials Splunk tutorial Splunk £TumbIr tutorial Tumblr AR Programming tutorial R Programming & Python Pillow tutorial Python Pillow Preparation SPSS tutorial spss # React tutorial ReactlS RAIS tutorial RxJS & Python Turtle ‘tutorial Python Turtle |nps:iwwwjavatpoin comijava-runtie-ass Java Runtime class -javatpoint 2) Swagger tutorial Swagger PRegex tutorial Regex #) React Native tutorial React Native aKeras tutorial Keras “SQL tutorial Transact-SQL [o} Reinforcement learning tutorial Reinforcement Leaming \s} Python Design Patterns Python Design Patterns 2122122, 1°51 PM Aptitude Logical Aptitude Reasoning Reasoning 2 Company Interview Questions Company Questions Trending Technologies 2 Axtificial (PAWS Tutorial Intelligence ‘Aws Artificial Intelligence (2:Hadoop tutorial ReactIS. Hadoop Tutorial ReacuS 2) Blockchain \AGit Tutorial Tutorial Git Blockchain npesiwwjavatpoin.comfava-runtime-lass Java Runtime class -javatpoint (eNerbal Ability Verbal Ability # Seler tutorial Selenium #) Data Science Tutorial Data Science 2 Machine ‘Learning Tutorial Machine Learning Interview Questions Interview Questions 2 Cloud ‘Computing Cloud Computing A Angular 7 Tutorial Angular 7 2 _Devops Tutorial DevOps 79 2122122, 11°51 PM B.Tech / MCA DBMS tutorial DBMS 2 Computer Network tutorial Computer Network Ethical Hacking Ethical Hacking #.Cyber Security tutorial Cyber Security #Java tutorial Java Data Structures tutorial Data Structures Compiler Design tutorial Compiler Design 2 Computer Graphies Tutorial Computer Graphies 2 Automata Tutorial Automata a Net Framework tutorial Net pesiwwjavatpoin.comjava-runtime-ass Java Runtime class -javatpoint DAA tutorial DAA #) Computer Organization and Architecture Computer Organization 2) Software Engineering Software Engineering 2 CLanguage tutorial C Programming #Python tutorial Python i) Operating System Operating System 5 Mathematics Tutorial Discrete Mathematics (Ahtm! tutorial Web Technology A List of Programs 2122122, 1°51 PM 2 Control #. Data Mining ‘Systems tutorial Control System |nps:iiwwjavatpoin comijava-runtime-ass ‘Tutorial Data Mining Java Runtime class -javatpoint Programs 2 Data Warchouse Tutorial Data Warehouse

You might also like