简体   繁体   中英

What does "runtime" mean in Java?

a JVM implementation is an interpreter that converts a bytecode to machine code. But in the meantime a JVM implementation throws runtime error. Does it mean that an interpreter checks runtime error in Java? Or does it mean that Java's runtime occurs during the stage from bypecode to machine code?

It means that during run time of the application (when app was actually running) some exception was thrown eg attempt to divide by 0 which happen to be an user input.

After research, I've found that a classical compiler converts source code to machine code, ready for computer to execute it, while a classical interpreter directly execute source code.

In C, the compiler converts its source code to almost machine code (an object file). When we "run" a C program, it means the machine execute the object file. So the runtime error is thrown by the machine.

While in Java, the compiler converts its source code to bytecode, an intermediate code between source code and machine code. After compilation, an non-classical interpreter (an bytecode interpreter) directly executes this bytecode. So the runtime error is thrown by this kind of interpreter, which is called "virtual machine" in Java, as it acts like the machine in C which execute the program.

Return to the question I asked, the interpreter (JVM) in Java throws runtime error because it acts like machine itself rather than acting as an intermediate stage before the actual execution.

Here is a resource which explains types of errors in Java, including the Runtime Error. @Antoniossss has a brief explanation if you like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM