Groovy and Java
Groovy and Java

posted @ 2009-04-19 10:49 mike zeseler 閱讀(206) | 評論 (0) | 編輯 收藏
張紹林
有時間我把它弄成中文的。
The 7th version of the Java Developer’s Kit (aka JDK 7) delivers quite a speed boost over JDK 6 array accesses. For us, this is huge. It’s like another year and a half of Moore’s law for free. Only in software. And you don’t even have to write multi-threaded code.
I’ve been profiling my new K-Means++ implementation for the next LingPipe release on some randomly generated data. It’s basically a stress test for array gets, array sets, and simple multiply-add arithmetic. Many LingPipe modules are like this at run-time: named entity, part-of-speech tagging, language modeling, LM-based classifiers, and much more.
While I was waiting for a run using JDK 1.6 to finish, I installed the following beta release of JDK 7:
> java -version java version "1.7.0-ea" Java(TM) SE Runtime Environment (build 1.7.0-ea-b52) Java HotSpot(TM) 64-Bit Server VM (build 15.0-b03, mixed mode)
You can get it, too:
I believe much of the reason it’s faster is the work of these fellows:
Java’s always suffered relative to C in straight matrix multiplication because Java does range checks on every array access (set or get). With some clever static and run-time analysis, Würthinger et al. are able to eliminate most of the array bounds checks. They show on matrix benchmarks that this one improvement doubles the speed of the LU matrix factorization benchmark in the U.S. National Institute of Standards (NIST) benchmark suite SciMark 2, which like our clustering algorithm, is basically just a stress test for array access and arithmetic.
So far, my tests have only been on a Thinkpad Z61P notebook running Windows Vista (64 bit) with an Intel Core 2 CPU (T2700; 2.0GHz), and 4GB of reasonably zippy memory. I don’t know if the speedups will be as great for other OSes or for 32-bit JDKs.
I’m pretty excited about the new fork-join concurrency, too, as it’s just what we’ll need to parallelize the inner loops without too much work for us or the operating system.
*Update: 2:30 PM, 30 March 2009 JDK 7 is only about 15% faster than Sun’s JDK 6 on my quad Xeons (E5410, 2.33GHz) at work running the same code. I’ll have to check the exact specs on both of my memory buses. The notebook has surprisingly fast memory and the Xeon’s running ECC registered memory that I don’t think is quite as fast.
Update: 11:00 AM, 31 March 2009 Like other matrix algorithms, k-means clustering is extremely front-side-bus sensitive (connection between memory and the CPU), because the bottleneck is often between memory and the CPU’s L2 cache. Memory’s significantly slower than CPU these days.
The Intel dual quad-core Xeon E5410 have 12MB of L2 cache at 2.3GHz, whereas the Thinkpad Z61P has Intel Core 2 Mobile T7200 has only 4MB of L2 cache at 2GHz. The Core 2 has a 667 MHz front-side bus whereas the Xeon reports a 1333 MHz front-side bus (is that just the confusion between spec reporting). I actually don’t know what kind of memory’s in the workstation — I’ll have to crack it open and look. I’ve got 4GB of RAM in the notebook, but the motherboard can only see 3GB (ithat is, it’s not Windows — the same thing happened when I installed Ubuntu on the notebook and it’s a known design limitation in many motherboards); I have 16GB of RAM in the workstation and the motherboard can see all of it. But it has two physical chips, each of which share the memory, so the motherboard’s architecture’s very different. There are so many confounding factors that I can’t tease apart what’s speeding up in JDK 7 so much on the notebook.
Anway, go forth and test. If you’re using a machine like my notebook to do number crunching, JDK 7 really is twice as fast as JDK 6 for matrix algorithms.
posted @ 2009-04-06 15:03 mike zeseler 閱讀(273) | 評論 (0) | 編輯 收藏
Hibernate入門指南
今天抽咯時間完成咯自己沒有完成的東西。
posted @ 2009-02-13 19:47 mike zeseler 閱讀(620) | 評論 (0) | 編輯 收藏
Groovy就是java世界的動態語言
一:快速開始(gettingStart)
安裝JDK環境
Groovy需要JDK1.4以上版本的支持。因此在安裝groovy時首先要安裝JDK。
JDK安裝步驟:
• 下載自己喜歡的JDK版本。(下載網址:http://java.sun.com)
• 下載Groovy:
Groovy的 下載首頁截圖
點擊Download
進入下載頁面
Groovy最新版本:Groovy 1.6-RC-2
我下載的是:Download Windows-Installer: Binary Release 安裝版本
運行安裝者
設置JAVA_HOME 環境變量. 在Windows平臺里,步驟如下:
(1)打開系統"控制面板"
單擊"高級"選項卡
單擊"環境變量" 按鈕
添加一個名稱為"JAVA_HOME" 的新的系統環境變量,并且將你的Java的安裝目錄作為它的值 (例如,我的是C:"Program Files"Java"jdk1.6.0(版本號))
你也可以添加 %JAVA_HOME%"bin到你的系統的PATH變量中
(2)右擊我的電腦屬性
點擊高級選項
點擊環境變量
點擊新建選項:
具體設置
Path:
我用的Jdk版本是Jdk1.6
• 運行安裝文件。(更改安裝路徑到:C:"Program Files"Java"jdk1.6.0(版本號))
• 設置JAVA_HOME環境變量(如我的
• 在系統path中增加:%JAVA_HOME%"bin
注:對于1.1-rc-1以上版本需要JDK1.5版或更高的版本。
點擊自己下載的Groovy windows安裝版本
安裝可以是默認的安裝全點擊下一步(next):
安裝就完成啦
(Note: as an alternative to setting a system environment variable, you can create yourself a '.bat' or '.cmd' file which sets
the variable. You then need to run that batch file in any console window in which you wish to run Java and double clicking on
.bat' or '.cmd' files containing Java invocation instructions won't work. If you are unsure about what this means, follow
the earlier instructions.)
Note: JDK 1.5 is required for version 1.1-rc-1. In earlier versions of JDK (notably 1.4.2) the compiller throws an exception:
*nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoSuchMethodError:
java.lang.String.replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
The method "replace" was introduced in JDK 1.5 and is not supportedin earlier versions. This is also a reason why GRails
framework doesn't run on JRE 1.4
(1)如果你是安裝版本Groovy環境變量不需要我們設置,在安裝的時候就自動設置好啦。
(2)如果不是,請自己嘗試Groovy設置如下:
設置你的Groovy環境變量
從下載頁面下載Groovy安裝器或者二進制包,并且跟著介紹進行安裝即可。(當前有一個問題,就是在windows下,你的安裝路徑不能含有空格
,即,要將其缺省的安裝路徑"c:"Program Files"Groovy" 改成象"c:"Groovy"這樣的路徑)
或者這樣
從站點上得到Groovy發行版的copy,并且copy它到你硬盤上的某個地方。
解壓縮這個groovy包到你硬盤的某個空間,如我的在 C:"dev"groovy-1.0-jsr-06
設置GROOVY_HOME環境變量. 在Windows下,作如下步驟:
添中新的系統環境變量GROOVY_HOME 并且將值設為你的groovy安裝的路徑( 我的是 C:"dev"groovy-1.0-jsr-06)
打開命令行窗口,并且鍵入"set" 然后打回車,查看你的環境變量設置是否已經正確。
可選的,你也可以添加 %GROOVY_HOME%"bin 到你的PATH環境變量中
通過雙擊試著運行groovyConsole.bat。如果它不能工作,打開一人命令行窗口,將目錄改變到bin目錄,并且運行它看他返回什么錯誤信息。
二:運行groovy
Groovy安裝:目錄
我們需要點擊groovyConsole.bat文件:
文件詳細內容如下:
@if "%DEBUG%" == "" @echo off @rem @rem $Revision: 2770 $ $Date: 2005-08-29 12:49:42 +0200 (Mo, 29. Aug 2005) $ @rem @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal :begin @rem Determine what directory it is in. set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=." "%DIRNAME%"startGroovy.bat" "%DIRNAME%" groovy.ui.Console %* @rem End local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" endlocal |
安裝完整無誤的話 運行groovyConsole.bat就會啟動groovyConsole.exe,出來一個編輯框。
上面的是文本輸入框:根據groovy的語法輸入要顯示的內容:
下面的是內容輸出框:顯示上面的內容:
開始運行groovy:
Hello, World
在 groovyConsole運行窗口的頂部,鍵入println "Hello, World!"
并且鍵入 <CTRL-R>.
注意,在控制臺窗口中(即 groovyConsole窗口前面的黑色的那個),文體得到打印并且 groovyConsole的下部顯示 :
groovy> println "Hello, World!"
null
以"groovy>"開頭的行正是控制臺處理的文本. "null" 是表達式的值. 因為表達式沒有任何值可以打印 ,所以groovyConsole打印為"null"
接下來,再試一些實際的值,用下面的字符串來替換控制臺里的文本:
123+45*67
或者你喜歡的任何表達式然后按<CTRL-R> (I'm going to stop telling you to hit <CTRL-R>, I think you get the idea). 現在, groovyConsole下面打印的值有更多的含義.
Variables
You can assign values to variables for later use. Try the following:x = 1
println x
x = new java.util.Date()
println x
x = -3.1499392
println x
x = false
println x
x = "Hi"
println x
Lists and Maps
The Groovy language has built-in support for two important data types, lists and maps (Lists can be operated as arrays in Java language). Lists are used to store ordered collections of data. For example an integer list of your favorite integers might look like this:myList = [1776, -1, 33, 99, 0, 928734928763]
You can access a given item in the list with square bracket notation (indexes start at 0):
println myList[0]
Should result in this output:
1776
You can get the length of the list with the "size" method:
println myList.size()
Should print out:
6
But generally you shouldn't need the length, because unlike Java, the preferred method to loop over all the elements in an list is to use the "each" method, which is described below in the "Code as Data" section.
Another native data structure is called a map. A map is used to store "associative arrays" or "dictionaries". That is unordered collections of heterogeneous, named data. For example, let's say we wanted to store names with IQ scores we might have:
scores = [ "Brett":100, "Pete":"Did not finish", "Andrew":86.87934 ]
Note that each of the values stored in the map is of a different type. Brett's is an integer, Pete's is a string, and Andrew's is a floating point number. We can access the values in a map in two main ways:
println scores["Pete"]
println scores.Pete
Should produce the output:
Did not finish
Did not finish
To add data to a map, the syntax is similar to adding values to an list. For example, if Pete re-took the IQ test and got a 3, we might:
scores["Pete"] = 3
Then later when we get the value back out, it will be 3.
println scores["Pete"]
should print out 3.
Also as an aside, you can create an empty map or an empty list with the following:
emptyMap = [:]
emptyList = []
To make sure the lists are empty, you can run the following lines:
println emptyMap.size()
println emptyList.size()
Should print a size of 0 for the List and the Map.
條件表達式
One of the most important features of any programming language is the ability to execute different code under different conditions. The simplest way to do this is to use the '''if''' construct. For example:amPM = Calendar.getInstance().get(Calendar.AM_PM)
if (amPM == Calendar.AM)
{
println("Good morning")
} else {
println("Good evening")
}
Don't worry too much about the first line, it's just some code to determine whether it is currently before noon or after. The rest of the code executes as follows: first it evaluates the expression in the parentheses, then depending on whether the result is '''true''' or '''false''' it executes the first or the second code block. See the section below on boolean expressions.
Note that the "else" block is not required, but the "then" block is:
amPM = Calendar.getInstance().get(Calendar.AM_PM)
if (amPM == Calendar.AM)
{
println("Have another cup of coffee.")
}
Boolean表達式
There is a special data type in most programming languages that is used to represent truth values, '''true''' and '''false'''. The simplest boolean expression are simply those words. Boolean values can be stored in variables, just like any other data type:myBooleanVariable = true
A more complex boolean expression uses one of the boolean operators:
==
!=
>
>=
<
<=
Most of those are probably pretty intuitive. The equality operator is '''==''' to distinguish from the assignment operator '''='''. The opposite of equality is the '''!=''' operator, that is "not equal"
So some examples:
titanicBoxOffice = 1234600000
titanicDirector = "James Cameron"
trueLiesBoxOffice = 219000000
trueLiesDirector = "James Cameron"
returnOfTheKingBoxOffice = 752200000
returnOfTheKingDirector = "Peter Jackson"
theTwoTowersBoxOffice = 581200000
theTwoTowersDirector = "PeterJackson"
titanicBoxOffice > returnOfTheKingBoxOffice // evaluates to true
titanicBoxOffice >= returnOfTheKingBoxOffice // evaluates to true
titanicBoxOffice >= titanicBoxOffice // evaulates to true
titanicBoxOffice > titanicBoxOffice // evaulates to false
titanicBoxOffice + trueLiesBoxOffice < returnOfTheKingBoxOffice + theTwoTowersBoxOffice // evaluates to false
titanicDirector > returnOfTheKingDirector // evaluates to false, because "J" is before "P"
titanicDirector < returnOfTheKingDirector // evaluates to true
titanicDirector >= "James Cameron" // evaluates to true
titanicDirector == "James Cameron" // evaluates to true
Boolean expressions are especially useful when used in conjunction with the '''if''' construct. For example:
if (titanicBoxOffice + trueLiesBoxOffice > returnOfTheKingBoxOffice + theTwoTowersBoxOffice)
{
println(titanicDirector + " is a better director than " + returnOfTheKingDirector)
}
An especially useful test is to test whether a variable or expression is null (has no value). For example let's say we want to see whether a given key is in a map:
suvMap = ["Acura MDX":""$36,700", "Ford Explorer":""$26,845"]
if (suvMap["Hummer H3"] != null)
{
println("A Hummer H3 will set you back "+suvMap["Hummer H3"]);
}
Generally null is used to indicate the lack of a value in some location.
Debugging and Troubleshooting Tips
Print out the class of a variable that you're interested in with myVar.getClass(). Then look up the documentation for that class.
If you're having trouble with a complex expression, pare it down to a simpler expression and evaluate that. Then build up to your more complex expression.
Try restarting the groovyConsole (this will clear out all the variables so you can start over.
Look for the topic you're interested in in the Groovy User Guide
If you are a Java developer
you might want to check on the Differences from Java
also there afew a few Things to remember
Labels parameters
posted @ 2009-02-08 12:20 mike zeseler 閱讀(3016) | 評論 (5) | 編輯 收藏
JAX 是德國十分重要的Java技術會議(Java conference),每一年該組織都會召開會議評選最具創新精神的項目,評選委員會從40個提名項目中選擇十個候選項目,許多優秀項目如Matisse GUI builder(NetBeans的一個插件,用于構建GUI程序)、Nuxeo(企業級內容管理解決方案)等都入圍候選,最后Groovy贏得了1等獎!這是一個崇高的榮譽,我們感到非常高興,特別是和許多非常優秀的項目一起競賽。另外該獎項的上一期勝出者是Spring framework。
還有,由Dierk König創作出版的暢銷書------《Groovy in Action》,也會作為獎品贈予Groovy社團,隨后JAX將單獨設置Groovy主題的會議進行頒獎。這些獎項證明并肯定了Groovy的創新價值,并說明Groovy在Java社團有不小的影響力。
http://groovy.codehaus.org
mxjava
http://www.mxjava.com/blog/
posted @ 2009-02-04 16:30 mike zeseler 閱讀(166) | 評論 (0) | 編輯 收藏
1.TheServerside.com 。
2.InfoQ.com Floyd Marinescu 在離開 TSS 后另起爐灶,2006年中最重要推薦。
視野不再局限于Java 而是包括Java,.Net, Ruby ,SOA, Agile方法等熱門話題。
3.JDJ的電子雜志 在JDJ首頁的最底處訂閱,文章質量不低于5-7的傳統三強。
4.SWik.net 收集了大量OpenSource Project的資源聚合。其中如Spring,
Hibernate的更新度非常高,出現什么和Spring有關的blog,article,project都會
馬上被聚合。
5.IBM DeveloperWorks 傳統、穩定的Java文章來源地。
6.JavaWorld 傳統、穩定的Java文章來源地。
7.OnJava 傳統、穩定的Java文章來源地。
8.Artima.com 類似于TSS而略遜,其中Spotlight 文章值得關注,而Java News是
聚合了所有其他Java站點的大聚合。
9.JavaLobby 站內的Announcements 是大大小小Java Project的發布聲明區,
Trips and Tricks 有很多的Tips。
10. No Fluff Just Stuff 的Blogs 聚合 一直缺一個所有優秀Java Blogger的
rss總聚合,NFJS這里勉強算一個。
一個接近于門戶類型的AJAX資源站點,包括Ajax示例收集,博客,論壇和教程等等。
8. DHTML Site
9. Solutoire
10. DevSnippets
2008年國外最佳Web設計/開發技巧、腳本及資源13個可能會讓你說”Thank You”的必不可少的開源應用
20個免費的SEO網站分析工具(已翻譯成中文)
11個功能強大甚至可以替代標準應用程序的Firefox3擴展插件
15個前端開發/網頁設計師必備的Bookmarklet(已翻譯成中文)
30+JavaScript, Ajax & CSS工具提示腳本
40+最熱門的wordpress秘訣和技巧, 30+ More
精選30個優秀的CSS技術和實例(已翻譯成中文)
12種Javascript解決常見瀏覽器兼容問題的方法(已翻譯成中文)
63個必不可少的Wordpress Hack、教程、幫助文件和手冊
20個神奇的Javascipt腳本原型、元素、Widgets、類…
整理及優化CSS代碼的7個原則(已翻譯成中文)
使用CSS為圖片添加更多趣味的5種方法(已翻譯成中文)
10個CSS簡寫技巧讓你永遠受用(已翻譯成中文)
推薦20個關于網站可用性及界面設計的網站(已翻譯成中文)
精選31個網站界面設計實踐教程(已翻譯成中文)
成為Web設計/開發自由職業者所要遵循了53個步(60+資源)
Ajax網頁趨勢研究,什么是最好的免費Ajax資源?(70+最佳Ajax資源)
155個Wordpress資源、教程、插件、主題、Ajax、播客…龐大的WP列表
10個非常棒的Ajax及Javascript實例資源網站(已翻譯成中文)
精選2008年最佳設計素材資源&靈感 (已翻譯成中文)
精選15個國外CSS框架(已翻譯成中文)
推薦20個讓你學習并精通CSS的網站(已翻譯成中文)
65個優秀的jQuery資源(教程、手冊、電子書、demo、插件…)
300+Jquery, CSS, MooTools 和 JS的導航菜單資源(已翻譯成中文)
網頁設計必備的10套漂亮圖標集(已翻譯成中文)
你早晚會用到的130款Wordpress插件-第一部分-第二部分
posted @ 2009-01-30 18:05 mike zeseler 閱讀(400) | 評論 (0) | 編輯 收藏
1、 Huihoo動力—當之無愧的老大 代表人物:龍輝(Allen)、程勇(Peter)、楊泳(Orbat) 代表項目:JFox等 |
|
簡評:說到java開源,大家不可能不知道Huihoo,Huihoo曾經創造了很多奇跡,不管是對是團隊成員的技術水平還是開源理念、開源組織的管理等都可以說是最棒的,JFox項目一直具有生命力,huihoo這么多年了也一直具有生命力,Allen、Peter、Orbat等對這個團隊這么多年來的堅持及貢獻,要選國內最值得推崇的開源團體,huihoo排在第一位可以說是當之無愧。因此,他們是最可愛的人。 2、Jdon—高處不勝寒 代表人物:彭晨陽(板橋里人) 代表項目:jdonframework 官方網站:http://www.jdon.com/ 簡評:作為國內第一個開源框架的發起人,作為國內第一個敢于與國外框架叫板的板橋里人,他曾經帶給大家很多很多的欣喜及回憶,橋技術水平及造詣這里就更不用說了,他“ 一個開源人的孤獨告白”,有點滄桑,有點心寒,jdon今天的現狀,是中國對待技術人才的真實寫照。無論如何,選中國Java開源界最可愛的人,板橋當之無愧。 3、Apusic OperaMasks—誰說開源不賺錢 代表人物:袁紅崗 張勇 代表項目:OperaMasks 官方網站:http://www.operamasks.org/ 簡評:1000萬人民幣的投入,一篇“勇敢者的新世界”也算是在中國開源界掀起了一陣波瀾,產品發布會上那一份份合同,更是讓同行的老總們有點眼紅。除去商業因素不說,這兩天Check out了OperaMasks的代碼,也看了示例,表現非常不錯,值得深層次的java開發人員學習。老袁深厚的技術功底、老張賣力的全國路演,公司經營戰略的成功,OperaMasks能否發展成為一個最能適合中國國情的開源組織,讓我們拭目以待。 4、EasyJF—后生可畏 代表人物:蔡世友(大峽)、吳嘉俊(stef_wu)、程強(天一) 代表項目:EasyJWeb 簡評:看了大峽小朋友的一些文章, 看到EasyJF現在的發展,真真實實有一種后生可畏的感嘆。他們有自己的專職團隊,有網下辦公室,還有硬件設施,還擁有一群有激情、好學的年輕小伙子們。雖然要得到中國人自己的認可是很不容易的事情,但搜索一下帶是發現國內已經有不少網站在用EasyJWeb做開發。因此,最可愛的人當他們莫屬,衷心希望他們能成功。 5、SpringSide—天才團隊 代表人物:肖樺(江南白衣)、陳俊(cac)、田淼(差沙) 代表項目:SpringSide 官方網站:http://www.springside.org.cn/ 簡評:雖然只是站在春天的傍邊,但已經帶給了整天忙于追逐新技術、新潮流的Java程序員們很多極具參考價值的東西。江南白衣同學可以算是一個天才般的人物,技術的攻底、接受并譯釋新技術的速度、能力及水平,可以說是少數中的少數。因此,SpringSide可以稱得上最具有偶像潛質的團隊,Java開源界最可愛的人,他們當之無愧,希望他們能從“傍邊”走到“中間”。 6、Buffalo社區—濃縮是精 代表人物:陳金洲(Michael Chen) 代表項目: Buffalo 官方網站:http://buffalo.sourceforge.net/ 簡評:作為第一個國人開發的Ajax框架,作為一個能把一直受java大拿們岐視javascript玩轉得如何熟悉的項目,作為一個能幾年堅持更新的開源項目,Buffalo是成功的,Michael Chen讓我們體會到國內開源貢獻者們執著與堅持。他是不是最可愛的人,誰是? 7、天乙社區—享受開源動力 代表人物:laoer 代表項目:天乙開源社區 簡評:有多少開源項目的產品發布到8.0,從jsp、struts1到struts2一路走來,一直能跟著新技術的步伐,不斷改進及完善。因此,當之無愧java開源界最可愛的人。 8、CowNew開源—真有一點牛 代表人物:楊中科 代表項目:CowNewSQL 簡評:看過楊中科同學的兩篇文章,我覺得他是可愛的。多數據庫翻譯引擎CowNewSQL的價值將在哪里體現?CowNew能在何時給我們帶來更多實用的東西,值得大家期待。無論如何,他們的進步是有目共睹。 9、CommonTemplate—值得期待 代表人物:梁飛(javatar) 代表項目:CommonTemplate 官方網站:http://www.commontemplate.org/ 簡評:也許很多人不知道這個項目,但他確實是一個很不錯的模板引擎,金子總有發光的時候。只要堅持,相信有一天梁飛同學會給大家帶來更多的驚喜。 10、恩信—小公司也能開源mike zeseler 代表人物:劉有濤 代表項目:恩信開源ERP 簡評:聽過劉總的演講,從“捕魚”到“授之以漁”,從劉總一系列運作手法,我覺得恩信可以成為很多追逐開源但又沒有上千萬資金來投入而總在為是否參加開源而徘徊的老總們的參考學習的案例。雖然沒有技術牛人加盟,雖然還使用稍為古老的技術體系,但既然開源了,總能讓我們學到很多東西。呵呵,所有最可愛的開源人中,劉總算是算是最年長的了,祝他們開源ERP大賣 |
posted @ 2009-01-30 17:59 mike zeseler 閱讀(341) | 評論 (1) | 編輯 收藏