Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Runtime classes and documentation comments

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use Runtime classes and documentation comments", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use Runtime classes and documentation comments" bar!

First, Runtime class 1. What is the Runtime class?

The Runtime class describes some information about the virtual machine JVM, which is the process used to encapsulate the virtual machine JVM. Every Java application has an instance of the Runtime class, so it has only one instance and no more. The Runtime class uses the singleton pattern, which is that in designing a class, there is only one instance object in the whole program.

two。 How to get a Runtime instance? Runtime r=Runtime.getRuntime (); example of 3.Rumtime instance object getting some information about virtual machine public class p57 {public static void main (String [] args) {/ / TODO Auto-generated method stub Runtime r=Runtime.getRuntime (); / / get System.out.println ("availableProcessors:" + r.availableProcessors () + "a") / processor System.out.println ("freeMemory:" + r.freeMemory () / (1024 / 1024) + "M"); / / Free memory space System.out.println ("maxMemory:" + r.maxMemory () / (1024 / 1024) + "M"); / / maximum available memory space System.out.println ("totalMemory:" + r.totalMemory () / (1024 / 1024) + "M"); / / available memory space}

The result of the operation is:

In the above code, use the "Runtime.getRuntime ()" method to get a Runtime instance object, call the availableProcessors () method, freeMemory () method, maxMemory () method, totalMemory () method to represent the number of processors, free memory space, maximum available memory space, available memory space, and print the current virtual information on the console. The results of the above run may be different because everyone's configuration is different.

Second, the function of the exec () method 1.exec () method of the run class is to run a dos command, which is the same as opening a command window and entering a dos command.

For example:

Typing calc.exe in the command window will open the calculator that comes with the Windows system. The effect image is as follows:

Open the calculator code that comes with the windows system with the exec () method as follows:

Import java.io.IOException; public class p58 {public static void main (String [] args) throws IOException {/ / TODO Auto-generated method stub Runtime r=Runtime.getRuntime (); / / get r.exec ("calc.exe"); / / Open Calculator}}

The result of the operation is:

The exec () method of the 2.Runtime class returns a new Process () object to manage the child processes. If you need to shut down the process, call the destory () method. The implementation closes the example public class p59 {public static void main (String [] args) throws IOException {/ / TODO Auto-generated method stub Runtime r=Runtime.getRuntime () after opening notepad using the exec () method; / / gets the Process p=r.exec ("notepad.exe"); / / opens the calculator try {Thread.sleep (5000) that comes with the windows system } catch (InterruptedException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} / the program hibernates for 5 seconds p.destroy (); / / shuts down this process}}

The result of the run is the effect of automatically shutting down after 5 seconds.

III. Notes on Java documents

There are three ways to annotate in 1.java programs. One is a documentation comment, which begins with / * and ends with /. The role of documentation comments is simply to help understand the code, standardize the source code, and reduce the later maintenance workload.

The javadoc command is provided in 2.java, and its function is to extract these information and automatically generate documents in HTML format, thus realizing the documentation of java programs. Programmers can learn about the functions of the program by looking at the help documentation, without having to look at the source code to improve development efficiency.

3. The role of the @ tag in a document comment is as follows:

Author: a description of the class, which is the author of the program

@ version: a description of the class, which is the version number of the developer

@ param: a description of a method, indicating the parameters of a method

@ return: a description of the method, indicating the return type of the method

Thank you for your reading, these are the contents of "how to use Runtime classes and documentation comments". After the study of this article, I believe you have a deeper understanding of how to use Runtime classes and documentation comments, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report