How the JVM accesses the file system

I have an argument with my boss who is convinced that the JVM uses JNI to access native things such as the file system. I think he is mistaken, because the JVM itself is native code and it is directly connected to the OS - you do not need a JNI template to access the file system.

Please help me clarify how the JVM works.

+3
source share
2 answers

This is really a moot point. Java kernel interfaces is a language function that allows you to define a function call in Java that will be passed to code that is not java, in particular, which is native to the platform. If you look at FileOutputStream.java in the src.zip of your SDK, you will see this code:

    /**
 * Opens a file, with the specified name, for writing.
 * @param name name of file to be opened
 */
private native void open(String name) throws FileNotFoundException;

/**
 * Opens a file, with the specified name, for appending.
 * @param name name of file to be opened
 */
private native void openAppend(String name) throws FileNotFoundException;

/**
 * Writes the specified byte to this file output stream. Implements 
 * the <code>write</code> method of <code>OutputStream</code>.
 *
 * @param      b   the byte to be written.
 * @exception  IOException  if an I/O error occurs.
 */
public native void write(int b) throws IOException;

So, I would say if the question is whether the class library uses the same notation to access external library calls at the system level. I think the answer is yes.

, Java, - Java , , , . , ( "" API-), , , .

+4

JNI Java . , JVM IS Native code, , . JVM. JVM Windows Windows, Linux Linux, OSX OSX .. , , JVM.

+2

Source: https://habr.com/ru/post/1731081/


All Articles