顯示具有 Java 標籤的文章。 顯示所有文章
顯示具有 Java 標籤的文章。 顯示所有文章

2008年12月11日 星期四

The Cafes » Java is Dead! Long Live Python!

[From The Cafes » Java is Dead! Long Live Python!]


Right, it's quite "unholy" to read that "Java is Dead" when you do Java programming for a living. (Well, I hear "FreeBSD is DEAD, according to Netcraft" all the time too, but I use FreeBSD a lot). But I think the article has a point on primitive typing thing though in the end it gets things done. Time to read more on Python 3.0.




2007年10月24日 星期三

Bug 14954 – [printing] Java editor should turn off line highlighting when printing


Bug 14954 – [printing] Java editor should turn off line highlighting when printing:


這是我2002年4月30日file的Eclipse bug,今天終於變成 FIXED in HEAD.


朔風野大,阿兄歸矣....



2007年9月28日 星期五

偉哉 Apache2

Root Beer - Serving Pack200 Jar files with Apache 2
最近一直被 WebStart 的 JAR 檔案大小所困擾。程式越寫越大,每次需要update的 JAR 就越來越肥、越來越多。


雖然之前就知道 JDK 都會送一個叫做 pack200 的壓縮工具,Pack200 實際上是把 JAR 壓縮起來傳輸,等傳到client 機器以後把解壓縮的工作丟給 client 機器來。
Pack200 把 XXX.jar 壓完以後改為 xxx.pack.gz,Webstart Client 在 request file 的時候,會把 Accepted Encoding 送到 server 去,可以接受的有 .gz 和 pack.gz 兩種。如果Server 發現有 <檔名>.pack.gz 的話,會優先送出,再來是 .gz,最後才是 .jar。但是 server side 每次都得裝個 container + servlet,由 servlet 來負責做 content negotiation,實在很不方便。
有一天,v3g 長輩看到我在頻道上問 mod_deflate 有沒有辦法改出 mod_pack200 來用,就很慷慨地說要幫我用 output_filter 寫一隻,今天測試完成。本來想就這樣deploy到香港去,應該可以節省不少 update 的頻寬。沒想到長輩真是太英明了,找到兩篇用 Apache2 內建的功能就可以達到相同目的的文章。
第一篇用的是 re-write engine,第二篇更暴力,直接開Multiview,把 .pack.gz 的 Mimetype 用 ForceType 和 Java Achive 綁在一起。第二個方法雖然很簡單,但是因為 Multiview 的 serve 順序會和原來 SUN 建議的方式不一樣,會以 .jar 優先,再來才是 .pack.gz。不過這並不影響我的用途,因為 JAR file 本來就會先 pack/sign 才會丟上 server 去,只要不要把 jar 放進去就可以了。

2007年9月21日 星期五

Big5, GB2312 and UTF-8-ization

這算是個由來已久的問題,現在看來,一開始錯誤的決定的確是會造成後面無數的困擾。

三年前這個系統開始需要作簡體中文版的時候,我們的team裡面有過一段討論,就是關於後台的DB到底應該用UTF-8還是使用 locale encoding。我們做 client 的人微言輕, arch leader 以『所謂的localization就是要讓使用者不可以輸入任何 local encoding 以外的字符』為理由,還是把後台的DB 設定成 Big5 (Oracle 還沒有MS950咧!) 或是 GB2312。

現在的問題來了,常常發生在台北開發的 code 移過來,卻發生 encoding 的問題,輸入到後台的東西也常常因為 iconv error 莫名奇妙掛掉(後來發現可以 /IGNORE,不過這是patch不是solution)。如果後台完全都是 UTF-8,那這些就不需要擔心了。

前端的 Java 一直以來都是 full UTF-8 capable,所以在 text component 裡面輸入任意文字都沒有問題,內部都當作 UTF-8 來處理。但是這裡有個小陷阱。如果某個輸入的String encoding==local encoding(internally UTF-8,但是以locale encoding去parse沒有錯誤的話),那個getBytes.length 會是以 local encoding 的長度來計算的。比如用在繁體中文Windows下輸入"只許成功不許失敗",然後去getBytes,結果會是16。但是同樣的 input string如果放在簡體中文Windows下用繁體中文輸入法輸入,得到的getBytes會 >= 16。因為此時用local encoding去parse有問題,只好用UTF-8的getBytes長度了。

所以現在測試人員如果用繁體中文環境來測試簡體中文的client,輸入的字串長度常常會因為這個問題,造成誤判,結果超出檢核的上限。會需要檢核上限,也是因為DB裡面設定的欄位寬度是以 latin-1 char 計算,其實通通改用 NCHAR, NVARCHAR2,檢核的時候也已 UTF-8 的 char 數來檢覈,就可以解決了。


2007年5月22日 星期二

TinyDISK

TinyDisk :: Most Significant Bit Labs

今天早上頻道長輩們在講利用 TinyURL 存放東西的 TinyDISK,過去看了一下,和想到的原理差不多,不過做得相當完整。為了避免 TinyURL開始對長度做限制,TinyDISK 還可以把檔案切開來放在不同的 hash 裡面,用一個 meta data 來取回所有的 hach chunks。

