Feeds:
文章
迴響

Archive for the ‘Java’ Category

久久用一次都會忘記, 寫個快速入門筆記給未來的自己參考

1. 產生, mvn -B archetype:generate -DgroupId=com.chuiwenchiu -DartifactId=helloApp
2. 編譯, mvn compile
3. 測試, mvn test
4. 執行, mvn exec:java -Dexec.mainClass="com.chuiwenchiu.App"
5. 打包 jar, mvn package
6. 測試 jar, java -cp target\helloApp-1.0-SNAPSHOT.jar com.chuiwenchiu.App

 

廣告

Read Full Post »

[Java8][Nashorn] 多執行緒

使用 Java.lang.Thread 讓 Javascript 具有多執行緒功能

thread.js

var Run = Java.type(“java.lang.Runnable");

var MyRun = Java.extend(Run, {

    run: function() {

        while(true){

            print(“Run in separate thread");

        }

    }

});

var Thread = Java.type(“java.lang.Thread");

var th = new Thread(new MyRun());

th.start();

while(true){

    print(“main thread");

}

Read Full Post »

測試 javascript 使用 Java Class, 外部 JAR

use_java_class.js

20140424-04

 

 

參考資料

http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html

Read Full Post »

參考 http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/shell.html

 

shell.js

20140424-03

Read Full Post »

蠻 Cool 只是啟動速度有點慢

javafx.js

20140424-01

20140424-02

Read Full Post »

import static java.lang.System.out;
import java.lang.reflect.Field;

public class Test {
    publicstaticvoid main(String[] args) {
        for (final Field field :Double.class.getDeclaredFields()){
           try {
                if(field.getName().equals("BYTES")){
                    out.println(field.get(null)); // Double = 8 bytes
                }
           }catch (IllegalAccessException illegalAccess){
                out.println("ERROR: Unable to reflect on field \"BYTES\"");
           }
        }
    }
}

參考資料
[1]http://www.javacodegeeks.com/2014/04/programmatic-access-to-sizes-of-java-primitive-types.html

Read Full Post »