FACTOID # 27: Russia won the first World Air Games, held in Turkey in 1997. Events included hang-gliding, sky-surfing, and ballooning.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

Encyclopedia > Java bytecode

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 no more than 256. Not all 256 possible bytecode values are used, in fact Sun Microsystems, the original creators of the 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. A Java Virtual Machine (JVM), originally developed by Sun Microsystems, is a virtual machine that executes Java bytecode. ... Bytecode is a binary representation of an executable program designed to be executed by a virtual machine rather than by dedicated hardware. ... Sun Microsystems, Inc. ... Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ... A Java Virtual Machine (JVM), originally developed by Sun Microsystems, is a virtual machine that executes Java bytecode. ...


A 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 or C++ programmer."[1] Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ... now. ... Wikibooks has a book on the topic of C Programming The C programming language (often, just C) is a general-purpose, procedural, imperative computer programming language developed in the early 1970s by Dennis Ritchie for use on the Unix operating system. ... C++ (generally pronounced /si plÊŒs plÊŒs/) is a general-purpose, high-level programming language with low-level facilities. ...


It is possible to write Java bytecode by hand, however this method is almost never used in real life because nowadays the compilers are able to compile well performing code and nearly no person is able to comprehend a piece of Java bytecode of considerable size. 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.: A diagram of the operation of a typical multi-language, multi-target compiler. ... In computing, a Java compiler is a computer program that translates programs in Java to Java byte-code. ... Java is an object-oriented programming language developed by Sun Microsystems in the early 1990s. ...

  • Jython, an interpreter for Python written in Java that also includes jythonc, a compiler that compiles Python code into Java bytecode
  • Jikes, compiles from the Java programming language to Java bytecode
  • JGNAT, compiles from the Ada programming language to Java bytecode
  • Espresso, compiles from the Java programming language to Java bytecode, only Java 1.0
  • Gnu Compiler for Java, GCJ, compiles from the Java programming language to Java bytecode, is also able to compile to native machine code.
  • Groovy programming language, A scripting language based on java

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 GNU Compiler for Java. Jython, formerly known as JPython, is an implementation of the Python programming language written in Java. ... Python is an interpreted programming language created by Guido van Rossum in 1990. ... In computing, a Java compiler is a computer program that translates programs in Java to Java byte-code. ... For the German Naval Acoustic Torpedo see G7es torpedo. ... Ada is a structured, statically typed imperative computer programming language designed by a team led by Jean Ichbiah of CII Honeywell Bull during 1977–1983. ... Espresso brewing, with a dark reddish-brown foam, called crema. ... The GNU Compiler for Java (GCJ) is a compiler for the Java programming language that is part of the GNU Compiler Collection (GCC). ... In slang and informal language, Groovy refers to a fashionable or desirable quality, without necessarily specifying one. ... The GNU Compiler for Java (GCJ) is a compiler for the Java programming language that is part of the GNU Compiler Collection (GCC). ...

Contents

Example

Consider the following Java code.

 outter: for (int i = 2; i < 1000; i++) { for (int j = 2; j < i; j++) { if (i % j == 0) continue outter; } System.out.println (i); } 

This is probably translated into byte code like (assuming the above was put in a method):

 Code: 0: iconst_2 1: istore_1 2: iload_1 3: sipush 1000 6: if_icmpge 44 9: iconst_2 10: istore_2 11: iload_2 12: iload_1 13: if_icmpge 31 16: iload_1 17: iload_2 18: irem # remainder 19: ifne 25 22: goto 38 25: iinc 2, 1 28: goto 11 31: getstatic #84; //Field java/lang/System.out:Ljava/io/PrintStream; 34: iload_1 35: invokevirtual #85; //Method java/io/PrintStream.println:(I)V 38: iinc 1, 1 41: goto 2 44: return 

The Java bytecodes

Please see Sun's Java Virtual Machine Specification for more detailed descriptions (link at bottom of page)

