jvm如何进入public static void main? [英] how does jvm enter in public static void main?
本文介绍了jvm如何进入public static void main?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jvm如何进入默认类:
How can jvm enter in default class:
class try1
{
public static void main(String args[])
{
...
}
}
其中jvm如何访问此方法?
In it how does jvm access this method?
在包中,如果某个类是默认的,则其公共方法无法从外部访问,那么jvm如何进入这个类?
In packages if a class is default its public methods cant be accessed from outside, so how does jvm enter this class?
推荐答案
调用 main $的不是JVM本身c $ c>方法。这是Java启动器的工作,即
java.exe
。
Java启动程序是一个用C编写的小程序,它使用常规JNI函数:
It is not JVM itself who invokes main
method. This is rather a job of Java launcher, i.e. java.exe
.
Java launcher is a small program written in C that uses regular JNI functions:
-
JNI_CreateJavaVM
创建JVM的新实例并获取JNIEnv的实例
; -
JNIEnv :: FindClass
找到命令行中指定的主类; -
JNIEnv :: GetStaticMethodID
在类#2中找到public static void main(String [])
方法。 -
JNIEnv :: CallStaticVoidMethod
调用#3中的方法。
JNI_CreateJavaVM
to create a new instance of JVM and to obtain an instance ofJNIEnv
;JNIEnv::FindClass
to locate the main class specified in the command line;JNIEnv::GetStaticMethodID
to findpublic static void main(String[])
method in class #2.JNIEnv::CallStaticVoidMethod
to invoke the method found in #3.
事实上,JNI允许您使用所有类,方法和字段,即使使用 private
修饰符。
In fact, JNI allows you to work with all classes, methods and fields, even with private
modifier.
这篇关于jvm如何进入public static void main?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文