<?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/"
				  >
<channel>
<title><![CDATA[Saturn's Weblog - 分类：J2EE]]></title>
<link>http://www.cnsaturn.com/category/J2EE</link>
<description><![CDATA[J2EE]]></description>
<language>zh-CN</language>
<pubDate>Sat, 31 Jul 2010 16:54:57 -0400</pubDate>
<item>
<title><![CDATA[卫报的网站技术架构]]></title>
<link>http://www.cnsaturn.com/posts/website-architecture-of-guardian</link>
<pubDate>Mon, 31 Aug 2009 11:21:00 -0400</pubDate>
<description><![CDATA[<p>
 这是<a href="http://www.infoq.com/presentations/evolving-architecture-guardian-uk">QCon 2009伦敦站</a>，由英国卫报的首席系统架构师<strong><a href="http://www.infoq.com/author/Mathew-Wall">Mathew Wall</a></strong>带来的演讲，非常具有借鉴和学习意义。</p>
<p>
 卫报的R2架构是一个典型的J2EE敏捷开发的实际应用，也是一个企业级的网站从旧的系统（卫报R1）移植到新的系统（R2）的典型实战。</p>
<p>
 R2的初步应用架构：</p>
<p style="text-align: center;">
 <img alt="" src="http://www.cnSaturn.com/uploads/app.jpg" /></p>
<p>
 可以看到，这是一个典型标准的J2EE敏捷开发架构：</p>
<p>
 1、采用原生Spring MVC作为Web Tier；</p>
<p>
 2、使用Velocity 1.5做模板引擎；</p>
<p>
 3、使用Hibernate ORM做持久层。</p>
<p>
 4、建立实体Domain Model和其对应的Repository。</p>
<p>
 6、使用<a href="http://ehcache.org/documentation/getting_started.html">Ehcache</a>配合Hibernate进行缓存</p>
<p>
 除架构值得学习之外，Mathew还介绍了他们的一些新老系统移植经验，比如，在移植过程中为何首先卫报的Travel频道作为测试对象，以及在这过程中碰到的问题和解决方案。</p>
<p>
 非常值得一看的视频：http://www.infoq.com/presentations/evolving-architecture-guardian-uk</p>]]></description>
<author><![CDATA[Saturn]]></author>
<guid isPermaLink="true" >http://www.cnsaturn.com/posts/website-architecture-of-guardian</guid>
</item>
<item>
<title><![CDATA[Java中的冒泡排序算法]]></title>
<link>http://www.cnsaturn.com/posts/bubble-sort-in-java</link>
<pubDate>Sat, 23 May 2009 23:15:00 -0400</pubDate>
<description><![CDATA[<p>
 在Java里面有内建的排序函数，比如要对一列字符数组进行排序，可以使用如下方法：</p>
<pre class="brush:java;">
double[] lengths = {120.0, 0.5, 0.0, 999.0, 77.3};
Arrays.sort(lengths);
System.out.println(Arrays.toString(lengths));</pre>
<p>
 当然，我们可以用最原始的排序方法，比如冒泡法来对数组列进行排序，如下：</p>
<pre class="brush:java;">
Integer[] arrIds = {12,24,1,2345,24,10};

int len = arrIds.length;

int temp;

if(len&gt;0){
    for(int i = 0;i&lt;len;i++){
  for(int j=len-1;j&gt;=i;j--){
      if(arrIds[j]&gt;arrIds[i]){
    temp = arrIds[i];
    arrIds[i] = arrIds[j];
    arrIds[j] = temp;
   }
  }
 }
}

for(int i=0;i&lt;len;i++){
    System.out.println(arrIds[i]);
}</pre>
<p>
 可以将以上算法简单的封装成方法，在实际中应用。</p>]]></description>
<author><![CDATA[Saturn]]></author>
<guid isPermaLink="true" >http://www.cnsaturn.com/posts/bubble-sort-in-java</guid>
</item>
<item>
<title><![CDATA[JAVA实现向上取整、Unix时间戳到普通日期转换等函数]]></title>
<link>http://www.cnsaturn.com/posts/java_ceil_unix_timestamp_to_normal_datetime_convert</link>
<pubDate>Sat, 25 Apr 2009 13:00:00 -0400</pubDate>
<description><![CDATA[<p>
 最近正在做的一个项目使用Java在同一个客户端中Consume多个REST类型的WebService，包括<a href="http://developer.yahoo.com/search/web/V1/webSearch.html" title="Yahoo V1 search API">Yahoo! Search API</a>, <a href="http://code.google.com/intl/zh-CN/apis/youtube/overview.html" title="YouTube API">YouTube Video API</a>和<a href="http://www.flickr.com/services/api/" target="_blank" title="Flickr API">Flickr</a>。</p>
<p>
 我这里想说的不是如何使用Java来调用这几个知名的WebService，而是我个人在客户端制作过程中编写的几个简单实用的函数。关于Java调用WebService的具体方法和方案，我会在稍后的系列日志中详细说明。</p>
<p>
 <strong>说明：</strong>由于我本人也是正式接触Java不久，如果以下函数有不妥的地方，请告诉我。</p>
<p>
 <strong>1、Java中的向上取整：</strong></p>
<p>
 我们知道，在PHP中如果要对一个浮点数进行向上取整操作，只需要使用PHP的内置函数ceil即可。</p>
<p>
 比如，要将1/3向上取整为1，只需要如下操作：</p>
<pre class="brush:php;">
echo ceil(1/3);</pre>
<p>
 那么在Java中，我们也可以编写一个小函数来实现上面的功能：</p>
<pre class="brush:java;">
public int ceil(int a, int b){
    return(((double)a/(double)b)&gt;(a/b)?a/b+1:a/b);
}</pre>
<p>
 <strong>2、Java中将Unix时间戳字符串转换成普通日期格式。</strong></p>
<pre class="brush:java;">
//Convert Unix timestamp to normal date style
private String TimeStamp2Date(String timestampString){
  Long timestamp = Long.parseLong(timestampString)*1000;
  String date = new java.text.SimpleDateFormat(&quot;dd/MM/yyyy hh:mm:ss&quot;).format(new java.util.Date(timestamp));
  return date;
}</pre>
<p>
 在调用Yahoo! News Search的WebService中，当我们提交了一个REST请求之后，假定Yahoo服务器回传给我们一个XML格式文档（假定是因为REST可以以多种格式回传数据流，比如JSON和CSV），此时每条新闻的日期均采用Unix时间戳来显示。在实际运用中，我们需要将它们转换成人们可以理解的正常格式。这就用到了下面我写的这个简单函数。</p>
<p>
 FAQ：什么是Unix时间戳？</p>
<p>
 <span style="color: rgb(204, 0, 51);">Unix时间戳</span>（英文为Unix epoch, Unix time, POSIX time 或Unix timestamp）是从1970年1月1日（UTC/GMT的午夜）开始所经过的秒数，不考虑闰秒。</p>]]></description>
