-1

As I read is bytecode an intermediate language which is used by a virtual machine which has to be installed on the computer to run the program. Wikipedia says, that a VM either executes the bytecode directly or generates machine code for better performance. The article also says, that bytecode is a set of instructions. For me it sounds like normal machine code, except that only the VM can understand it (Am I right?).

So what is the purpose of bytecode? If a VM can also compile it to machine code why can't the compiler do it directly and we don't need the VM and have better performance?

Bruno Zell
  • 7,761
  • 5
  • 38
  • 46
  • 2
    I went to A Well-Known Search Engine and typed in your exact subject line: "What is the purpose of bytecode?" The very first hit was a SO question very similar to this question, and that question linked to the one I've now marked as duplicate. Please put effort into researching your question before you ask strangers to do it for you; and if you did, then please include some of the results of that research so that we can better tailor our responses instead of rehashing what's already out there. – yshavit Aug 04 '15 at 21:50

1 Answers1

0

This may not be the best place for this question, but it depends. In the case of Java, portability is king.

Windows applications have the advantage that you can rely on many of the system libraries not being compiled with the program. It also extends portability since the code will not depend on architecture (generally.)

More generally, you can generate byte code compilers that can generate code to the same byte code standard in many languages, providing easy interoperability between modules. (like in. NET a c# library can be referenced in a VB project)

There is certainly a much more in depth explanation, but generally these are the advantages.

James Ralston
  • 1,170
  • 8
  • 11