2009年8月29日
Groovy 支持操作符重载, 每个操作符对应一个方法签名, 如‘+’对应的是’plus’.
Groovy 支持多种字符串表示, 单引号, 双引号(支持GString), 3个单引号(支持多行), 3个双引号(支持多行, 支持GString).
在 Groovy 中, 方法的括号是可选的, 如果一行只有一个语句, 那么语句后的分号也可省略不写.
Groovy range, 可用于: 数字, 日期, 字符串. 只要数据类型实现了 next(++), previous(–), 和
java.lang.Comparable 接口, 就可以使用 range .
Groovy list 默认使用 ArrayList, 欲使用 LinkedList 等其它类型 List, 需要明确声明.
List 可以使用负值作为index值进行访问, 例如 list[-1]返回的就是list的最后一个值, list[-2]则返回倒数第二个值. 也可以指定倒序的 range, 如list[4..0].
需注意: list[0..<-2] 等价于 list[0..-1] 而非 list[0..-3].
声明空的map: [:]
['a':1] 等价于 [a:1]
Related Posts:
2009/08/05 — Groovy [...]
文章来源:
http://blog.baturu.com/index.php/2009/08/25/groovy_lesson_four.html
1. == 是判断是否 equals, 而判断是否是同一对象则用 is
2. list 和 map 的一些方法:
def x = 1..10
assert x.contains(5)
assert x.contains(15) == false
assert x.size() == 10
assert x.from == 1
assert x.to == 10
assert x.reverse() == 10..1
3. 以下对象都有 size() 方法
Array, String, StringBuffer, Collection, Map, File
4. 数据类型:12 – Integer, 100L – Long, 1.23F – Float, 1.23D – Double, 123G – BigInteger, 1.23,1.23G – BigDecimal
如果一个小数, [...]
文章来源:
http://blog.baturu.com/index.php/2009/08/05/groovy_lesson_three.html
在某开源项目里, 发现它使用了一种很有意思的 assertion 机制. 这是一种仿 assertion 的方式来实现对输入参数或特定表达式的判断.
伪代码如下:
public final class Assert {
private Assert() {}
public static void notNull(Object o) {
notNull("Null object is used", o);
}
public static void notNull(String description, Object o) {
[...]
文章来源:
http://blog.baturu.com/index.php/2009/07/30/the_interesting_but_useful_mock_assertion_in_java.html
在 XML 实例文档中有时会发现有 schemaLocation 属性。很多人对此非常疑惑,搞不清这个属性究竟是什么意思,究竟该如何使用。
schemaLocation 属性用来引用(schema)模式文档,解析器可以在需要的情况下使用这个文档对 XML 实例文档进行校验。它的值(URI)是成对出现的,第一个值表示命名空间,第二个值则表示描述该命名空间的模式文档的具体位置,两个值之间以空格分隔。当然,在必要情况下,可以为 schemaLocation 属性指派多个这样的值对。
<p:Person
xmlns:p="http://contoso.com/People"
xmlns:v="http://contoso.com /Vehicles"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://contoso.com/People
http://contoso.com/schemas/people.xsd
http://contoso.com/schemas/Vehicles
http://contoso.com/schemas/vehicles.xsd
http://contoso.com/schemas/People
http://contoso.com/schemas/people.xsd">
<name>John</name>
<age>28</age>
<height>59</height>
<v:Vehicle>
<color>Red</color>
[...]
文章来源:
http://blog.baturu.com/index.php/2009/07/23/whats_the_purpose_of_schemalocation_attribute_in_xml.html
该同步要同步
同步块尽可能的小
循环内使用wait()
synchronized (obj) {
while (condition) {
obj.wait();
}
}
notifyAll()优先于notify()
yield()不可靠
在持有锁的时候, 尽量不要调用其它对象的方法, 因为这很可能是死锁的源头.
线程优先级取决于底层实现, 应尽量避免使用.
守护线程与非守护线程的区别:当进程中所有非守护线程已(结束或)退出时,即使仍有守护线程在运行,进程仍将结束.
Related Posts:
2009/08/25 — Groovy 学习笔记 (四)
2009/08/05 — Groovy 学习笔记 (三)
2009/07/30 — The interesting but useful mock assertion in
java
2009/07/08 —
java 中类的重载与覆盖之间的一点小区别
2009/07/03 — Servlet 3.0 新特性
文章来源:
http://blog.baturu.com/index.php/2009/07/22/some_java_thread_tips.html
SOAP 除了可以 bind 到 HTTP 上外, 也可以 bind 到 SMTP 上. 其实个人感觉, SOAP bind 到 SMTP 上的场景很少会使用到, 通常限于 one-way operation (比如通知等不需要响应). 如果需要实现 request/response, 那么是需要多做一些工作的(下文会有叙述).
soap:binding element 的 transport 属性需指定一个 http://xxx(例如:http://schemas.xmlsoap.org/soap/smtp) URL 来表明所要 binding 的 protocol. 似乎这个 URL 是任意形式, 只要能让调用方知道要使用什么协议即可. 在 soap:address 要给定 mailto:xxxx@xxx.xxx 这样形式的 URI.
<service name="StockQuoteServiceBinding_service">
[...]
文章来源:
http://blog.baturu.com/index.php/2009/07/19/smtp_transport_binding_for_soap.html
大的区分我想熟悉
java 这门语言的人都知道,本文仅为记录在阅读《Effective
java》时所遇到的新知识。
在《Effective
java》中,Joshua Bloch提到:对于重载方法 (overloaded method) 的选择是静态的,而对于被改写的方法 (overridden method) 的选择是动态的。
对于被改写的方法,选择正确的方法版本是在运行时刻进行的,选择的依据是被调用方法所在对象的运行时类型。如果被改写方法是在子类实例上被调用,那么该子类实例中的方法将会执行。
而对于重载方法,则恰恰与改写方法的行为相反。
请看如下例子:
public class CollectionClassifier {
public static String classify(Set s) {
return "Set";
}
public static String classify(List l) {
return "List";
[...]
文章来源:
http://blog.baturu.com/index.php/2009/07/08/a_slight_difference_between_overload_and_override_in_java.html
A Web Services Description Language (WSDL) binding style can be RPC or document. The use can be encoded or literal. How do you determine which combination of style and use to use? The author describes the WSDL and SOAP messages for each combination to help you decide.
文章来源:
http://blog.baturu.com/index.php/2009/07/07/which-style-of-wsdl-should-i-use-reship.html
Servlet 3.0 规范的 JSR 315 已经进入到了 proposed final draft 阶段,想必很快就会在
java EE 6 中释出。 新版本的 Servlet 规范变动比较大,不单单只是 API 的变动,而是引入了很多新特性。
那么都有哪些新特性呢:
支持注释
可插拔、易扩展
支持请求的异步处理
安全性得到增强
其他杂项变化
支持注释
Servlet、Filter、Listener 都可使用注释,且不必如之前版本那样,必须实现 Servlet, Filter, Listener 等接口。
@Servlet(urlMapping={“/foo”, “/bar”}, name=”MyServlet”)
public class SampleUsingAnnotationAttributes {
@GET
public void handleGet(HttpServletRequest req, HttpServletResponse res)
{
....
[...]
文章来源:
http://blog.baturu.com/index.php/2009/07/03/servlet_30_new_features.html
Append this -J-Dawt.useSystemAAFontSettings=on to netbeans_default_options in etc/netbeans.conf, then restart netbeans
Related Posts:
2009/06/30 — SVN 1.6 on ubuntu
2009/06/19 — How to reset your Linux root password (reship)
2009/05/13 — How to install libstdc++.so.5 for Ubuntu
2009/02/02 — 使用 netbeans 6.5 创建 firefox 扩展
2008/10/22 — Linux 上的 svn UI 客户端
文章来源:
http://blog.baturu.com/index.php/2009/07/02/how_to_fix_editor_jagged_font_in_netbeans_on_ubuntu.html