0

i want to ask how i can write in bytecode, i need some example for sample things like make a function etc...

if someone can tell me how to write this code in bytecode i can mabey compare and learn from this.

how do i write this java code in bytecode ?

package Bytecode;

public class Main {

    public static void main(String[] args) {
        System.out.println(factorial(5));
    }

    public static int factorial(int value){
        if(value<=0 || value==1)
            return 1;

        return value*factorial(value-1);

    }
}

3 Answers3

3

You can check out Jasmin. From Wikipedia,

Some projects provide Java assemblers to enable writing Java bytecode by hand. Assembly 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 assembly-like syntax using Java Virtual Machine instruction set and generates a Java class file.

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.

Also you can see the byte code of ur class file using javap -c classname

Kick
  • 4,823
  • 3
  • 22
  • 29
1

Here's a tutorial with examples for programming with Java bytecode that I wrote. Unfortunately I stopped due to lack of interest, but if you find it useful I can finish it.

Antimony
  • 37,781
  • 10
  • 100
  • 107
0

You need a tool like this one http://commons.apache.org/proper/commons-bcel/manual.html

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275