อ่านแล้วตลกดี (เหมือนชีิวิตจริง)
เอามาจาก Deepak Alur's Blog
Javaเร็วส์, Javascript, Erlang, Python, Ruby, Clojure, Groovy, เลี้ยงลูก, วาดภาพ
We started developping using all the nice technologies we know: Servlet/JSP, Struts, Spring DAOs, Hibernate.
But we experienced painful problems and the learning curve was hard.
Between you and me, if we had to do it again in the same conditions, I may not use Hibernate, neither Spring transactions, and probably something else than Struts (maybe PhP ? oups, I've said it !). We'll publish an article later end May and explain how these painful layers have been useful sometimes.
Java is fast and scallable when used right.
Unfortunatelly, Java developers quite often over-engineer, over-design, over-layer, over-hype, over-complicate...

Configuration config = new PropertiesConfiguration("usergui.properties");
ConfigurationFactory factory = new ConfigurationFactory("config.xml");
Configuration config = factory.getConfiguration();<configuration>
<system/>
<properties fileName="application.properties"/>
<xml fileName="conf/test.xml"/>
<jndi prefix="java:comp/env"/>
</configuration>
include = colors.properties
PropertiesConfiguration config = new PropertiesConfiguration("usergui.properties");
config.setReloadingStrategy(new FileChangedReloadingStrategy());app.name=pok
app.version=1.0
app.title=${app.name}-${app.version}
PropertiesConfiguration config = new PropertiesConfiguration("usergui.properties");
config.setAutoSave(true);colors.pie = #FF0000, #00FF00, #0000FF
String[] colors = config.getStringArray("colors.pie");colors.pie = #FF0000;
colors.pie = #00FF00;
colors.pie = #0000FF;
function calculator()
{
var a, b, operator;
cocoon.sendPageAndWait("getA.html");
a = cocoon.request.get("a");
cocoon.sendPageAndWait("getB.html");
b = cocoon.request.get("b");
cocoon.sendPageAndWait("getOperator.html");
operator = cocoon.request.get("op");
try {
if (operator == "plus")
cocoon.sendPage("result.html", {result: a + b});
else if (operator == "minus")
cocoon.sendPage("result.html", {result: a - b});
else if (operator == "multiply")
cocoon.sendPage("result.html", {result: a * b});
else if (operator == "divide")
cocoon.sendPage("result.html", {result: a / b});
else
cocoon.sendPage("invalidOperator.html", {operator: operator});
}
catch (exception) {
cocoon.sendPage("error.html", {message: "Operation failed: " + exception.toString()});
}
}
public class Person {
String name;
int age;
boolean isSmoker;
...
public int hashCode() {
// you pick a hard-coded, randomly chosen, non-zero, odd number
// ideally different for each class
return new HashCodeBuilder(17, 37).
append(name).
append(age).
append(smoker).
toHashCode();
}
} public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
} public boolean equals(Object o) {
if ( !(o instanceof MyClass) ) {
return false;
}
MyClass rhs = (MyClass) o;
return new EqualsBuilder()
.appendSuper(super.equals(o))
.append(field1, rhs.field1)
.append(field2, rhs.field2)
.append(field3, rhs.field3)
.isEquals();
}
ถ้าใช้ reflection public boolean equals(Object o) {
return EqualsBuilder.reflectionEquals(this, o);
} public boolean equals(Object other) {
if ( !(other instanceof Client) ) return false;
Client castOther = (Client) other;
return new EqualsBuilder()
.append(this.getId(), castOther.getId())
.isEquals();
}
// Note: id is object id (surrogate identifier) of this object
public int hashCode() {
return new HashCodeBuilder()
.append(getId())
.toHashCode();
} <dependency>
<groupId>classifier4j</groupId>
<artifactId>Classifier4J</artifactId>
<version>0.6</version>
</dependency>
public class BreakTokenizer implements ITokenizer {
public String[] tokenize(String input) {
ArrayList list = new ArrayList();
BreakIterator bt = BreakIterator.getWordInstance();
bt.setText(input);
int start = bt. first ();
for (int end = bt. next (); end != BreakIterator. DONE; start = end, end = bt. next ()) {
String tmp = input.substring(start, end);
list.add(tmp);
}
return (String[]) list.toArray(new String[0]);
}
} public static void main(String[] args) throws ClassifierException {
TermVectorStorage store = new HashMapTermVectorStorage();
VectorClassifier cs = new VectorClassifier(store);
BreakTokenizer tk = new BreakTokenizer();
cs.setTokenizer(tk);
cs.teachMatch("สวัสดีครับนี่คือภาษาไทย");
System.out.println(cs.classify("สวัสดี ภาษาไทย"));
IWordsDataSource ds = new SimpleWordsDataSource();
BayesianClassifier bcs = new BayesianClassifier(ds, tk);
bcs.teachMatch("สวัสดีครับนี่คือภาษาไทย");
System.out.println(bcs.classify("สวัสดี ภาษาไทย"));
}
0.7071067811865476
0.99
<project default="compile">
<target name="init" if="eclipse.running">
<property name="build.compiler"
value="org.eclipse.jdt.core.JDTCompilerAdapter" />
</target>
<target name="compile" depends="init">
<echo>debug build.compiler = ${build.compiler}</echo>
<javac srcdir="." destdir="./target" />
</target>
</project>