Java 中类的重载与覆盖之间的一点小区别
大的区分我想熟悉 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";
}
public static String classify(Collection c) {
return "Unknown Collection";
}
public static void main(String[] args) {
Collection[] cs = new Collection[] {
new HashSet(), new ArrayList(), new HashMap().values()
};
for (Collection c : cs) {
System.out.println(classify(c));
}
}
}
在这个例子中,将打印 “Unknown Collection” 三次。这是因为到底调用哪个重载方法是在编译时刻就做出决定的。在三次循环中,参数的编译类型都是:Collection。
Categorized in: Java · Tagged with: Java
Which style of WSDL should I use? (reship)
Date: 24 May 2005 (Published 31 Oct 2003)
Level: Advanced
Summary: 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.
Introduction
A WSDL document describes a Web service. A WSDL binding describes how the service is bound to a messaging protocol, particularly the SOAP messaging protocol. A WSDL SOAP binding can be either a Remote Procedure Call (RPC) style binding or a document style binding. A SOAP binding can also have an encoded use or a literal use. This gives you four style/use models:
- RPC/encoded
- RPC/literal
- Document/encoded
- Document/literal
Add to this collection a pattern which is commonly called the document/literal wrapped pattern and you have five binding styles to choose from when creating a WSDL file. Which one should you choose?
Before I go any further, let me clear up some confusion that many of us have stumbled over. The terminology here is very unfortunate: RPC versus document. These terms imply that the RPC style should be used for RPC programming models and that the document style should be used for document or messaging programming models. That is not the case at all. The style has nothing to do with a programming model. It merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
Likewise, the terms encoded and literal are only meaningful for the WSDL-to-SOAP mapping, though, at least here, the traditional meanings of the words make a bit more sense.
For this discussion, let’s start with the Java method in Listing 1 and apply the JAX-RPC Java-to-WSDL rules to it (see Resources for the JAX-RPC 1.1 specification).
public void myMethod(int x, float y); |
RPC/encoded
Take the method in Listing 1 and run it through your favorite Java-to-WSDL tool, specifying that you want it to generate RPC/encoded WSDL. You should end up with something like the WSDL snippet in Listing 2.
Listing 2. RPC/encoded WSDL for myMethod
<message name="myMethodRequest">
<part name="x" type="xsd:int"/>
<part name="y" type="xsd:float"/>
</message>
<message name="empty"/>
<portType name="PT">
<operation name="myMethod">
<input message="myMethodRequest"/>
<output message="empty"/>
</operation>
</portType>
<binding .../>
<!-- I won't bother with the details, just assume it's RPC/encoded. -->
|
Now invoke this method with “5″ as the value for parameter x and “5.0″ for parameter y. That sends a SOAP message which looks something like Listing 3.
Listing 3. RPC/encoded SOAP message for myMethod
<soap:envelope>
<soap:body>
<myMethod>
<x xsi:type="xsd:int">5</x>
<y xsi:type="xsd:float">5.0</y>
</myMethod>
</soap:body>
</soap:envelope>
|
There are a number of things to notice about the WSDL and SOAP message for this RPC/encoded example:
Strengths
- The WSDL is about as straightforward as it’s possible for WSDL to be.
- The operation name appears in the message, so the receiver has an easy time dispatching this message to the implementation of the operation.
Weaknesses
- The type encoding info (such as
xsi:type="xsd:int") is usually just overhead which degrades throughput performance. - You cannot easily validate this message since only the
<x ...>5</x>and<y ...>5.0</y>lines contain things defined in a schema; the rest of thesoap:bodycontents comes from WSDL definitions. - Although it is legal WSDL, RPC/encoded is not WS-I compliant.
Is there a way to keep the strengths and remove the weaknesses? Possibly. Let’s look at the RPC/literal style.
Categorized in: SOA · Tagged with: schema, SOAP, UDDI, Webservice, WSDL, XML
Servlet 3.0 新特性
Servlet 3.0 规范的 JSR 315 已经进入到了 proposed final draft 阶段,想必很快就会在 Java EE 6 中释出。 新版本的 Servlet 规范变动比较大,不单单只是 API 的变动,而是引入了很多新特性。
那么都有哪些新特性呢:
- 支持注释
- 可插拔、易扩展
- 支持请求的异步处理
- 安全性得到增强
- 其他杂项变化
Categorized in: Java · Tagged with: Java, Servlet
Ubuntu 下 NetBeans 编辑器的字体锯齿问题
Append this -J-Dawt.useSystemAAFontSettings=on to netbeans_default_options in etc/netbeans.conf, then restart netbeans
Categorized in: Java · Tagged with: NetBeans, Ubuntu
SVN 1.6 on ubuntu
For Karmic:
deb http://ppa.launchpad.net/anders-kaseorg/subversion-1.6/ubuntu karmic main deb-src http://ppa.launchpad.net/anders-kaseorg/subversion-1.6/ubuntu karmic main
For Jaunty:
deb http://ppa.launchpad.net/anders-kaseorg/subversion-1.6/ubuntu jaunty main deb-src http://ppa.launchpad.net/anders-kaseorg/subversion-1.6/ubuntu jaunty main
For Intrepid:
deb http://ppa.launchpad.net/anders-kaseorg/subversion-1.6/ubuntu intrepid main deb-src http://ppa.launchpad.net/anders-kaseorg/subversion-1.6/ubuntu intrepid main
For Hardy:
deb http://ppa.launchpad.net/anders-kaseorg/subversion-1.6/ubuntu hardy main deb-src http://ppa.launchpad.net/anders-kaseorg/subversion-1.6/ubuntu hardy main
Categorized in: Operation Systems · Tagged with: Linux, SVN, Ubuntu
How to reset your Linux root password (reship)
原文: http://www.ibm.com/developerworks/cn/linux/l-10sysadtips/
如果忘记根密码,就必须重新安装整台机器。更惨的是,许多人都会这样做。但是启动机器并更改密码却十分简单。这并非在所有情况下都适用(比如设置了一个 GRUB 密码,但也忘记了),但这里介绍一个 Cent OS Linux 示例,说明一般情况下的操作。
首先重启系统。重启时会跳出如图 1 所示的 GRUB 屏幕。移动箭头键,这样可以保留在此屏幕上,而不是进入正常启动。
图 1. 重启后的 GRUB 屏幕

