Class System
For simple stand-alone Java applications, a typical way to write a line of output data is:
See the println methods in class PrintStream .
Typically this stream corresponds to display output or another output destination specified by the host environment or user. By convention, this output stream is used to display error messages or other information that should come to the immediate attention of a user even if the principal output stream, the value of the variable out , has been redirected to a file or other destination that is typically not continuously monitored. The encoding used in the conversion from characters to bytes is equivalent to Console.charset() if the Console exists, stderr.encoding otherwise.
Method Details
setIn
setOut
setErr
console
inheritedChannel
In addition to the network-oriented channels described in inheritedChannel , this method may return other kinds of channels in the future.
setSecurityManager
Otherwise, the argument is established as the current security manager. If the argument is null and no security manager has been established, then no action is taken and the method simply returns.
getSecurityManager
currentTimeMillis
See the description of the class Date for a discussion of slight discrepancies that may arise between «computer time» and coordinated universal time (UTC).
nanoTime
This method provides nanosecond precision, but not necessarily nanosecond resolution (that is, how frequently the value changes) — no guarantees are made except that the resolution is at least as good as that of currentTimeMillis() .
Differences in successive calls that span greater than approximately 292 years (2 63 nanoseconds) will not correctly compute elapsed time due to numerical overflow.
The values returned by this method become meaningful only when the difference between two such values, obtained within the same instance of a Java virtual machine, is computed.
For example, to measure how long some code takes to execute:
To compare elapsed time against a timeout, use instead of because of the possibility of numerical overflow.
arraycopy
If the src and dest arguments refer to the same array object, then the copying is performed as if the components at positions srcPos through srcPos+length-1 were first copied to a temporary array with length components and then the contents of the temporary array were copied into positions destPos through destPos+length-1 of the destination array.
If dest is null , then a NullPointerException is thrown.
If src is null , then a NullPointerException is thrown and the destination array is not modified.
- The src argument refers to an object that is not an array.
- The dest argument refers to an object that is not an array.
- The src argument and dest argument refer to arrays whose component types are different primitive types.
- The src argument refers to an array with a primitive component type and the dest argument refers to an array with a reference component type.
- The src argument refers to an array with a reference component type and the dest argument refers to an array with a primitive component type.
- The srcPos argument is negative.
- The destPos argument is negative.
- The length argument is negative.
- srcPos+length is greater than src.length , the length of the source array.
- destPos+length is greater than dest.length , the length of the destination array.
Otherwise, if any actual component of the source array from position srcPos through srcPos+length-1 cannot be converted to the component type of the destination array by assignment conversion, an ArrayStoreException is thrown. In this case, let k be the smallest nonnegative integer less than length such that src[srcPos+ k ] cannot be converted to the component type of the destination array; when the exception is thrown, source array components from positions srcPos through srcPos+ k -1 will already have been copied to destination array positions destPos through destPos+ k -1 and no other positions of the destination array will have been modified. (Because of the restrictions already itemized, this paragraph effectively applies only to the situation where both arrays have component types that are reference types.)
identityHashCode
getProperties
The current set of system properties for use by the getProperty(String) method is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties includes a value for each of the following keys unless the description of the associated value indicates that the value is optional.
| Key | Description of Associated Value |
|---|---|
| java.version | Java Runtime Environment version, which may be interpreted as a Runtime.Version |
| java.version.date | Java Runtime Environment version date, in ISO-8601 YYYY-MM-DD format, which may be interpreted as a LocalDate |
| java.vendor | Java Runtime Environment vendor |
| java.vendor.url | Java vendor URL |
| java.vendor.version | Java vendor version (optional) |
| java.home | Java installation directory |
| java.vm.specification.version | Java Virtual Machine specification version, whose value is the feature element of the runtime version |
| java.vm.specification.vendor | Java Virtual Machine specification vendor |
| java.vm.specification.name | Java Virtual Machine specification name |
| java.vm.version | Java Virtual Machine implementation version which may be interpreted as a Runtime.Version |
| java.vm.vendor | Java Virtual Machine implementation vendor |
| java.vm.name | Java Virtual Machine implementation name |
| java.specification.version | Java Runtime Environment specification version, whose value is the feature element of the runtime version |
| java.specification.maintenance.version | Java Runtime Environment specification maintenance version, may be interpreted as a positive integer (optional, see below) |
| java.specification.vendor | Java Runtime Environment specification vendor |
| java.specification.name | Java Runtime Environment specification name |
| java.class.version | Java class format version number |
| java.class.path | Java class path (refer to ClassLoader.getSystemClassLoader() for details) |
| java.library.path | List of paths to search when loading libraries |
| java.io.tmpdir | Default temp file path |
| java.compiler | Name of JIT compiler to use |
| os.name | Operating system name |
| os.arch | Operating system architecture |
| os.version | Operating system version |
| file.separator | File separator («/» on UNIX) |
| path.separator | Path separator («:» on UNIX) |
| line.separator | Line separator («\n» on UNIX) |
| user.name | User’s account name |
| user.home | User’s home directory |
| user.dir | User’s current working directory |
| native.encoding | Character encoding name derived from the host environment and/or the user’s settings. Setting this system property has no effect. |
| stdout.encoding | Character encoding name for System.out . The Java runtime can be started with the system property set to UTF-8 , starting it with the property set to another value leads to undefined behavior. |
| stderr.encoding | Character encoding name for System.err . The Java runtime can be started with the system property set to UTF-8 , starting it with the property set to another value leads to undefined behavior. |
The java.specification.maintenance.version property is defined if the specification implemented by this runtime at the time of its construction had undergone a maintenance release. When defined, its value identifies that maintenance release. To indicate the first maintenance release this property will have the value «1» , to indicate the second maintenance release this property will have the value «2» , and so on.
Multiple paths in a system property value are separated by the path separator character of the platform.
Note that even if the security manager does not permit the getProperties operation, it may choose to permit the getProperty(String) operation.
lineSeparator
On UNIX systems, it returns «\n» ; on Microsoft Windows systems it returns «\r\n» .
System.arraycopy
![]()
We can also copy elements of an array to another array by using the arraycopy() method of the System class.
The signature of the arraycopy() method is as follows:
- sourceArray is the source array.
- sourceStartPosition is the starting index in the source array from where the copying of elements will start.
- destinationArray is the destination array.
- destinationStartPosition is the start index in the destination array from where new elements from source array will be copied.
- lengthToBeCopied is the number of elements to be copied.
We can replace the previous for loop with the following code:
The following code shows how to use System.arraycopy to copy an array.
The code above generates the following result.
Array Clone
We can make a copy of array using array’s clone() method. For primitive types, the cloned array will have a true copy of the original array.
However, for reference types, the reference of the object stored in each element is copied to the cloned array.
This is known as a shallow copy. In a shallow copy, elements of both arrays, the original and the cloned, refer to the same object in memory.
The following code illustrates the cloning of an int array and a String array.
Как скопировать массив в Java
Java предоставляет встроенный метод System.arraycopy() для копирования элементов из одного массива в другой. Следующий пример использует System.arraycopy() для копирования последних пяти элементов одного массива в другой массив.
1. Создание исходного массива
Вот код для исходного массива:
2. Создание массива-назначения
Массив назначения будет длиной в пять элементов. Он также должен быть массивом типа int. Вот код для массива назначения:
3. Копирование элементов массива
Метод System.arraycopy() принимает несколько параметров.
- Первым параметром является массив-источник.
- Вторым параметром является позиция начала нового массива.
- Третий параметр — массив-назначения.
- Четвертый параметр является начальным положением целевого массива.
Последний параметр это количество элементов, которые будут скопированы. Вот код, чтобы скопировать последние пять элементов исходного массива в конечный массив (массив-назначения):
System arraycopy java как работает

java.lang.System class provides useful methods for standard input and output, for loading files and libraries or to access externally defined properties. The java.lang.System.arraycopy() method copies a source array from a specific beginning position to the destination array from the mentioned position. No. of arguments to be copied are decided by an argument. The components at source_Position to source_Position + length – 1 are copied to destination array from destination_Position to destination_Position + length – 1 Class Declaration
Syntax :