Content deleted Content added
add an example, which I think is not too long |
put the example first |
||
Line 13:
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]].
== Example ==▼
Consider the following Java code.▼
<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);▼
}▼
</code>▼
This is probably translated into byte code like (assuming the above was put in a method):▼
<code>▼
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▼
</code>▼
==The Java bytecodes==
Line 239 ⟶ 282:
''This list is incomplete.''
▲== Example ==
▲Consider the following Java code.
▲<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);
▲ }
▲</code>
▲This is probably translated into byte code like (assuming the above was put in a method):
▲<code>
▲ 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
▲</code>
==See also==
|