• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

question about jvm

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic