JAVA common API - Runtime and System

Article directory


foreword

Hello everyone, I love animal milk the most. Today I will bring you the Runtime class and System class in the commonly used JAVA API.

So let's go and have a look!


1. Rubtime

1. What is Rubtime?

2. Runtime common methods

Runtime provides many methods, here are two demonstrations

  1. public static Runtime getRuntime(): Returns the Runtime object of the current runtime environment.

  2. public void exit(int status): Terminate the running of the current Java virtual machine and return a specified status code.

  3. public long freeMemory(): Returns the amount of free memory for the current runtime environment.

  4. public long totalMemory(): Returns the total amount of memory for the current runtime environment.

  5. public void gc(): Request the Java virtual machine to perform garbage collection.

  6. public Process exec(String command) throws IOException: Execute the specified command in a separate process.

  7. public Process exec(String[] cmdarray) throws IOException: Execute the specified command and parameters in a separate process.

  8. public InputStream getLocalizedInputStream(InputStream in): Get the localized input stream.

  9. public OutputStream getLocalizedOutputStream(OutputStream out): Get the localized output stream.

1.getRuntime

Let's take a look at the source code

test

 

Increase knowledge: 

Operating environment:

Runtime Environment refers to the hardware and software environment required to run software on a computer. It includes hardware devices such as operating systems, processors, memory, and network connections, as well as installed software components such as programming languages, library files, frameworks, and databases.

In software development, different programming languages ​​and development frameworks require different operating environments to support their operation. For example, a Java program requires a Java Virtual Machine (JVM) as its operating environment, while a Python program requires a Python interpreter as its operating environment.

The configuration of the operating environment has a great influence on the operating efficiency and stability of the software. Therefore, in software development, it is necessary to select a suitable operating environment according to the specific needs and environment, and perform corresponding configuration and optimization.


 2. exit 

 verify normal exit

2. System

1. What is System?

System is a tool class that provides some system-related methods

  1. currentTimeMillis(): Returns the current time in milliseconds.

  2. nanoTime(): Returns the current time in nanoseconds.

  3. exit(int status): Terminate the currently running Java virtual machine and return a specified status code.

  4. gc(): Runs the garbage collector.

  5. getProperty(String key): Get the value of the specified system property.

  6. getenv(String name): Get the value of the specified environment variable.

  7. arraycopy(Object src, int srcPos, Object dest, int destPos, int length): Copy the specified element in one array to another array.

  8. setIn(InputStream in): Set the standard input stream.

  9. setOut(PrintStream out): Set the standard output stream.

  10. setErr(PrintStream err): Sets the standard error stream.

  11. loadLibrary(String libname): Load the native library with the specified name.

  12. getProperty(String key, String def): Get the value of the specified system property, or return the default value if none.

  13. getProperties(): Get a copy of all system properties.

  14. arraycopy(Object src, int srcPos, Object dest, int destPos, int length): Copy the specified element in one array to another array.

  15. identityHashCode(Object x): Returns the hash code of the specified object.

  16. lineSeparator(): Get the line separator of the current system.

  17. setSecurityManager(SecurityManager s): Sets the security manager.

  18. getSecurityManager(): Get the current security manager.

 2. Common methods

1. currentTimeMillis(): Returns the current time in milliseconds.

 

2. exit(int status): Terminate the currently running Java virtual machine and return a specified status code

 

 3. arraycopy: Copy the specified element in one array to another array.


 Summarize

The above is what I want to talk about today. This article introduces the use of Runtime and System. You can try some of these methods.

 

Guess you like

Origin blog.csdn.net/weixin_73869209/article/details/130687862
Recommended