Tiantian said to use System.out.println for output, so I have a small question to ask, is out a variable or an internal class? Large and systematic knowledge is explained in detail in various topics. We cannot ignore these scattered knowledge points, otherwise it will be very embarrassing if we are asked such a simple question during the interview and cannot answer it.
Non-instantiable System class
System is a system class. In the java.lang package of JDK, it can be seen that it is also a core language of java. characteristic. The constructor of the System class is decorated with private and is not allowed to be instantiated. Therefore, the methods in the class are also static modified static methods.
Field
public final static InputStream in;
//标准输入流
public final static PrintStream out;
//标准输出流
public final static PrintStream err;
//标准错误流
Copy after login
It can be seen that out and in in System are not internal classes, but genuine field variables. out is the variable field modified by PrintStream's final static, which means it can call methods of the PrintStream class. Println is an output method of PrintStream, so we usually use System.out.println() to output content on the console.
The arraycopy method has five parameters, which are the array to be copied, the starting position to be copied, the array to copy to, the starting position of the array to copy, and the copy to the end of this array. This method is similar to copyOf and copyOfRange in Arrays. It has more parameters and can be used if necessary.
currentTimeMillis——Return the number of milliseconds
I won’t give an example here, the currentTimeMillis method and the getTime method in the Date class It's exactly the same, if you just need milliseconds, such a call is also very convenient. However, it should be noted that currentTimeMillis does not directly get the result of getTime. currentTimeMillis is a local method that returns the time of the operating system. Since the minimum accuracy of the time of some operating systems is 10 milliseconds, this method may cause some deviations. .
/* register the natives via the static initializer.
*
* VM will invoke the initializeSystemClass method to complete
* the initialization for this class separated from clinit.
* Note that to use properties set by the VM, see the constraints
* described in the initializeSystemClass method.
*/
private static native void registerNatives();
static {
registerNatives();
}
Copy after login
native不用看了,本机方法。这是可以猜得到的,因为System类要使用输入和输出流可能会用到和操作系统相关的一些本机方法。那么在static块中调用了registerNatives()方法,这个方法是本地方法我们看不到具体实现。但是注释说了:“VM will invoke the initializeSystemClass method to complete the initialization for this class separated from clinit”。
那么JVM调用的initializeSystemClass方法是怎么实现的呢?
private static void initializeSystemClass() {
props = new Properties();
initProperties(props);
sun.misc.VM.saveAndRemoveProperties(props);
lineSeparator = props.getProperty("line.separator");
sun.misc.Version.init();
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
setIn0(new BufferedInputStream(fdIn));
setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
loadLibrary("zip");
Terminator.setup();
sun.misc.VM.initializeOSEnvironment();
Thread current = Thread.currentThread();
current.getThreadGroup().add(current);
setJavaLangAccess();
sun.misc.VM.booted();
}
The above is the detailed content of In-depth analysis of java-System system class. For more information, please follow other related articles on the PHP Chinese website!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Java document interpretation: Usage analysis of the currentTimeMillis() method of the System class, specific code examples are required. In Java programming, the System class is a very important class, which encapsulates some properties and operations related to the system. Among them, the currentTimeMillis method is a very commonly used method in the System class. This article will explain the method in detail and provide code examples. 1. Overview of currentTimeMillis method
The win10 system is a very easy-to-use and highly intelligent system. Its strong compatibility can ensure that the system will basically not have any problems during normal use. However, as people continue to use the win10 system, sometimes the system will also have problems. The problem of Win10 booting blue screen termination code SystemServiceException. Today I will bring you the solution to Win10 booting Blue Screen termination code SystemServiceException. If you need it, please download it quickly. Solution to win10systemserviceexception blue screen: Method 1: 1. Use Windows key + R to open Run and enter “contr
The computer system is a relatively common system process. You will often see system when viewing the process. This process simply means the computer system; however, if the system.exe process appears on the computer, it needs to be deleted in time. , this is a file generated by a Trojan horse virus. There is no exe suffix behind the real system.
Object is the base class of all Java classes, the top of the entire class inheritance structure, and the most abstract class. Everyone uses toString(), equals(), hashCode(), wait(), notify(), getClass() and other methods every day. Maybe they don’t realize that they are methods of Object, and they don’t look at what other methods Object has. And think about why these methods should be placed in Object. 1. Introduction to JavaObject class - the super class of all classes Object is a special class in the Java class library and is also the parent class of all classes. In other words, Java allows any type of object to be assigned to the Object type
I believe that netizens are very familiar with the Windows 7 system. Have you heard of the Windows 7 English version system? I believe that many netizens have heard about the Windows 7 English version system. However, some friends are looking for the Windows 7 English version system to download. Today I will The editor is going to share the introduction of the original version of win7 in English with everyone, so that netizens can understand the original version of win7 in English. The following is to tell you where to download the English version of Windows 7 system. The original English system of win7 has been released to MSDN for subscription download. The official English integrated version was first released, Windows7WithSP1, which is the Windows7 CD image with integrated SP1. Includes SP1 standalone for multiple languages
Microsoft has announced the availability of System Center 2022. The latest version brings System Center Operations Manager (SCOM), Virtual Machine Manager (VMM), System Center Orchestrator (SCORCH), Service Manager (SM) and Data Protection Manager
Step back in time to the Macintosh of the 1990s and run complete virtual installations of System 7 and MacOS 8 in a browser window. One flaw with new virtual versions of 1990s Mac software is that they run at the speed of a 2020s Mac. You're looking at a MacSE/30 or Quadra700, but everything is as fast as Apple Silicon. You can actually work in these simulated operating systems, and they can even drag documents or files in and out of macOS Monterey. But whether for some practical purposes or more likely just for pure fun, here's how
1. Introduction to System as a system class. In the java.lang package of JDK, it can be seen that it is also a core language feature of Java. The constructor of the System class is decorated with private and is not allowed to be instantiated. Therefore, the methods in the class are also static methods modified by static. The Arrays class in JAVA is a tool class that implements array operations. It includes a variety of static methods that can implement array sorting and search, array comparison, adding elements to arrays, array copying, and converting arrays into String functions. These methods have overloaded methods for all basic types. 2. Detailed explanation of knowledge points 1. The concept is relatively simple introduced in the System class in the API. We give the definition.