2009年8月14日
從上班開(kāi)始沒(méi)多久,就開(kāi)始用Evernote,是portable 2.2版本。
好記性不如爛筆頭。真的是做到了隨手記,尤其是搜索功能簡(jiǎn)單易用,用來(lái)挖很久以前記下的tips,界面也很簡(jiǎn)潔,明了、夠用。
備份也方便,反正換了電腦,文件夾直接拷貝,數(shù)據(jù)沒(méi)丟。
就這樣,一用多少年過(guò)去了。
如今,“印象筆記”在iphone應(yīng)用推薦榜的筆記類里一直居高位,圖標(biāo)也早就不是我v2.2的老土模樣,如果不是英文名字就叫evernote,我完全對(duì)不上號(hào)。
人家其實(shí)從v3開(kāi)始就不是老土的本地應(yīng)用了,都講究“云”了。
雖然手頭的v2.2完全滿足我隨手記一記的需求,但是,本著與時(shí)俱進(jìn)和稍微保證一下數(shù)據(jù)的安全性,我還是下了個(gè)最近的v4.x的版本,結(jié)果發(fā)現(xiàn)還是要從v3開(kāi)始才能導(dǎo)入v2的數(shù)據(jù)。嗯,看來(lái)是落后太久了。
有一點(diǎn)夸獎(jiǎng)一下:免費(fèi)賬戶的每月上傳容量是有限的,但是對(duì)于我這種文本筆記,夠傳3w條的。
——嗯,其實(shí),本來(lái)只是個(gè)小軟件的更新而已,竟然跑到blogjava寫(xiě)上一篇,可能是因?yàn)榘殡S感吧,再有點(diǎn)兒時(shí)過(guò)境遷的唏噓。
春節(jié)過(guò)后這幾天干的活兒就沒(méi)一件痛痛快快的?
第一天是發(fā)現(xiàn)編譯環(huán)境有異動(dòng),我以為是代碼有問(wèn)題,折騰了1天多。。。
第二天是自己機(jī)器上的IE8抽瘋弄得我以為是build有問(wèn)題。。。
第三天從TimesTen轉(zhuǎn)到Psql的各種毛病。。。
好吧。言歸正傳:
1)找一個(gè)跟表無(wú)關(guān)的通用的單純的select語(yǔ)句作為測(cè)試語(yǔ)句不容易啊,
Dual是Oracle自帶的表,其他DBS木有的。。不用Dual的話Oracle又不認(rèn)。
2)Cause: org.postgresql.util.PSQLException: Method org.postgresql.jdbc2.Jdbc2PreparedStatement.setQueryTimeout(int) is not yet implemented.
這個(gè)錯(cuò)誤,把sqlMapConfig.xml中在settings里配置的defaultStatementTimeout去掉就可以避免了。但是,這個(gè)配置對(duì)PSQL應(yīng)該OK啊。。。待查
【續(xù)】——
defaultStatementTimeout 確實(shí)不是所有的driver都支持的。
但去掉的話,TimesTen又不干了:太囧了。。。
[TimesTen][TimesTen 7.0.5.9.0 CLIENT]Query Timeout must be numeric; if the Network Timeout
is non-zero, the Query Timeout must be greater than zero and less than the Network Timeout, else if the Network Timeout is zero, the Query Timeout must be greater than or equal to zero.
兜兜轉(zhuǎn)轉(zhuǎn)又遇到了這個(gè)之前遇到過(guò)的問(wèn)題。這些driver就不能統(tǒng)一統(tǒng)一咩!
parseInt(String s, int radix)
Parses the string argument as a signed integer in the radix specified by the second argument.
今兒頭回用,真是……反省ing
文檔寫(xiě)到現(xiàn)在,猛然說(shuō)不上
abbreviation 和 acronym 的區(qū)別。。。真是慚愧。。。
abbreviation:?jiǎn)卧~、語(yǔ)句的縮略形式,縮到短一點(diǎn)兒。
acronym:“首字母”縮寫(xiě)
之前都沒(méi)注意過(guò)有這么個(gè)方法,否則判斷日期格式就太不靠譜了。
又是晦澀的單詞:setLenient(false),嚴(yán)格匹配日期格式
SimpleDateFormat df = new SimpleDateFormat("MMddyyyy");
/*
* With lenient parsing, the parser may use heuristics to interpret inputs that
* do not precisely match this object's format.
* With strict parsing, inputs must match this object's format.
*/
df.setLenient(false);
try {
Date a = df.parse("23232011");
System.out.print("date: " + a);
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i18n,之前在J2EE里,自然用struts來(lái)做。但是Web Service里貌似應(yīng)該不需要這部分,但是實(shí)際上,有些操作還是避免不了要支持多國(guó)語(yǔ)言。
查了一圈兒,好像WS-i18n還在working draft的階段,而且好像已經(jīng)好幾年了……也沒(méi)找到什么開(kāi)源中間件的實(shí)現(xiàn)。
大意是在SOAP header中加上<i18n:international>相關(guān)的標(biāo)簽。
因?yàn)楫吘故荳eb Service,利用http header還是不太妥,還是要放在SOAP里面。
記錄一下查到的鏈接,備用。
For a SOAP web service the language/country code should be part of the SOAP request and possibly the SOAP response. You can always base your solution on the above WS-I18N working draft.
Internationalization isn't as big a priority with SOAP web services as it is with web pages as web services are consumed by other applications - not humans. In most cases normalized "generic data" is exchanged which is displayed on the client using the client's locale. SOAP web services exchanging localized text are pretty much in the minority.
這回是更加深深地體會(huì)到IDE的重要性了!
想當(dāng)初要不是eclipse,估計(jì)上手過(guò)程會(huì)很痛苦;
后來(lái)myeclipse的官方網(wǎng)站竟然封掉了;
現(xiàn)在,眼巴巴瞅著NetBeans美麗的GUI Builder,假如當(dāng)年Swing那部分是用NetBeans開(kāi)發(fā)的,或者NetBeans可以不要那個(gè).form的文件直接解析代碼,就好了啊!!!
唉……
繁瑣的登陸過(guò)程讓人抓狂,telnet到第一臺(tái)機(jī)器輸入用戶名之前,點(diǎn)擊SecureCRT里menu->Script->Start recording script,錄下接下來(lái)的步驟,然后點(diǎn)擊Stop recording script,就會(huì)提示保存腳本。以后登陸時(shí),選擇Run腳本就可以了。
引子只是個(gè)小問(wèn)題,JTextArea多行文本,想設(shè)置文字的對(duì)齊方式為居中對(duì)齊,卻發(fā)現(xiàn)死活沒(méi)有合適有效的方法,又試了JTextField和JLabel,都不理想。搜了一溜夠看到JTextPane的解決方法,其實(shí)真是有點(diǎn)兒大材小用了。JTextPane里可以設(shè)置style,對(duì)齊方式、字體字號(hào)、顏色等等,并且還可以設(shè)置style的作用范圍,挺方便的。另外,想把文字區(qū)域背景設(shè)為透明的也是在API中找了一通,才發(fā)現(xiàn)敢情就是setOpacity,呃,對(duì)這個(gè)單詞實(shí)在是太不敏感了。。。。
把在coderanch上搜的例子貼在這里吧,以防以后忘了:
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class Styling


