node jvm
1.0.0
node-jvm - 纯 Node.js 中的 jvm
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." );
}
}
var JVM = require ( "node-jvm" ) ;
var jvm = new JVM ( ) ;
jvm . setLogLevel ( 7 ) ;
var entryPointClassName = jvm . loadJarFile ( "./Main.jar" ) ;
jvm . setEntryPointClassName ( entryPointClassName ) ;
jvm . on ( "exit" , function ( code ) {
process . exit ( code ) ;
} ) ;
jvm . run ( [ 15 ] ) ;
cd examples/fibonacci; make
./fibonacci.js
make clean
Fibonacci from 1 to 15:
1: 1
2: 1
3: 2
4: 3
5: 5
6: 8
7: 13
8: 21
9: 34
10: 55
11: 89
12: 144
13: 233
14: 377
15: 610
time: 106ms
done.
cd examples/
arrays - working with different types of arrays
dogs - simple object-oriented programming
fibonacci - recursion
jsclass - java and javascript mix
switcher - working with different switches
cast - cast for different types
ex - program exceptions
ex2 - jvm exceptions
idogs - working with interface
static - working with static objects
threads - multithreading
雅罗斯拉夫·加波诺夫 (yaroslav.gaponov -at - gmail.com)
麻省理工学院许可证 (MIT)
版权所有 (c) 2013 雅罗斯拉夫·加波诺夫
特此免费授予获得本软件和相关文档文件(“软件”)副本的任何人不受限制地使用本软件,包括但不限于使用、复制、修改、合并的权利、发布、分发、再许可和/或销售软件的副本,并允许向其提供软件的人员这样做,但须满足以下条件:
上述版权声明和本许可声明应包含在本软件的所有副本或主要部分中。
本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途的适用性和不侵权的保证。在任何情况下,作者或版权持有者均不对因本软件或本软件中的使用或其他交易而产生或与之相关的任何索赔、损害或其他责任负责,无论是合同、侵权行为还是其他行为。软件。