• Post Reply Bookmark Topic Watch Topic
  • New Topic

Time line of the code from IDE "run" to machine cod executed by CPU  RSS feed

 
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m studying inheritance and polymorphism at the moment , probably one of the hardest thing i found in java as of yet . I only started learning programming recently but i found an issue i don't understand and i bump into it allot .I didn't find this issue explained broadly in the books i used .Basically i don't really understand how the java code is actually run , i know that is compiled(transformed into machine code?!) and interpreted(transformed into a pre-machine code that the JVM can interpret on every different machine without the need to recompile it ?!) but i don't understand the process that well , for example what exactly is runtime ? When it's compile time ? when the code is compiled and when it get's at runtime ? I m interested to understand the time line of the code from the point i "run" it in the IDE until it goes to the CPU in the form of machine code to be executed ...
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget about an IDE. They run the code differently from a JVM on the command line/terminal.
The compiler checks the code for syntax and also other errors signalled by generics or the @Override annotation. The compiler produces a .class file for each class (including inner classes) in bytecode.
The bytecode is loaded and interpreted by the JVM. The exact order in which things are executed is in the Java Language Specification. It is by no means easy to read.
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First think about it without an IDE. What happens in a nutshell:
1) You type code
2) You run the javac command - This is compile time. The output of this command is .class files is bytecode. This is special code that can be run by the java command. It's kind of like machine code. But instead of being for a specific machine, it is for the "java virtual machine."
3) You run the java command - This is run time. It runs the class files. The Java virtual machines knows how to map the bytecode to machine code for whatever specific machine you are on. This is why there is a different Java install for Windows, Mac, etc. Because the mapping to machine code part is different.

In the IDE, it is a little more complicated. IDEs try to do a limited compile as you type so they can tell you about errors.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This page from Oracle's Java Tutorials explains it: About the Java Technology
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!