利用Calendar class
java.util.Calendar
ex: 顯示目前幾點
Calendar.getInstance().get(Calendar.HOUR_OF_DAY)
顯示目前幾分
Calendar.getInstance().get(Calendar.MINUTE)
2008年2月28日 星期四
2008年2月19日 星期二
2008年2月17日 星期日
JNI
檔名:
.jnilib : mac os x , prefixed by lib and suffixed with .jnilib
.so : solaris and linux
.dll: windows
in library file:
(1) include
(2) function格式:
ex: JNIEXPORT jint JNICALL Java_Test_show(JNIEnv *env, jobject rkObject)
function name = Java_Test_show, 以Java開頭,接著是溝通的Java的class name,最後才是function name
如果Java是在某個package上,要包含package name, 例如class Dog在package Animal下,
則完整的function name是Java_Animal_Dog_eat()
JNIEXPORT and JNICALL make this function to be found
(3)compile:
gcc -c -I /System/Library/Frameworks/JavaVM.framework/Headers test.c
如果是在xcode,在target info panel下的 build tab下的Header Search Paths設成/System/Library/Frameworks/JavaVM.framework/Headers
(4) product jnilib file
gcc -dynamiclib -o libtest.jnilib test.o -framework JavaVM
in Java
(1) check path, jnilib檔的位置要在path上
System.out.println( System.getProperty( "java.library.path" ) );
(2) loads the library named libhello.jnilib
System.loadLibrary("hello")
(3) 宣告要呼叫的library function
ex: public native void show();
以public native開頭
把Array 的結果copy back to 呼叫端
(*env)->ReleaseIntArrayElements(env, ctrllist, jBody, 0);
.jnilib : mac os x , prefixed by lib and suffixed with .jnilib
.so : solaris and linux
.dll: windows
in library file:
(1) include
(2) function格式:
ex: JNIEXPORT jint JNICALL Java_Test_show(JNIEnv *env, jobject rkObject)
function name = Java_Test_show, 以Java開頭,接著是溝通的Java的class name,最後才是function name
如果Java是在某個package上,要包含package name, 例如class Dog在package Animal下,
則完整的function name是Java_Animal_Dog_eat()
JNIEXPORT and JNICALL make this function to be found
(3)compile:
gcc -c -I /System/Library/Frameworks/JavaVM.framework/Headers test.c
如果是在xcode,在target info panel下的 build tab下的Header Search Paths設成/System/Library/Frameworks/JavaVM.framework/Headers
(4) product jnilib file
gcc -dynamiclib -o libtest.jnilib test.o -framework JavaVM
in Java
(1) check path, jnilib檔的位置要在path上
System.out.println( System.getProperty( "java.library.path" ) );
(2) loads the library named libhello.jnilib
System.loadLibrary("hello")
(3) 宣告要呼叫的library function
ex: public native void show();
以public native開頭
把Array 的結果copy back to 呼叫端
(*env)->ReleaseIntArrayElements(env, ctrllist, jBody, 0);
2008年1月31日 星期四
ShiftOne JRat
可trace Java程式運行過程中的function call。
如何trace
在觀察的java程式的VM arguments加上
-javaagent:shiftone-jrat.jar
如何trace
在觀察的java程式的VM arguments加上
-javaagent:shiftone-jrat.jar
jar
建jar檔
jar cvfm myJAR.jar manifest *.class
mainfest : 說明main在哪個class
Main-Class:<空一格>類別名稱
<空白行>
run多個jar檔:
java -cp x.jar:y.jar abc.mainApp
-cp後接相關的jar檔, mainApp表示main所在的class, abc表 mainApp所在的package
jar cvfm myJAR.jar manifest *.class
mainfest : 說明main在哪個class
Main-Class:<空一格>類別名稱
<空白行>
run多個jar檔:
java -cp x.jar:y.jar abc.mainApp
-cp後接相關的jar檔, mainApp表示main所在的class, abc表 mainApp所在的package
shark( profile program in MAC)
ex:
如果test是java的程式,
java -agentlib:Shark test 使得此程式可被shark觀看,
然後在shark的程式裡選擇start開始sample。
選擇java call trace可觀看程式運行時的function call呼叫情形。
如果test是java的程式,
java -agentlib:Shark test 使得此程式可被shark觀看,
然後在shark的程式裡選擇start開始sample。
選擇java call trace可觀看程式運行時的function call呼叫情形。
2008年1月29日 星期二
2008年1月24日 星期四
2008年1月23日 星期三
instanceof
判斷一個物件是否是某個type
ex: if(x instanceof Dog)
如果x的type是dog,and dog extends Animal
x instanceof Dog and x instanceof Animal are both true
如果y的type是Animal,
y instanceof Animal is ture. But y instanceof Dog is false
ex: if(x instanceof Dog)
如果x的type是dog,and dog extends Animal
x instanceof Dog and x instanceof Animal are both true
如果y的type是Animal,
y instanceof Animal is ture. But y instanceof Dog is false
how to get resource
1. get Class object of the class that has resource
2. if resource is image or audio , use getResource(String name) to get resource as a URL.
Then read it with getImage or getAudioClip
3. other resource use getResourceAsStream(String name) to get InputStream to read.
2. if resource is image or audio , use getResource(String name) to get resource as a URL.
Then read it with getImage or getAudioClip
3. other resource use getResourceAsStream(String name) to get InputStream to read.
property
The keys & values are strings
java.util.Properties
property file format:
key = value
ex:
Properties settings = new Properties();
settings.put("PROMPT", "$p$g");
settings.put("TEMP", "C:\\Windows\\Temp");
settings.put("CLASSPATH", "c:\\jdk\\lib;.");
settings.store(System.out, "Environment settings");
output:
#Environment settings
#Sun Jan 21 07:22:52 1996
CLASSPATH=c:\\jdk\\lib;.
TEMP=C:\\Windows\\Temp
PROMPT=$p$g
store(OutputStream out, String comments):
Writes this property list (key and element pairs) in this Properties table to the output stream
to load properties from a file:
FileInputStream in = new FileInputStream("text.properties");
settings.load(in);
use getProperty(String key) to get property
java.util.Properties
property file format:
key = value
ex:
Properties settings = new Properties();
settings.put("PROMPT", "$p$g");
settings.put("TEMP", "C:\\Windows\\Temp");
settings.put("CLASSPATH", "c:\\jdk\\lib;.");
settings.store(System.out, "Environment settings");
output:
#Environment settings
#Sun Jan 21 07:22:52 1996
CLASSPATH=c:\\jdk\\lib;.
TEMP=C:\\Windows\\Temp
PROMPT=$p$g
store(OutputStream out, String comments):
Writes this property list (key and element pairs) in this Properties table to the output stream
to load properties from a file:
FileInputStream in = new FileInputStream("text.properties");
settings.load(in);
use getProperty(String key) to get property
2008年1月22日 星期二
eclipse cvs
Synchronize with Repository
顯示本地端檔案與CVS的差異
Commit
將檔案更改送上CVS, 參考 Eclipse/CVS Commit
Update
更新本地端檔案, 參考 Eclipse/CVS Update
顯示本地端檔案與CVS的差異
Commit
將檔案更改送上CVS, 參考 Eclipse/CVS Commit
Update
更新本地端檔案, 參考 Eclipse/CVS Update
2008年1月14日 星期一
訂閱:
文章 (Atom)