{
public Styling()

{
String text = "To refer to locations within the sequence, the " +
"coordinates used are the location between two " +
"characters.\nAs the diagram below shows, a location " +
"in a text document can be referred to as a position, " +
"or an offset. This position is zero-based.";
SimpleAttributeSet aSet = new SimpleAttributeSet();
StyleConstants.setForeground(aSet, Color.blue);
StyleConstants.setBackground(aSet, Color.orange);
StyleConstants.setFontFamily(aSet, "lucida bright italic");
StyleConstants.setFontSize(aSet, 18);
SimpleAttributeSet bSet = new SimpleAttributeSet();
StyleConstants.setAlignment(bSet, StyleConstants.ALIGN_CENTER);
StyleConstants.setUnderline(bSet, true);
StyleConstants.setFontFamily(bSet, "lucida typewriter bold");
StyleConstants.setFontSize(bSet, 24);
JTextPane textPane = new JTextPane();
textPane.setText(text);
StyledDocument doc = textPane.getStyledDocument();
doc.setCharacterAttributes(105, doc.getLength()-105, aSet, false);
doc.setParagraphAttributes(0, 104, bSet, false);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new JScrollPane(textPane));
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
public static void main(String[] args)

{
new Styling();
}
}
之前用axis2生成代碼的時(shí)候都沒(méi)有在意過(guò),一路用default configuration下來(lái)。
前一陣子發(fā)現(xiàn)以前的代碼在生成時(shí)選擇的data binding不是用默認(rèn)的adb方式,而是用xmlbeans。
google了一番不同數(shù)據(jù)綁定的區(qū)別,好像也沒(méi)什么結(jié)果,大意就是adb的最簡(jiǎn)單,但是有局限性;xmlbeans支持的比較全面,但是用起來(lái)有點(diǎn)兒復(fù)雜。不過(guò),我也沒(méi)有體會(huì)出來(lái)xmlbeans強(qiáng)大在哪里……只是知道生成的代碼更多了,調(diào)用起來(lái)更繞彎子而已。。。
server端用xmlbeans生成,client端用adb生成,互通是沒(méi)有問(wèn)題的。
client端用xmlbeans生成時(shí),需要把產(chǎn)生于resources里面的所有.class文件打成jar包加到client端的build path里,否則運(yùn)行client加載類的時(shí)候就會(huì)報(bào)錯(cuò)了,好詭異,太不友好了。
類似這種錯(cuò)誤:
ClassNotFoundException : Cannot load SchemaTypeSystem. Unable to load class with name schemaorg_apache_xmlbeans.system.s68C41DB812F52C975439BA10FE4FEE54.TypeSystemHolder. Make sure the generated binary files are on the classpath.
所幸是在官方網(wǎng)站上有說(shuō)明:http://ws.apache.org/axis2/tools/1_2/CodegenToolReference.html
一個(gè)JNLP文件中的資源必須由同一個(gè)證書(shū)簽名
當(dāng)需要不同證書(shū)時(shí),可以創(chuàng)建多個(gè)JNLP文件,并在主JNLP文件中引用之。
遇到過(guò)的問(wèn)題:找不到子JNLP文件中的資源
解決方法:竟然把子JNLP文件放到比主JNLP文件所在目錄低一級(jí)就可以了?!
JLabel.setText("<html>auto new line</html>");
JLabel.setText("<html>line<br>force new line</html>");
費(fèi)了半天勁,敢情Firefox在3.0版本后又支持彈出modal window啦
window.showModalDialog
HttpClient.getHttpConnectionManager().getParams().setSoTimeout()
HttpClient.getHttpConnectionManager().getParams().setConnectionTimeout()
第一個(gè)針對(duì)連接建立后,但是沒(méi)有收到response的超時(shí)時(shí)間,測(cè)試時(shí)可將server simulator收到request后等一段時(shí)間后再回response。
出錯(cuò)信息:
java.net.SocketTimeoutException: Read timed out
第二個(gè)針對(duì)連接建立的超時(shí)時(shí)間,測(cè)試時(shí)可將目的IP地址設(shè)為不存在的IP地址。
出錯(cuò)信息:
org.apache.commons.httpclient.ConnectTimeoutException: The host did not accept the connection within timeout of 8000 ms
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:154)
默認(rèn)值為0,如果不設(shè)置的話大概2分多鐘才會(huì)得到異常
導(dǎo)入了某證書(shū)至truststore,建立SSL連接時(shí)遇到錯(cuò)誤
javax.net.ssl.SSLKeyException: RSA premaster secret error
Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
在windows上雙擊查看該證書(shū)時(shí)發(fā)現(xiàn)Public Key是4096bit,查了一番后發(fā)現(xiàn)Java默認(rèn)好像不能處理這么長(zhǎng)的key,必須要按照J(rèn)CE的一個(gè)Unlimited Strength Jurisdiction Policy
http://java.sun.com/javase/downloads/index_jdk5.jsp里面就有下載,這樣貌似就可以處理這種強(qiáng)度比較高的了。
打印數(shù)組的方法,小地方,卻老忘記,來(lái)自FindBugs的提示:
The code invokes toString on an array, which will generate a fairly useless
result such as [C@16f0472. Consider using Arrays.toString to convert the array
into a readable String that gives the contents of the array.
Arrays提供一系列接收不同類型數(shù)組作為參數(shù)的toString方法
String[] array = new String[]{"a","b","c"};
System.out.println(Arrays.toString(array));
FindBugs,
http://findbugs.sourceforge.net/
發(fā)現(xiàn)代碼中潛在bug的工具,有eclipse的插件,安裝后右鍵單擊java project name,點(diǎn)擊Find Bugs,切換到FindBugs得perspective可以看到結(jié)果,速度還比較快,比之前用過(guò)的一個(gè)(雖然已經(jīng)記不得名字了)快一些~具體的效果還是要逐個(gè)分析。
Bug categories:
- Correctness bug
- Probable bug - an apparent coding mistake
resulting in code that was probably not what the
developer intended. We strive for a low false positive rate.
- Bad Practice
-
Violations of recommended and essential
coding practice. Examples include hash code and equals
problems, cloneable idiom, dropped exceptions,
serializable problems, and misuse of finalize.
We strive to make this analysis accurate,
although some groups may
not care about some of the bad practices.
- Dodgy
-
Code that is confusing, anomalous, or
written in a way that leads itself to errors.
Examples include dead local stores, switch fall through,
unconfirmed casts, and redundant null check of value
known to be null.
More false positives accepted.
In previous versions of FindBugs, this category was known as Style.
Multithreaded correctness
Incorrect lazy initialization and update of static field
Calls Thread.sleep() with a lock held: better to use wait(lock)
Synchronization on interned String could deadlock: 最好不用字符串,以免重復(fù)
Performance
invokes inefficient new String() constructor
concatenates strings using + in a loop: better to use append StringBuffer
inner class usage