Mnemonic Opcode
(in hex)
Description
A
aaload 32 loads onto the stack a reference to an array
aastore 53 stores into a reference to an array
aconst_null 01 pushes a null reference onto the stack
aload 19 loads a reference onto the stack from a local variable
aload_0 2a loads a reference onto the stack from local variable 0
aload_1 2b loads a reference onto the stack from local variable 1
aload_2 2c loads a reference onto the stack from local variable 2
aload_3 2d loads a reference onto the stack from local variable 3
anewarray bd creates a new array of references
areturn b0 returns a reference from a method
arraylength be gets the length of an array
astore 3a stores a reference into a local variable
astore_0 4b stores a reference into local variable 0
astore_1 4c stores a reference into local variable 1
astore_2 4d stores a reference into local variable 2
astore_3 4e stores a reference into local variable 3
athrow bf throws an error or exception
B
baload 33 loads a byte or Boolean value from an array
bastore 54 stores a byte or Boolean value into an array
bipush 10 pushes a byte onto the stack
C
caload 34 loads a char from an array
castore 55 stores a char into an array
checkcast c0 checks whether an object is of a certain type
D
d2f 90 converts a double to a float
d2i 8e converts a double to an int
d2l 8f converts a double to a long
dadd 63 adds two doubles
daload 31 loads a double from an array
dastore 52 stores a double into an array
dcmpg 98 compares two doubles
dcmpl 97 compares two doubles
dconst_0 0e pushes the constant 0.0 onto the stack
dconst_1 0f pushes the constant 1.0 onto the stack
ddiv 6f divides two doubles
dload 18 loads a double from a local variable
dload_0 26 loads a double from local variable 0
dload_1 27 loads a double from local variable 1
dload_2 28 loads a double from local variable 2
dload_3 29 loads a double from local variable 3
dmul 6b multiplies two doubles
dneg 77 negates a double
drem 73 gets the remainder from a division between two doubles
dreturn af returns a double from a method
dstore 39 stores a double into a local variable
dstore_0 47 stores a double into local variable 0
dstore_1 48 stores a double into local variable 1
dstore_2 49 stores a double into local variable 2
dstore_3 4a stores a double into local variable 3
dsub 67 subtracts a double from another
dup 59 duplicates the value on top of the stack
dup_x1 5a inserts a copy of the top value into the stack two values from the top
dup_x2 5b inserts a copy of the top value into the stack two or three values from the top
dup2 5c duplicate top two stack words
dup2_x1 5d duplicate two words and insert beneath third word
dup2_x2 5e duplicate two words and insert beneath fourth word
F
f2d 8d converts a float to a double
f2i 8b converts a float to an int
f2l 8c converts a float to a long
fadd 62 adds two floats
faload 30 loads a float from an array
fastore 51 stores a float in an array
fcmpg 96 compares two floats
fcmpl 95 compares two floats
fconst_0 0b pushes 0.0f on the stack
fconst_1 0c pushes 1.0f on the stack
fconst_2 0d pushes 2.0f on the stack
fdiv 6e divides two floats
fload 17 loads a float from a local value
fload_0 22 loads a float from local variable 0
fload_1 23 loads a float from local variable 1
fload_2 24 loads a float from local variable 2
fload_3 25 loads a float from local variable 3
fmul 6a multiplies two floats
fneg 76 negates a float
frem 72 gets the remainder from a division between two floats
freturn ae returns a float
fstore 38 stores a float into a local variable
fstore_0 43 stores a float into local variable 0
fstore_1 44 stores a float into local variable 1
fstore_2 45 stores a float into local variable 2
fstore_3 46 stores a float into local variable 3
fsub 66 subtracts two floats
G
getfield b4 gets a field of an object
getstatic b2 gets a static field of a class
goto a7 goes to another instruction
goto_w c8 goes to another instruction
I
i2b 91 converts an int into a byte
i2c 92 converts an int into a character
i2d 87 converts an int into a double
i2f 86 converts an int into a float
i2l 85 converts an int into a long
i2s 93 converts an int into a short
iadd 60 adds two ints together
iaload 2e loads an int from an array
iand 7e performs a logical and on two integers
iastore 4f stores an int into an array
iconst_m1 02 loads the int value -1 onto the stack
iconst_0 03 loads the int value 0 onto the stack
iconst_1 04 loads the int value 1 onto the stack
iconst_2 05 loads the int value 2 onto the stack
iconst_3 06 loads the int value 3 onto the stack
iconst_4 07 loads the int value 4 onto the stack
iconst_5 08 loads the int value 5 onto the stack
idiv 6c divides two integers
if_acmpeq a5 branch if reference comparison succeeds
if_acmpne a6 branch if int comparison succeeds
if_icmpeq 9f branch if int is value of comparator
if_icmpne a0 branch if int is not value of comparator
if_icmplt a1 branch if int is less than value of comparator
if_icmpge a2 branch if int is greater than or equal to value of comparator
if_icmpgt a3 branch if int is greater than value of comparator
if_icmple a4 branch if int is less than or equal to value of comparator
ifeq 99 branch if int is 0
ifne 9a branch if int is not 0
iflt 9b branch if int is less than 0
ifge 9c branch if int is greater than or equal to 0
ifgt 9d branch if int is greater than 0
ifle 9e branch if int is less than or equal 0
ifnonnull c7 branch if reference is not null 0
ifnull c6 branch if reference is null 0
iinc 84 increment local variable by constant
iload 15 loads an int from a variable
iload_0 1a loads an int from variable 0
iload_1 1b loads an int from variable 1
iload_2 1c loads an int from variable 2
iload_3 1d loads an int from variable 3
imul 68 multiply two integers
ineg 74 negate int
instanceof c1 determines if an object is of a given type
invokeinterface b9 invokes an interface
invokespecial b7 invoke instance method
invokestatic b8 invoke a static method
invokevirtual b6 invoke virtual method
ior 80 logical int or
irem 70 logical int remainder
ireturn ac returns an integer from a method
ishl 78 int shift left
ishr 7a int shift right
istore 36 store int into variable
istore_0 3b store int into variable 0
istore_1 3c store int into variable 1
istore_2 3d store int into variable 2
istore_3 3e store int into variable 3
isub 64 int subtract
iushr 7c int shift right
ixor 82 int xor
J
jsr a8 jump to subroutine
jsr_w c9 jump to subroutine (wide index)
L
l2d 8a converts a long to a double
l2f 89 converts a long to a float
l2i 88 converts a long to a int
ladd 61 add two longs
laload 2f
land 7f bitwise and of two longs
lastore 50
lcmp 94 compares two longs values
lconst_0 09 pushes the long 0 onto the stack
lconst_1 0a pushes the long 1 onto the stack
ldc 12 pushes a constant (String, int or float) onto the stack
ldc_w 13 pushes a constant (String, int or float) onto the stack (wide index)
ldc2_w 14
ldiv 6d divide two longs
lload 16
lload_0 1e
lload_1 1f
lload_2 20
lload_3 21
lmul 69 multiplies two longs
lneg 75 negates a long
lookupswitch ab
lor 81 bitwise or of two longs
lrem 71
lreturn ad
lshl 69
lshr 7b
lstore 37 store a long in a local variable
lstore_0 3f
lstore_1 40
lstore_2 41
lstore_3 42
lsub 65 subtract two longs
lushr 7d
lxor 83 bitwise exclusive or of two longs
M
monitorenter c2
monitorexit c3
multianewarray c5
N
new bb
newarray bc
nop 00 performs no operation
P
pop 57 discards the top value on the stack
pop2 58 discards the top two values on the stack
putfield b5
putstatic b3
R
ret a9
return b1
S
saload 35
sastore 56
sipush pushes a signed integer onto the stack
swap 5f
T
tableswitch aa
W
wide c4
Unused
breakpoint ca reserved for breakpoints in Java debuggers; should not appear in any class file
impdep1 fe reserved for implementation-dependent operations within debuggers; should not appear in any class file
impdep2 ff reserved for implementation-dependent operations within debuggers; should not appear in any class file
(no name) cb-fd these values are currently unassigned for opcodes and are reserved for future use
xxxunusedxxx ba this opcode is reserved "for historical reasons"

