Java bytecode: Difference between revisions

Content deleted Content added
m Typo & format fix , typos fixed: assymetry → asymmetry using AWB
Miko3k (talk | contribs)
added some headings; expanded
Line 1:
'''Java bytecode''' is the form of instructions that the [[Java virtual machine]] executes. Each [[bytecode]] instruction is one byte in length (hence the name), thus the number of bytecodes is limited to 256. Not all 256 possible bytecode values are used. In fact, [[Sun Microsystems]], the original creators of the [[Java (programming language)|Java programming language]], the [[Java virtual machine]] and other components of the Java Runtime Environment, have set aside a number of values to be permanently unimplemented. The bytecodes are given below.
 
== Relation to Java ==
A [[Java (programming language)|Java]] programmer does not need to be aware of or understand Java bytecode at all. However, as suggested in the [[IBM]] developerWorks journal, "Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembler helps the [[C (programming language)|C]] or [[C++]] programmer."<ref>[http://www-128.ibm.com/developerworks/ibm/library/it-haggar_bytecode/ Understanding bytecode makes you a better programmer]</ref>
 
A [[Java (programming language)|Java]] programmer does not need to be aware of or understand Java bytecode at all. However, as suggested in the [[IBM]] developerWorks journal, "Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembler helps the [[C (programming language)|C]] or [[C++]] programmer."<ref>[http://www-128.ibm.com/developerworks/ibm/library/it-haggar_bytecode/ Understanding bytecode makes you a better programmer]</ref>.
It is possible to write Java bytecode by hand, though this is almost never done, as modern [[compiler]]s are able to produce well performing bytecode and such code is far less readable than Java source. Originally only one compiler existed, the [[javac]] compiler from Sun Microsystems, which compiles [[Java source code]] to Java bytecode; but because all the specifications for Java bytecode are available, other parties have supplied compilers that produce Java bytecode. E.g.:
 
* [[Jikes]], compiles from the Java programming language to Java bytecode
== Generating of bytecode ==
* [[JGNAT]] and [[AdaMagic|AppletMagic]], compile from the [[Ada programming language]] to Java bytecode
 
ItMost iscommon possiblelanguage to writetargeting [[Java bytecodeVirtual by hand, though this is almost never done, as modern [[compilerMachine]]s areby ableproducing to produce well performingJava bytecode and such code is far[[Java|Java less(programming readable than Java sourcelanguage)]]. Originally only one compiler existed, the [[javac]] compiler from Sun Microsystems, which compiles [[Java source code]] to Java bytecode; but because all the specifications for Java bytecode are available, other parties have supplied compilers that produce Java bytecode. E.g.Examples other compilers include:
* [[Jikes]], compiles from the Java programming language to Java bytecode developed by [[IBM]], implemented in [[C++]]
* Espresso, compiles from the Java programming language to Java bytecode, only Java 1.0
* [[GCJ|Gnu Compiler for Java]], GCJ, compiles from the Java programming language to Java bytecode, is also able to compile to native machine code.
 
Some projects provide Java assemblers to enable writing Java bytecode by hand. Assembler code may be also generated by machine, for example by compiler targeting [[Java virtual machine]]. Notable Java assemblers include:
* [[Jasmin]], takes textual descriptions for Java classes, written in a simple assembler-like syntax using Java Virtual Machine instruction set" and generates a Java class file
* [[Jamaica (Java assembler)|Jamaica]], a macro assembly language for the [[Java virtual machine]]. Java syntax is used for class or interface definition. Method bodies are specified using bytecode instructions.
 
Others developed compilers for different programming languages targeting Java virtual machine, such as
* [[JGNAT]] and [[AdaMagic|AppletMagic]], compile from the [[Ada programming language]] to Java bytecode
* [[Groovy programming language]], A scripting language based on Java
 
== Bytecode execution ==
 
Java bytecode is designed to be executed in [[Java virtual machine]]. There are several virtual machines available today both free or commercial.
 
{{See|Java virtual machine}}
 
If executing Java bytecode in a Java virtual machine is not desirable, a developer can also compile Java source code or Java bytecode directly to native machine code with tools such as the [[GCJ|GNU Compiler for Java]].