基于Node.js的Java虛擬機:node-jvm

jopen 11年前發布 | 47K 次閱讀 Node.js Node.js 開發

node-jvm 實現了純 Node.js 環境下的 Java 虛擬機。

示例:

java

public class Main {
    public static long fib(int n) {
        if (n <= 1) return n;
        return fib(n-1) + fib(n-2);
    }

    public static void main(String[] args) {
        if (args.length == 0) {
                System.out.print("help: java Main.class {Number}");
                return;
        }

        int N = Integer.parseInt(args[0]);
        long start = System.currentTimeMillis();            
        System.out.format("Fibonacci from 1 to %s:\n", N);
        for (int i = 1; i <= N; i++) {
            System.out.println(i + ": " + fib(i));
        }
        long stop = System.currentTimeMillis();
        System.out.println("time: " + (stop - start) + "ms");

        System.out.println("done.");
    }
}

node.js

var JVM = require("../../index");
var jvm = new JVM();
jvm.loadClassFile("./Main.class");
jvm.run([10]);

項目主頁:http://www.baiduhome.net/lib/view/home/1383295597338

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!