This list is incomplete.


See also

ARM9E is an ARM architecture 32-bit RISC CPU family. ... CPU redirects here. ... It has been suggested that Microsoft Intermediate Language be merged into this article or section. ... In computing, Common Language Runtime (CLR) is the name chosen by Microsoft for the virtual machine plus runtime library underlying their . ... The Microsoft . ... C to Java Virtual Machine compilers attempt to marry the highly popular C language with the platform independent Java Virtual Machine for Write Once Run Anywhere (WORA) using the C language. ...

External links

Java (Sun)
Major Technologies: Java (programming language) | Java Platform | Java Development Kit | Java Virtual Machine | Java Runtime Environment
History: Java version history | Criticism of Java | Java Community Process | Sun Microsystems
Language Features: Bytecode | Syntax | Applets | Servlets | JavaServer Pages

  Results from FactBites:
 
Program Transformation Wiki / Java Decompilers (718 words)
Decompilers that read Java bytecode programs usually decompile to Java, since that is the language that the majority of such programs are written in.
SourceTec Java Decompiler (formerly the Jasmine Java Decompiler) is a patch to Mocha, a well known decompiler.
Programming Languages for the Java Virtual Machine is a page by Robert Tolksdorf for all sorts of languages that can be compiled to bytecodes, or translated to Java source.
  More results at FactBites »

 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your location
Your comments
Please enter the 5-letter protection code


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.