然后,使用箭头键选择要启动的内核,并输入 E 编辑内核行。然后便可看到如图 2 所示的屏幕:
图 2:准备编辑内核行

再次使用箭头键突出显示以 kernel 开始的行,按 E 编辑内核参数。到达如图 3 所示的屏幕时,在图 3 中所示的参数后追加数字 1 即可:
图 3. 在参数后追加数字 1

然后按 Enter 和 B,内核会启动到单用户模式。然后运行 passwd 命令,更改用户根密码:
sh-3.00# passwd
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully
现在可以重启了,机器将使用新密码启动。
Categorized in: Operation Systems · Tagged with: Linux, Ubuntu
eBay Marketplace Architecture (reship)
Architectural Forces: What do we think about?
• Scalability
– Resource usage should increase linearly with load
– Design for 10x growth in data, traffic, users, etc.
• Availability
– Resilience to failure
– Graceful degradation
– Recoverability from failure
• Latency
– User experience latency
– Data latency
• Manageability
– Simplicity
– Maintainability
– Diagnostics
• Cost
– Development effort and complexity
– Operational cost (TCO)
Architectural Strategies: How do we do it?
• Strategy 1: Partition Everything
– “How do you eat an elephant? … One bite at a time”
• Strategy 2: Async Everywhere
– “Good things come to those who wait”
• Strategy 3: Automate Everything
– “Give a man a fish and he eats for a day … Teach a man to fish and he eats for a lifetime”
• Strategy 4: Remember Everything Fails
– “Be Prepared”
…
Categorized in: Architecture · Tagged with: Architecture
弃用 Yahoo! stat.
雅虎统计改为量子恒道统计,遂决意放弃,改用 google analytics。
Categorized in: My Life · Tagged with: MyLife

(
(4.00 out of 5)