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 雅羅斯拉夫·加波諾夫
特此免費授予任何獲得本軟體和相關文件文件(「軟體」)副本的人不受限制地使用本軟體,包括但不限於使用、複製、修改、合併的權利、發布、分發、再授權和/或銷售軟體的副本,並允許向其提供軟體的人員這樣做,但須滿足以下條件:
上述版權聲明和本授權聲明應包含在本軟體的所有副本或主要部分中。
本軟體以「現況」提供,不提供任何明示或暗示的保證,包括但不限於適銷性、特定用途的適用性和不侵權的保證。 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE軟體.