<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MoDoFo.println(" &#187; Java</title>
	<atom:link href="http://zhangv.com/archives/tag/java/feed" rel="self" type="application/rss+xml" />
	<link>http://zhangv.com</link>
	<description>Life for Idea - forever young</description>
	<lastBuildDate>Sat, 07 Apr 2012 04:08:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>java程序员的集合使用误区</title>
		<link>http://zhangv.com/archives/1689</link>
		<comments>http://zhangv.com/archives/1689#comments</comments>
		<pubDate>Sun, 20 Feb 2011 08:00:15 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/1689</guid>
		<description><![CDATA[
ArrayList用到底, 其他选择 LinkedList, set, treeset,stack 关键是你要解决什么问题
一直以来, 在没有什么特殊情况下, 只要是元素数量不确定, 必然会用ArrayList. 除了增加了变长的特性外, ArrayList本质上就是个数组.
因此在创建ArrayList时应对其中要存储的对象数量有个估计, 否则经常性的扩容操作和remove带来的下标移位操作会影响程序的性能.
如果需要经常性的删除, 可以考虑hashset. 当然hashset不支持随机访问, 只能通过遍历.所以要根据需求来决定.
Linked***和其他集合的区别基本就是底层实现用链表和数组的区别. 链表和数组的区别请自行翻阅课本.


HashMap不指定size
由于HashMap的实现也是基于数组进行散列, 所以同样存在扩容时的性能问题. 所以尽量要指定合理的大小和factor


鄙视(膜拜)数组
最原始意味着最好或最坏, 每个人的看法都不一样. 数组的局限在于它是定长且只能是一种类型(java中).(当然你可以声明Object数组然后放任何东西, 但相信我, 你很少需要这么做)
通过下标访问数组元素是最快的
如果是频繁的数据访问, 计算(比如位图处理). 建议还是用数组, 最简单最纯粹也最高效.


随意使用concurrent
当发现HashMap存在多线程修改的情况时, 会立刻Map m = Collections.synchronizedMap(new HashMap(...));
实际上很多时候应该在集合操作以外保证并发的情况, 当然这里再加上一道也更稳妥,但能不用就不用
小心集合类的垃圾回收陷阱
集合对象如果没有设置为null的时候, 其中所有的对象即便设置为null都是无法被回收的, 因为集合仍然有该对象的引用.
所以当使用集合对象时 要记得集合中对象的生命周期, 以免造成泄漏.

参考: 
深入Java集合学习系列：ArrayList的实现原理-http://zhangshixi.javaeye.com/blog/674856
深入Java集合学习系列：LinkedHashMap的实现原理-http://zhangshixi.javaeye.com/blog/673789
深入Java集合学习系列：LinkedHashSet的实现原理-http://zhangshixi.javaeye.com/blog/673319
深入Java集合学习系列：HashSet的实现原理-http://zhangshixi.javaeye.com/blog/673143
深入Java集合学习系列：HashMap的实现原理-http://zhangshixi.javaeye.com/blog/672697


	Tags: Java
]]></description>
			<content:encoded><![CDATA[<div><span style="font-family: 微软雅黑; font-size: small;"></p>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><strong>ArrayList用到底, 其他选择 LinkedList, set, treeset,stack 关键是你要解决什么问题</strong></span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">一直以来, 在没有什么特殊情况下, 只要是元素数量不确定, 必然会用ArrayList. 除了增加了变长的特性外, ArrayList本质上就是个数组.</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">因此在创建ArrayList时应对其中要存储的对象数量有个估计, 否则经常性的扩容操作和remove带来的下标移位操作会影响程序的性能.</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">如果需要经常性的删除, 可以考虑hashset. 当然hashset不支持随机访问, 只能通过遍历.所以要根据需求来决定.</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">Linked***和其他集合的区别基本就是底层实现用链表和数组的区别. 链表和数组的区别请自行翻阅课本.</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><br />
</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><strong>HashMap不指定size</strong></span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">由于HashMap的实现也是基于数组进行散列, 所以同样存在扩容时的性能问题. 所以尽量要指定合理的大小和factor</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><br />
</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><strong>鄙视(膜拜)数组</strong></span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">最原始意味着最好或最坏, 每个人的看法都不一样. 数组的局限在于它是定长且只能是一种类型(java中).(当然你可以声明Object数组然后放任何东西, 但相信我, 你很少需要这么做)</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">通过下标访问数组元素是最快的</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">如果是频繁的数据访问, 计算(比如位图处理). 建议还是用数组, 最简单最纯粹也最高效.</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><br />
</span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><strong>随意使用concurrent</strong></span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">当发现HashMap存在多线程修改的情况时, 会立刻<span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; line-height: 18px;"><span style="color: black;">Map m = Collections.synchronizedMap(</span></span><span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; line-height: 18px;"><span style="color: #7f0055; font-weight: bold;">new</span></span><span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; line-height: 18px;"><span style="color: black;"> HashMap(...));</span></span></span></div>
<div><span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; line-height: 18px;"><span style="color: black;">实际上很多时候应该在集合操作以外保证并发的情况, 当然这里再加上一道也更稳妥,但能不用就不用</span></span></div>
<div><strong>小心集合类的垃圾回收陷阱</strong></div>
<div>集合对象如果没有设置为null的时候, 其中所有的对象即便设置为null都是无法被回收的, 因为集合仍然有该对象的引用.</div>
<div>所以当使用集合对象时 要记得集合中对象的生命周期, 以免造成泄漏.</div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><br />
参考: </span></div>
<div><span style="border-collapse: separate; color: #000000; font-family: 微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">深入Java集合学习系列：ArrayList的实现原理-http://zhangshixi.javaeye.com/blog/674856<br />
深入Java集合学习系列：LinkedHashMap的实现原理-http://zhangshixi.javaeye.com/blog/673789<br />
深入Java集合学习系列：LinkedHashSet的实现原理-http://zhangshixi.javaeye.com/blog/673319<br />
深入Java集合学习系列：HashSet的实现原理-http://zhangshixi.javaeye.com/blog/673143<br />
深入Java集合学习系列：HashMap的实现原理-http://zhangshixi.javaeye.com/blog/672697</span></div>
<p></span></div>

	Tags: <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1689/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何javame调用goo.gl短网址服务</title>
		<link>http://zhangv.com/archives/1627</link>
		<comments>http://zhangv.com/archives/1627#comments</comments>
		<pubDate>Thu, 25 Nov 2010 18:19:19 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[goo.gl]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javame]]></category>

		<guid isPermaLink="false">http://zhangv.com/?p=1627</guid>
		<description><![CDATA[直接上代码:
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import org.json.me.JSONObject;
public class GooglUtils {
private static String GOOGL_API_ENDPOINT="http://goo.gl/api/shorten?security_token=null&#38;url=";
public static String shorten(String url) throws Exception{
HttpConnection con = null;
InputStream in = null;
OutputStream out = null;
ByteArrayOutputStream bos = null;
OutputStreamWriter osw = null;
InputStreamReader isr = null;
byte[] request;
int messageLength;
try {
bos = new ByteArrayOutputStream();
osw = new OutputStreamWriter(bos, "UTF-8");
//            osw.write(url);
osw.flush();
request = bos.toByteArray();
messageLength [...]]]></description>
			<content:encoded><![CDATA[<p>直接上代码:</p>
<p>import java.io.ByteArrayOutputStream;<br />
import java.io.IOException;<br />
import java.io.InputStream;<br />
import java.io.InputStreamReader;<br />
import java.io.OutputStream;<br />
import java.io.OutputStreamWriter;</p>
<p>import javax.microedition.io.Connector;<br />
import javax.microedition.io.HttpConnection;</p>
<p>import org.json.me.JSONObject;</p>
<p>public class GooglUtils {<br />
private static String GOOGL_API_ENDPOINT="http://goo.gl/api/shorten?security_token=null&amp;url=";<br />
public static String shorten(String url) throws Exception{<br />
HttpConnection con = null;<br />
InputStream in = null;<br />
OutputStream out = null;<br />
ByteArrayOutputStream bos = null;<br />
OutputStreamWriter osw = null;<br />
InputStreamReader isr = null;<br />
byte[] request;<br />
int messageLength;</p>
<p>try {<br />
bos = new ByteArrayOutputStream();<br />
osw = new OutputStreamWriter(bos, "UTF-8");<br />
//            osw.write(url);<br />
osw.flush();</p>
<p>request = bos.toByteArray();<br />
messageLength = request.length;</p>
<p>con = (HttpConnection) Connector.open(GOOGL_API_ENDPOINT+url, Connector.READ_WRITE);<br />
con.setRequestMethod(HttpConnection.POST);<br />
con.setRequestProperty("Content-Length", Integer<br />
.toString(messageLength));<br />
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");<br />
out = con.openOutputStream();<br />
out.write(request);<br />
in = con.openInputStream();<br />
isr = new InputStreamReader(in,"UTF-8");</p>
<p>char[] buf = new char[256];<br />
int rsize = 0;<br />
StringBuffer sb = new StringBuffer();<br />
while((rsize=isr.read(buf))&gt;0){<br />
sb.append(buf,0,rsize);<br />
}<br />
System.out.println(sb.toString());</p>
<p>JSONObject jo = new JSONObject(sb.toString());<br />
String shorturl = (String) jo.get("short_url");<br />
System.out.println(shorturl);<br />
return shorturl;</p>
<p>} catch (Exception x) {<br />
throw x;<br />
} finally {<br />
try {<br />
if (con != null)<br />
con.close();<br />
if (in != null)<br />
in.close();<br />
if (out != null)<br />
out.close();<br />
} catch (IOException ioe) {<br />
ioe.printStackTrace();<br />
}<br />
}<br />
}<br />
}</p>

	Tags: <a href="http://zhangv.com/archives/tag/goo-gl" title="goo.gl" rel="tag">goo.gl</a>, <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/javame" title="javame" rel="tag">javame</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1627/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jdepend分析研究</title>
		<link>http://zhangv.com/archives/1429</link>
		<comments>http://zhangv.com/archives/1429#comments</comments>
		<pubDate>Sun, 31 Jan 2010 11:33:52 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jdepend]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/1429</guid>
		<description><![CDATA[jdepend使用起来还是比较容易的,但是report分析,以及背后的一些事情还是要弄明白的.否则report就真的成了只是report而没有任何实际价值.
使用jdepend的目的
分析包的依赖情况是否满足面向对象的依赖原则.其实面向对象,设计模式变出那么多花样最后无非就是要解决依赖的问题.但很多情况下,我们用了技巧却忘了为什么用,最后便的为了技巧而技巧,为了设计而设计,而忽略了最终目的.
也许这种感觉只有在深刻的体会过"混乱"之后才能理解吧.
如何分析jdepend的report
Abstractness - 抽象度,该包中抽象类所占的比例
Afferent coupling(Ca) - 被依赖度,有的翻译成传入耦合.我觉得传入耦合不是很清楚,很容易让人理解反了.指依赖该包的其他包的总数. 这个值越高说明他应该要么是公用包,要么是抽象(接口)包
Efferent coupling(Ce) - 依从度,有的翻译是传出耦合.指该包依赖于其他包的个数.通常越高表明依赖其他包越严重,如果这个包不是实现包,并不意味着ce就越大越好.依从度应该在一个合理的范围.同时依从的包应该是stable的.
Instability(I) - 不稳定性.公式 ce/(ce+ca).即依从度在所有依赖中的比例.还比较好理解,如果是完全抽象包(ca=N,ce=0),I=0,如果是完全具体实现包(ca=0,ce=N),I=1.
Distance - 指该包和理想情况的最大差距.这个有点绕.举个例子,如果一个包的A=1,也就是完全抽象的.那么他的I应该是=0的,但如果不是(也即是他还要依赖其他更抽象的包).那么distance=Instability-0(理想值).而如果一个包的A=0,即该包完全是实现,那么他的I应该是1,那么distance = 1(理想值)-Instability
而如果0&#60;A&#60;1,那么就不知道他的I的理想值是什么了.这个时候理想值应该是A,distance=&#124;A+I-1&#124;.
参考资料1


	Tags: Java, jdepend
]]></description>
			<content:encoded><![CDATA[<p>jdepend使用起来还是比较容易的,但是report分析,以及背后的一些事情还是要弄明白的.否则report就真的成了只是report而没有任何实际价值.</p>
<p><strong>使用jdepend的目的</strong><br />
分析包的依赖情况是否满足面向对象的依赖原则.其实面向对象,设计模式变出那么多花样最后无非就是要解决依赖的问题.但很多情况下,我们用了技巧却忘了为什么用,最后便的为了技巧而技巧,为了设计而设计,而忽略了最终目的.<br />
也许这种感觉只有在深刻的体会过"混乱"之后才能理解吧.</p>
<p><strong>如何分析jdepend的report</strong></p>
<p>Abstractness - 抽象度,该包中抽象类所占的比例</p>
<p>Afferent coupling(Ca) - 被依赖度,有的翻译成传入耦合.我觉得传入耦合不是很清楚,很容易让人理解反了.指依赖该包的其他包的总数. 这个值越高说明他应该要么是公用包,要么是抽象(接口)包<br />
Efferent coupling(Ce) - 依从度,有的翻译是传出耦合.指该包依赖于其他包的个数.通常越高表明依赖其他包越严重,如果这个包不是实现包,并不意味着ce就越大越好.依从度应该在一个合理的范围.同时依从的包应该是stable的.</p>
<p>Instability(I) - 不稳定性.公式 ce/(ce+ca).即依从度在所有依赖中的比例.还比较好理解,如果是完全抽象包(ca=N,ce=0),I=0,如果是完全具体实现包(ca=0,ce=N),I=1.</p>
<p>Distance - 指该包和理想情况的最大差距.这个有点绕.举个例子,如果一个包的A=1,也就是完全抽象的.那么他的I应该是=0的,但如果不是(也即是他还要依赖其他更抽象的包).那么distance=Instability-0(理想值).而如果一个包的A=0,即该包完全是实现,那么他的I应该是1,那么distance = 1(理想值)-Instability<br />
而如果0&lt;A&lt;1,那么就不知道他的I的理想值是什么了.这个时候理想值应该是A,distance=|A+I-1|.</p>
<p><a href="http://www.blogjava.net/hengheng123456789/archive/2007/01/30/96675.html">参考资料1</a></p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=6c588998-cdf0-8570-bec8-7011e30c9d27" alt="" /></div>

	Tags: <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/jdepend" title="jdepend" rel="tag">jdepend</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1429/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>java获取昨天的日期</title>
		<link>http://zhangv.com/archives/1288</link>
		<comments>http://zhangv.com/archives/1288#comments</comments>
		<pubDate>Tue, 20 Oct 2009 07:46:49 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[canlendar]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/1288</guid>
		<description><![CDATA[如果不小心还是会栽跟头，看到网上有的人只是roll(Calendar.Date,-1)就了事了。要么就是判断日，月写一大堆。其实最简单的应该是：
GregorianCalendar cal = new GregorianCalendar();if(cal.get(Calendar.MONTH)==0 &#38;&#38; cal.get(Calendar.DAY_OF_YEAR)==1){&#160;&#160;&#160;&#160; cal.roll(Calendar.YEAR, -1);}cal.roll(Calendar.DAY_OF_YEAR, -1);
不知道是不是最简单的


	Tags: canlendar, Java
]]></description>
			<content:encoded><![CDATA[<p>如果不小心还是会栽跟头，看到网上有的人只是roll(Calendar.Date,-1)就了事了。要么就是判断日，月写一大堆。<br />其实最简单的应该是：</p>
<p>GregorianCalendar cal = new GregorianCalendar();<br />if(cal.get(Calendar.MONTH)==0 &amp;&amp; cal.get(Calendar.DAY_OF_YEAR)==1){<br />&nbsp;&nbsp;&nbsp;&nbsp; cal.roll(Calendar.YEAR, -1);<br />}<br />cal.roll(Calendar.DAY_OF_YEAR, -1);</p>
<p>不知道是不是最简单的</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=13c18d2f-5c2d-8bdd-88d1-f243025e2ec5" /></div>

	Tags: <a href="http://zhangv.com/archives/tag/canlendar" title="canlendar" rel="tag">canlendar</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1288/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>对Java技术面试非常有用的几本书</title>
		<link>http://zhangv.com/archives/1188</link>
		<comments>http://zhangv.com/archives/1188#comments</comments>
		<pubDate>Mon, 10 Aug 2009 04:10:33 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[面试]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[书]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/1188</guid>
		<description><![CDATA[Effective Java - 2002年的Jolt大奖，详细讲解了57个平时 不大会深入了解而又非常重要的知识点。作者Joshua Bloch还有一本类似的书 - Java PuzzlersEffective Enterprise Java - Effective Java的姊妹篇，专注于企业级Java应用的各种蹊跷和最佳实践。Bitter Java - 从负面学习，在教训和犯错中成长。作者列举了大量的反模式来挑战我们那些被动接受的先入为主。高质量Java程序设计：2003年的一本书，作者是几个国内的程序员。模仿Effective Java的组织形式，通过35个条款，讲解了一些在实际工作中经常会忽视的问题。SCEA study guide - 考试用书，如果可能遇到面试=笔试的情况，当然还可以把其他的study guide都拿出来看看。各种specification,直接到JCP找相应的JSR：

JSE： New I/O&#160;,Concurrency Utilities, Profiling Architecture,JAXP1.3,JavaTM SE 6 Release Contents,JavaTM Language Specification,JVM
JEE: EJB3.0,JSP2.1,  JavaEE 1.5,Servlet 2.4 Specification,JDBCTM 4.0 ,Servlet 3.0,JavaMail,             [...]]]></description>
			<content:encoded><![CDATA[<p>Effective Java - 2002年的Jolt大奖，详细讲解了57个平时 不大会深入了解而又非常重要的知识点。作者Joshua Bloch还有一本类似的书 - Java Puzzlers<br />Effective Enterprise Java - Effective Java的姊妹篇，专注于企业级Java应用的各种蹊跷和最佳实践。<br />Bitter Java - 从负面学习，在教训和犯错中成长。作者列举了大量的反模式来挑战我们那些被动接受的先入为主。<br />高质量Java程序设计：2003年的一本书，作者是几个国内的程序员。模仿Effective Java的组织形式，通过35个条款，讲解了一些在实际工作中经常会忽视的问题。<br />SCEA study guide - 考试用书，如果可能遇到面试=笔试的情况，当然还可以把其他的study guide都拿出来看看。<br />各种specification,直接到<a target="_blank" href="http://www.jcp.org/en/home/index">JCP</a>找相应的JSR：
<ul>
<li><b>JSE</b>： <a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=51"><b>New I/O&nbsp;</b></a>,<b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=166">Concurrency Utilities</a>,</b> <b><a href="http://www.jcp.org/en/jsr/detail?id=163">Profiling Architecture</a></b>,<b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=206">JAXP1.3</a>,</b><b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=270">Java<sup><font size="-2">TM</font></sup> SE 6 Release Contents</a>,</b><b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=901">Java<sup><font size="-2">TM</font></sup> Language Specification</a>,</b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=924"><b>JVM</b></a></li>
<li><b>JEE: </b><b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=220">EJB3.0</a>,</b><b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=245">JSP2.1</a>,</b> <!-- Gutter //--> <a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=244"><b>JavaEE 1.5</b></a>,<b><a href="http://www.jcp.org/en/jsr/detail?id=154">Servlet 2.4 Specification</a>,</b><b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=221">JDBC<sup><font size="-2">TM</font></sup> 4.0 </a>,</b><b><a href="http://www.jcp.org/en/jsr/detail?id=315">Servlet 3.0</a>,</b><b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=904">JavaMail</a>,</b> <!-- Gutter //-->                            <b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=907">JTA</a>, <a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=317">JPA2.0</a>,<a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=914">JMS</a><br /></b></li>
<li><b>JME: </b><b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=68">J2ME<sup><font size="-2">TM</font></sup> Platform Specification</a>,</b><a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=37"><b>MIDP 2.0</b></a><b>,</b> <!-- Gutter //-->                            <a target="_blank" href="http://www.jcp.org/en/jsr/detail?id=172"><b>J2ME<sup><font size="-2">TM</font></sup> Web Services Specification</b></a></li>
</ul>
<p><!-- Gutter //-->                            针对特定的工具和领域：推荐 in action 系列，比如hibernate in action, spring in action, lucene in action ...</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=593349c7-5d7d-8ae9-89aa-912f2898fb3a" /></div>

	Tags: <a href="http://zhangv.com/archives/tag/%e9%9d%a2%e8%af%95" title="面试" rel="tag">面试</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/tips" title="tips" rel="tag">tips</a>, <a href="http://zhangv.com/archives/tag/%e4%b9%a6" title="书" rel="tag">书</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1188/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>facebook-java-api验证问题</title>
		<link>http://zhangv.com/archives/1093</link>
		<comments>http://zhangv.com/archives/1093#comments</comments>
		<pubDate>Sat, 20 Jun 2009 15:56:28 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[openAPI]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/1093</guid>
		<description><![CDATA[想要用facebook-java-api做一个简单的登录验证并获取用户信息，可是：
用facebook的login页面验证后，居然是自动跳转到app的中定义的callbackUrl（也就是app host的url）。这样就给本地调试带来很大的麻烦，难不成每次做了修改都要发布到host上然后再测试？

	Tags: facebook, Java, openAPI
]]></description>
			<content:encoded><![CDATA[<p>想要用facebook-java-api做一个简单的登录验证并获取用户信息，可是：<br />
用facebook的login页面验证后，居然是自动跳转到app的中定义的callbackUrl（也就是app host的url）。这样就给本地调试带来很大的麻烦，难不成每次做了修改都要发布到host上然后再测试？</p>

	Tags: <a href="http://zhangv.com/archives/tag/facebook" title="facebook" rel="tag">facebook</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/openapi" title="openAPI" rel="tag">openAPI</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1093/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how big should the byte array be in java me(j2me)</title>
		<link>http://zhangv.com/archives/1020</link>
		<comments>http://zhangv.com/archives/1020#comments</comments>
		<pubDate>Wed, 20 May 2009 04:32:07 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JME]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/1020</guid>
		<description><![CDATA[Keep getting the out of memory error when handling the image file in emulator(wtk) and device(e61i)
Just had a simple test and here is what I found:
The code is simple:
for(int i=1000;i&#60;Integer.MAX_VALUE;i++){
System.out.println(i);
byte[] buf = new byte[i];
}
and see when your program will crash. - Actually it won't crash, as the OOME(out of memory error), is an Error rather [...]]]></description>
			<content:encoded><![CDATA[<p>Keep getting the out of memory error when handling the image file in emulator(wtk) and device(e61i)<br />
Just had a simple test and here is what I found:<br />
The code is simple:<br />
for(int i=1000;i&lt;Integer.MAX_VALUE;i++){<br />
System.out.println(i);<br />
byte[] buf = new byte[i];<br />
}<br />
and see when your program will crash. - Actually it won't crash, as the OOME(out of memory error), is an Error rather RuntimeException, when the OOME is thrown, the program just go on.</p>
<p>Let's see the result:<br />
In wtk2.5.2 emulator: the size cannot beyond "2003765" byte(for comparison: we can reserve byte array of size  Integer.MAX_INTEGER/40 - 53687091 in standard version on my laptop).<br />
In e61i: not instrumented yet. My guess is maybe much smaller, as I had experience that OOME thrown when the image size is only 300k, what different is: the byte array CAN take up to that size, however error happened when handling the image(when trying to createImage from byte array).<br />
I followed this <a href="http://discussion.forum.nokia.com/forum/showthread.php?t=98259">thread </a>and the guys found that 400k bytes is the limit on nokia6681.</p>
<p>Another depressing result.</p>

	Tags: <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/jme" title="JME" rel="tag">JME</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1020/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于java6中scripting engine的invoke和invokeFunction的问题</title>
		<link>http://zhangv.com/archives/976</link>
		<comments>http://zhangv.com/archives/976#comments</comments>
		<pubDate>Sun, 10 May 2009 05:42:48 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/976</guid>
		<description><![CDATA[在java6中加入了对scripts的支持（jsr223），并且捆绑了一种javascript的实现（来自mozilla的rhino)。
但是今天在使用时候发现一个小问题，jdk-6u12和jdk-6u13里的Invocable居然是不兼容的！
在jdk-6u12中是
invokeFunction(String name, Object... args)
而jdk-6u13中是
invoke(String name, Object... args)
在网上发现大多数的写法都是前一种(invokeFunction)，搞不清楚为什么会出现这样的问题。但如果这的出现开发环境和部署环境稍有不同岂不是搞的很不爽，明明只是一个很小的问题。却可能造成很奇怪的结果，还要改代码重新编译才行。
解决方法：
1.开发环境和部署环境的jdk版本统一。
2.干脆使用BSF或者BSH。
虽说两种方法和简单直接，但是总觉得因为这么一点点问题而动这么大的干戈真不应该。


	Tags: Java, script
]]></description>
			<content:encoded><![CDATA[<p>在java6中加入了对scripts的支持（<a href="http://www.jcp.org/en/jsr/detail?id=223">jsr223</a>），并且捆绑了一种javascript的实现（来自<a href="http://www.mozilla.org/rhino/">mozilla的rhino</a>)。<br />
但是今天在使用时候发现一个小问题，jdk-6u12和jdk-6u13里的Invocable居然是不兼容的！</p>
<p>在jdk-6u12中是<br />
invokeFunction(String name, Object... args)<br />
而jdk-6u13中是<br />
invoke(String name, Object... args)</p>
<p>在网上发现大多数的写法都是前一种(invokeFunction)，搞不清楚为什么会出现这样的问题。但如果这的出现开发环境和部署环境稍有不同岂不是搞的很不爽，明明只是一个很小的问题。却可能造成很奇怪的结果，还要改代码重新编译才行。</p>
<p>解决方法：<br />
1.开发环境和部署环境的jdk版本统一。<br />
2.干脆使用BSF或者BSH。<br />
虽说两种方法和简单直接，但是总觉得因为这么一点点问题而动这么大的干戈真不应该。</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=4768913c-1435-8b42-abba-e87139db7832" alt="" /></div>

	Tags: <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/script" title="script" rel="tag">script</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/976/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google App Engine Java</title>
		<link>http://zhangv.com/archives/902</link>
		<comments>http://zhangv.com/archives/902#comments</comments>
		<pubDate>Tue, 14 Apr 2009 01:58:32 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[非技术(non-tech)]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/902</guid>
		<description><![CDATA[http://code.google.com/appengine/docs/java/overview.html

	Tags: gae, google, Java
]]></description>
			<content:encoded><![CDATA[<p>http://code.google.com/appengine/docs/java/overview.html</p>

	Tags: <a href="http://zhangv.com/archives/tag/gae" title="gae" rel="tag">gae</a>, <a href="http://zhangv.com/archives/tag/google" title="google" rel="tag">google</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/902/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nokia网站上的资源</title>
		<link>http://zhangv.com/archives/900</link>
		<comments>http://zhangv.com/archives/900#comments</comments>
		<pubDate>Sat, 11 Apr 2009 15:36:42 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JME]]></category>
		<category><![CDATA[nokia]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/900</guid>
		<description><![CDATA[pureMVC http://wiki.forum.nokia.com/index.php/Model-View-Controller_Architecture可以用于jme开发的MVC框架
nokia2008年的CallingAllInnovators比赛的获胜者，其中总冠军是来自中国的，居然一直都没听说过，Grand Prize: X Dancery，看了一下视频，震撼到了!http://www.callingallinnovators.com/previous_winners.aspx
eSWT貌似s60的runtime一直都支持eSWT，怎么没怎么见有人用过呢？可能还是见的太少了。http://wiki.forum.nokia.com/index.php/ESWTeRCP是nokia的开源项目http://www.eclipse.org/ercp &#160;&#160;&#160; * eSWT:&#160;&#160; The embedded Standard Widget Toolkit which is a subset of desktop SWT API. An eSWT implementation for Series 80 has been contributed. The development for s60 platform is in progress.&#160;&#160;&#160; * Core Runtime:&#160;&#160; Eclipse Core which provides OSGI and Extension Point Framework support.&#160;&#160;&#160; * eJFace:&#160;&#160; A set [...]]]></description>
			<content:encoded><![CDATA[<p>pureMVC <br />http://wiki.forum.nokia.com/index.php/Model-View-Controller_Architecture<br />可以用于jme开发的MVC框架</p>
<p>nokia2008年的CallingAllInnovators比赛的获胜者，其中总冠军是来自中国的，居然一直都没听说过，Grand Prize: X Dancery，看了一下视频，震撼到了!<br />http://www.callingallinnovators.com/previous_winners.aspx</p>
<p>eSWT貌似s60的runtime一直都支持eSWT，怎么没怎么见有人用过呢？可能还是见的太少了。<br />http://wiki.forum.nokia.com/index.php/ESWT<br />eRCP是nokia的开源项目http://www.eclipse.org/ercp <br />&nbsp;&nbsp;&nbsp; * eSWT:&nbsp;&nbsp; The embedded Standard Widget Toolkit which is a subset of desktop SWT API. An eSWT implementation for Series 80 has been contributed. The development for s60 platform is in progress.<br />&nbsp;&nbsp;&nbsp; * Core Runtime:&nbsp;&nbsp; Eclipse Core which provides OSGI and Extension Point Framework support.<br />&nbsp;&nbsp;&nbsp; * eJFace:&nbsp;&nbsp; A set of classes which extend eSWT to: enable eRCP applications to integrate with an eRCP workbench, and provide more complex widgets like MVC oriented viewers.<br />&nbsp;&nbsp;&nbsp; * eWorkbench:&nbsp;&nbsp; A UI framework which supports multiple cooperative eRCP applications, and a generic Workbench which manages launching and display of eRCP applications.<br />&nbsp;&nbsp;&nbsp; * eUpdate:&nbsp;&nbsp; A simplified API and interface for dynamically updating device software.</p>
<p>How to use eSWT with Midlets<br />http://wiki.eclipse.org/How_to_use_eSWT_with_Midlets<br />Using eSWT and MMAPI together to take a picture in Java ME<br />http://wiki.forum.nokia.com/index.php/Using_eSWT_and_MMAPI_together_to_take_a_picture_in_Java_ME</p>
<p>Java Runtime 1.4 for S60 Release notes(目前只有N97)<br />http://wiki.forum.nokia.com/index.php/Java_Runtime_1.4_for_S60_Release_notes（支持触摸屏）</p>
<p>Java Runtime 1.3 for S60 Release notes(目前只有5800)<br />http://wiki.forum.nokia.com/index.php/Java_Runtime_1.3_for_S60_Release_notes</p>
<p>Java API Specifications<br />http://www.forum.nokia.com/Resources_and_Information/Documentation/Java/Java_API_Specifications.xhtml</p>
<p>System properties<br />http://wiki.forum.nokia.com/index.php/TSJ000306_-_MIDP:_System_properties</p>
<p>Java ME UI Frameworks<br />http://wiki.forum.nokia.com/index.php/Java_ME_UI_Frameworks</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=98613139-05d2-8258-8bc1-b07c69e3b670" /></div>

	Tags: <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/jme" title="JME" rel="tag">JME</a>, <a href="http://zhangv.com/archives/tag/nokia" title="nokia" rel="tag">nokia</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/900/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

