SoFunction
Updated on 2025-03-08

The function and instructions for use of Java

Function and use of ()

Recently, when I was looking at some code, I used(),(), etc. in many places.

System can have streams of standard input, standard output, error output; access to externally defined properties and environment variables; methods to load files and libraries; and also practical methods to quickly copy part of an array () to determine the current system attributes, and the return value is a Properties;

  • (String filename)Equivalent to: ().load(String filename) Their function is to load code files with specified file names from the local file system as dynamic libraries.
  • (Properties propes)Set system properties to Properties parameter;
  • (String key,String value)Equivalent to ().setProperties(String key,String value): Set the system properties indicated by the specified key
static void **setProperties**(Properties props) Sets the system properties to the Properties parameter.
static String **setProperty**(String key, String value) Sets the system properties indicated by the specified key.
static Properties **getProperties**() Determines the current system properties.
static String **getProperty**(String key) Gets the system properties indicated by the specified key.
static String **getProperty**(String key, String def) Gets the system properties described with the specified key.

setProperties

public static void setProperties(Properties props)

Set system properties toProperties

First, if there is a security manager, it will be called directly without parameters.checkPropertiesAccessmethod. This can lead to a security exception.

The parameters aregetProperty(String)A collection of current system properties used by the method. If the parameter isnull, the collection of current system attributes is ignored.

parameter:- New system properties.SecurityException``checkPropertiesAccessSee also:

public static Properties getProperties()

Determine the current system properties.

First, if there is a security manager, it will be called directly without parameters.checkPropertiesAccessmethod. This can lead to a security exception.

WillgetProperty(String)The current system attribute set used by the method isPropertiesObject returns. If there is no current system attribute collection, a system attribute collection is created and initialized first.

This system attribute set always contains the following key values:

Description of key-related values

Java Runtime Environment Version
Java Runtime Environment Vendor
Java vendor's URL
Java installation directory
Java Virtual Machine Specification Version
Java Virtual Machine Specification Vendor
Java Virtual Machine Specification Name
Java virtual machine implementation version
Java Virtual Machine Implementation Vendor
Java virtual machine implementation name
Java Runtime Environment Specification Version
Java Runtime Environment Specification Vendor
Java Runtime Environment Specification Name
Java class format version number
Java classpath
List of paths to search when loading the library
Default temporary file path
The name of the JIT compiler to be used
Paths to one or more extension directories
The name of the operating system
The architecture of the operating system
Operating system version
File delimiter ("/" in UNIX systems)
Path separator (":" in UNIX systems)
Line delimiter ("/n" in UNIX systems)
User's account name
User's home directory
The user's current working directory

Multiple paths in system attribute values ​​are separated by platform path separators.

Note that even if the security manager does not allow executiongetPropertiesIt may also choose to allow executiongetProperty(String)operate.

**return:**Throw:- If the Security Manager exists and its method does not allow access to system properties.setProperties()()Properties

Java code

public class TestSystemGetSet {  
    static{  
        ("DB", "mysql");// Can be used as a global variable anywhere    }  
    public static void main(String[] args) {  
        ((""));  
        ((""));  
        (("DB"));  
    }  
}  

Output result:

10.0
C:\Java\jdk1.8.0_121\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Java/jre8/bin/server;C:/Java/jre8/bin;C:/Java/jre8/lib/amd64;C:\Program Files\IBM\WebSphere MQ\java\lib;C:\Program Files\IBM\WebSphere MQ\java\lib64;E:\app\Administrator\product\11.2.0\dbhome_2\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\MySQL\MySQL Server 5.1\bin;D:/maven\bin;C:\Program Files (x86)\Rational\common;C:\Program Files\IBM\WebSphere MQ\bin64;C:\Program Files\IBM\WebSphere MQ\bin;C:\Program Files\IBM\WebSphere MQ\tools\c\samples\bin;C:\Java\jdk1.8.0_121\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;D:\maven\bin;E:\soft\apache-ant-1.10.1\bin;D:\erl9.2\bin;;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;E:\tool\eclipse;;.
mysql

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.