• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about jvm  RSS feed

 
Abigail Decan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did my own reasearch on jvm, and i would appreciate it if someone could confirm my answers.

a jvm is is a software that has its own compiler and interpreter.
the compiler translates .java files into .class files (written in bytecode; not sure bytecode is yet) for the interpreter to execute.
a normal program is executed by the computer's CPU. therefore, performance of the program is platform-dependent.
but java programs are executed by the jvm, and not the computer, so java programs performs the same on different computers.
in other words the jvm assures that the program is executed in the same environment across all platforms.
 
Barry Burd
Author
Ranch Hand
Posts: 133
10
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abigail, You have most of it right. The only thing is, a JVM doesn't include a compiler. The compiler is a separate piece of software. The compiler turns a .java file into a .class file. The .class file is a lot like the kind of program that a computer executes. (For example, a Windows computer normally executes a .exe file, which is a collection of instructions that can be carried out directly by the computer's processor.) A .class file is such a set of instructions, but it's not a set of instructions for any particular kind of processor. (The instructions buried inside a .class file look like they might be executed by a particular processor, but they're not meant for any particular processor.) Instead, when you run a JVM on a Windows machine, the JVM is a .exe file that interprets the instructions in your .class file and turns those instructions into instructions that the processor on a Windows computer can execute. Alternatively, when you run a JVM on a Mac, the JVM is a Mac executable that interprets the instructions in your .class file and turns those instructions into instructions that the processor on a Mac can execute.) To sum up, the JVM is a piece of software that you run on your computer, and when you run it, the JVM interprets, instruction by instruction, whatever steps are described in a .class file. The thing that makes a .class file able to be "run" on both Windows and Mac is that there's one JVM program that runs on Windows computers, and a separate JVM program that (does the same interpreting of .class files when it) runs on Mac computers.
I hope this helps.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry Burd wrote:The only thing is, a JVM doesn't include a compiler.

What Abigail may have heard of is the Just In Tiime or JIT compiler. This is different to the Java compiler (javac).
Some (all ?) JVMs include a JIT compiler that can convert some or all of the OS independent class files into OS dependent code in order to improve performance.
This is done whilst the program is running (hence the Just In Time name) and has to be done anew every time the program runs.
Which class files get converted and when will vary from platform to platform and is controlled by the JVM.
 
Abigail Decan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you.
so the conclusion is that jvm is a translator from .class to executables for each type of processor?
 
Barry Burd
Author
Ranch Hand
Posts: 133
10
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jvm is a translator from .class to executables for each type of processor?"

That's the story in a nutshell. Each processor (more precisely, each operating system for each processor) has its own version of the JVM for translating .class code to executables for that operating system and that processor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!