之前也有一個利用 skype 的服務來做大檔案 publish/retrieval 的程式叫做 Pando,不過看起來沒有流行。



2007年2月10日 星期六

Java 6 and Firefox

Java SE 6 Firefox 2 UI 問題 - 網絡暴民 Jacky’s Blog

居然是只有台灣的中文才會有問題,Sun實在應該打屁股....(難怪只在我的X31上面發作,公司的電腦反而沒問題)


2006年10月16日 星期一

2006年7月22日 星期六

JRE在FreeBSD底下顯示正確中文的秘技

一直以來,被FreeBSD下的X locale + Java的中文問題困擾很久。每次都去動 fonts.gg.yy.properties,換個字體馬上爆炸。從以前用的新細明體、simhei.ttf到現在的微軟正黑體,只要換一次字體就要來個大手術。這次裝了Diablo 1.5,更是完全不知道從何下手,原始碼只附送了一個 fontconfig.properties.src,裡面壓根沒提到 iso-10646-1。想到要手動把每一種字體都加進去都快抓狂了。沒想到,這個網站的方法真是簡單到一種境界,只要:

sudo ln -s /usr/X11R6/lib/X11/fonts/TTF ${JAVA_HOME}/lib/fonts/fallback

一切天下太平....雖然中文字還是粉醜,但是繁簡中可以一起顯示不再有框框的問題。真是絕招中的絕招、秘技中的秘技啊~

2005年11月8日 星期二

It is a dark blue Monday indeed, with thoughts on Coding Styles

It is a dark blue Monday, with most of the stuff not going too well. I need to pick up maintaining a set of code that I left when I came over to Shanghai. To my horror, the code has gained YET ANOTHER LIBRARY! I really hate these stuff as they:

1. Increase 3rd party library maintenance burden
2. Non-standard API conventions, which once a person sticks to, it's hard to shake off
3. Importing something for the sake of "easy" coding is sloppy.

Sloppy import means sloppy way to think about approaches to problems, and may result in sloppy code. (this was later proved in the code with upper-case first letter for a package name). I really wouldn't mind anyone inventing something new or great, but doing it because it's more easily done is plainly unacceptable. I spent over 2 weeks with Hanhui trying to convert all dom4j API over to W3C in hope that we might at last rely on a standard base for XML APIs, instead of a patch here and a patch there. XPath was incoporated into JDK1.5 too, making it possible to retain most of the XPath code with very little modification. A line with:

XPath xpath = XPathFactory.newInstance().newXPath();


and anyone can continue using XPath expressions, why another XML4J? And the only file that uses XML4J can be changed in a day if one reads the document and understands enough about XML basics. If one cannot do that, either one knows too little about XML, or is being lazy.

For the past 2 years, I thought what I did to the code regarding styles and coding rules would make a difference to all my teammates, at least they would understand what I was doing. No, apparantly I was wrong. Action does not speak at all. This incident just proves it.

To look on the bright side of things, at least here in Shanghai, I am not preaching to the choir. One of my teammates agreed to what I had in mind and went ahead to implement what BlueStone was supposed to do - render XML-defined Swing Objects. To take this further down the road, combined with what we did previously, we are into:
1. XML-based GUI rendering, with proper ActionListeners and inter-object calls.
2. Renderers and Editors for JTextComponents
3. Form-based designer for non-programmers, virtually creating a much more powerful rendering environment than the standard web-browsers. But browser technology is gaining fast too, we may need to look into XUL. Sadly it's firefox and mozilla only at the moment.
4. Quick business logic -> GUI controllers. Controllers are to be linked to the GUIs rendered by XML, providing mechanisms akin to JSP Custom Tags.

One man has only 24 HRs a day, I need to focus on what I WILL do than what I already DID. Enough whining and get back to work now.

2005年9月13日 星期二

終於把Java client 的UTF-8搞定了

原本把系統從Big5改為UTF-8的時候犯了一個小錯誤,對於JVM內部的String結構有所誤解

,以為可指定charset,所以一直都在
new String(byte[], charset)
上面打轉。
後來把Java Tutorial裡面相關的i18n的章節又看了一次,才發現原來問題出在input/output stream。只要把系統的出入口搞定了,內部的String表現全部都是unicode,也就不存在charset轉換的問題了。這下子也一併解決了BlueStone+Dom4j原本不能處理按鈕使用UTF-8的問題了。
目前只剩下一個問題,也就是DOM DocumentBuilder利用ByteArrayInputStream讀入一個ByteArray的時候,這個ByteArray如果先利用 getBytes("UTF-8")把非法的UTF-8 character 拿掉的話,就不容易發生SAXException。但是如果僅使用getBytes的話,可能因為docString裡面含有非法的UTF-8字元,造成client death。我認為的解法應該是把document好好重建一次,這樣對於整體程式碼來說,是比較健康的。

2005年5月19日 星期四

Eclipse 3.1 M7 出爐,外加些Memory Options

eclipsepowered ? Blog Archive ? 3.1M7 memory options
Eclipse 3.1 M7出了,速度比M6快了不少。還有些特別的Memory Options,可以讓IDE定期在Idle的時候去gc一下。