這幾天看新聞知道番茄花園作者被警方逮捕,樹大招風,槍打出頭鳥,很正常,從程序員的身份來講,盜版是要打擊的,不過我本身電腦里要付費的軟件都是盜版的,很矛盾,呵呵。 實在太久沒寫servlet了,應該至少1年了,那時候做了點皮毛,現在項目要求用到servlet的相關知識,同時我在blogjava的bolg又開張了。學習的過程將記錄在我的blog中。對比了一下netbean和eclipse感覺用netbean編寫servlet程序方便些,eclipse用了幾年,但是還是感覺每次要找好相關的jar需要花費太多時間,于是決定用netbean編寫了。
看看以下代碼:
將26個英文字母重復加了5000次,
String tempstr = "abcdefghijklmnopqrstuvwxyz";
int times = 5000;
long lstart1=System.currentTimeMillis();
??String str ="";
??for(int i=0;i<times;i++)
??{
???str+=tempstr;
??}
??
??long lend1=System.currentTimeMillis();
??long time = (lend1-lstart1);
??System.out.println(time);
可惜我的計算機不是超級計算機,得到的結果每次不一定一樣一般為 154735 左右。
也就是154秒。
我們再看看以下代碼
String tempstr = "abcdefghijklmnopqrstuvwxyz";
?
??int times = 5000;
long lstart2=System.currentTimeMillis();
??StringBuffer sb =new? StringBuffer();
??for(int i=0;i<times;i++)
??{
???sb.append(tempstr);
???
??}
??long lend2=System.currentTimeMillis();
??long time2 = (lend2-lstart2);
??System.out.println(time2);
?得到的結果為 16 有時還是 0
所以結論很明顯,StringBuffer 的速度幾乎是String 上萬倍。當然這個數據不是很準確。因為循環的次數在100000次的時候,差異更大。不信你試試。
下一次我將解釋為什么StringBuffer 的效率比String 高這么多。
swt 簡單的托盤程序
java寫和操作系統相關的程序難度非常大。在java 6出現之前,如果你想實現一個托盤程序,最簡單的就是用swt了。
通過google我找到了一段代碼。
其實很簡單。主要的代碼如下:
?????????????final Tray tray = display.getSystemTray();
??????????? final TrayItem trayItem = new TrayItem(tray, SWT.NONE);
??????????? Image image = new Image (display, 16, 16);
??????????? trayItem.setImage(image);
知道了重點,事情變的很簡單了。看看所有程序
//-----------------
public class SystemTray extends Shell {
??? public static void main(String args[]) {
??????? try {
??????????? Display display = Display.getDefault();
??????????? SystemTray shell = new SystemTray(display, SWT.SHELL_TRIM);
?????????? // shell.createSystemTray(shell);
??????????? final Tray tray = display.getSystemTray();
??????????? final TrayItem trayItem = new TrayItem(tray, SWT.NONE);
??????????? Image image = new Image (display, 16, 16);
??????????? trayItem.setImage(image);
??????????? shell.open();
??????????? shell.layout();
??????????? while (!shell.isDisposed()) {
??????????????? if (!display.readAndDispatch())
??????????????????? display.sleep();
??????????? }
??????? } catch (Exception e) {
??????????? e.printStackTrace();
??????? }
??? }
??? public SystemTray(Display display, int style) {
??????? super(display, style);
??????? createContents();
??? }
??? /**
???? * Create contents of the window
???? */
??? protected void createContents() {
??????? setText("SWT Application");
??????? setSize(500, 375);
??? }
??? //swt 默認情況下不允許shell被繼承
??? //所以我重載了父類的方法
??? protected void checkSubclass() {
???????? }
}
//--------------------
如果你想成功運行以上代碼,你最好在eclipse下新建一個swt的類。具體操作你搜索一下吧。
但是上面的代碼只是加入了托盤,這可能是最簡單的實現托盤的程序了。我們加入事件處理,讓程序能夠最大和最小化。然后把托盤用圖片來表示。
詳細的代碼不參考
下載
到eclipse里運行
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
31 | 1 | 2 | 3 | 4 | 5 | 6 | |||
7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
21 | 22 | 23 | 24 | 25 | 26 | 27 | |||
28 | 29 | 30 | 31 | 1 | 2 | 3 | |||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
常用鏈接
留言簿(18)
我參與的團隊
隨筆檔案(39)
- 2008年8月 (1)
- 2008年7月 (1)
- 2007年1月 (2)
- 2006年9月 (1)
- 2006年5月 (5)
- 2006年4月 (4)
- 2006年3月 (5)
- 2006年2月 (1)
- 2006年1月 (9)
- 2005年12月 (2)
- 2005年11月 (2)
- 2005年10月 (6)
收藏夾(1)
搜索
積分與排名
- 積分 - 451355
- 排名 - 119
最新評論

- 1.?re: 天行健,君子以自強不息;地勢坤,君子以厚德載物
- 有這麼難嗎,
- --弟弟
- 2.?re: 效率低下
- 真是的,既然不是靜水流深,那就把家底一五一十的報上來
- --簡單的生長
- 3.?re: 天行健,君子以自強不息;地勢坤,君子以厚德載物
- 幼稚,天主動,意為天道,天道運行不息。君子當效天道,錘煉意志,精神。一往無前,以證天道。地為坤,主靜,意指本源。君子當應地勢,取長補短,明心見性,外練體魄,內修德行。
- --大號中華
- 4.?re: 天行健,君子以自強不息;地勢坤,君子以厚德載物
-
灌灌灌灌灌灌灌灌灌灌灌灌灌灌灌
@對方的豐富的
- --的幾率
- 5.?re: 樹型Table的設計[未登錄]
- 求一份,xuan0555@126.com
- --ff