Oracle’s Java FAQ Displays in Chinese

17. January, 2014

I just looked at an article in the Oracle Java FAQ and I was a bit surprised to get this result:

         如何設定例外網站清單?


本文適用於:

  • Java 版本: 7.0

從 Java 7 Update 51 版本開始導入了例外網站清單功能。藉由將應用程式 URL 新增至「例外」清單,可讓使用者執行通常會被安全檢查封鎖的「豐富網際網路應用程式 (Rich Internet Applications, RIA)」。[...]

The solution was pretty simple: Append ?locale=en to the end of the URL: http://www.java.com/de/download/faq/exception_sitelist.xml?locale=en

That fixed it for me … sometimes.


Bean of type is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

30. October, 2013

Haunted by this? Getting mysterious NullPointerExceptions in your BeanPostProcessors?

I have written a lengthy answer how to debug and solve these issues on stackoverflow.com.


Jazoon 2013 – The Economies of Scaling Software

25. October, 2013

Jazoon 2013 badgeIf you’re small, scalability is not an issue. If you’re big, you can plan for it. But what if you wake up one morning and you suddenly find you’ve become the next Google?

In his talk “The Economies of Scaling Software“, Abdelmonaim Remani talks about what scaling means, how you can plan for it (even if you don’t expect it to happen) and all the nasty details that stand between you and success (slides on slideshare).

Today, the ubiquity of the Internet has blurred the lines between consumers and enterprises. They start to ask the same questions which eventually all boil down to: “How can I find what I’m looking for in a universe of haystacks?”

One day, many of us will find themselves with the need to scale because the performance of the old solution has become unbearable and all low-hanging fruit (faster CPU, more RAM) have been picked.

To solve this, you can look at the CPU (slide 16-35) or you can start to build clusters (36-45).

Or your I/O might be the bottleneck (slides 46-60). You can solve this by looking at NoSQL databases and caching.

Is the network the problem? (slides 61-75) Start with asynchronous processing, batch jobs, content delivery networks (CDN), DNS sharding or use a different protocol to connect the various parts of your system.

But how do you know what part is the bottleneck? The answer here is monitoring. (slide 77)

Note that scaling often helps with disaster recovery, you still have to plan for it – if all nodes of your cluster are in the same room, it’s still a single point of failure (slide 79)

Software isn’t everything. Don’t forget your team (slide 82)


Jazoon 2013 – Join the Java Evolution; JCP & Adopt-a-JSR

25. October, 2013

Jazoon 2013 badgeHeather VanCura explained how the new JCP works in her talk “Join the Java Evolution; JCP & Adopt-a-JSR” (slides on slideshare)

Oracle spent the last years to make the JCP much more open and accessible. One example here are the JSRs which are much more lightweight than the complex JCPs. You can even adopt one.

Maybe you’re a long time joda-time user and want to make sure important features make it into JSR 310 – new Date and Time API for Java? Join them to discuss your need, share some code, help write, improve or translate documentation.

Some bug in the SDK nagging you? Contribute a fix to the OpenJDK. With Java 8, the OpenJDK build has been simplified tremendously. Sun ignored your bug report for years even though it contained a patch? Now is the time to change this.

I had the chance to chat with Heather after the talk which earned me a copy of “Java 7 Concurrency Cookbook”; thanks for that :-) We discusses a couple of ideas and she gave me points; maybe I’ll submit a few patches. If I do, I’ll blog about the experience here.


Jazoon 2013 – Kafka and Storm – event processing in realtime

25. October, 2013

Jazoon 2013 badgeGuido Schmutz introduces two frameworks in his talk “Kafka and Storm – event processing in realtime” (slides on slideshare)

Apache Kafka is a publish-subscribe messaging system like JMS but more simple. Messages are kept in files and never deleted. Together with the fact that subscribers have to tell the system which message they want next, this means you can recover from bugs that corrupted your data even if you notice them only after some time: Just process all the corrupted messages again.

Storm is a “distributed realtime computation system. ” It makes it easy to define topologies (= graphs) of bolts (= places where a computation takes place) flowing your real-time data through a complex network to process, filter and aggregate it. Just like Akka, it defines all kinds of operations (filters, switches, routers, …) so you can easily and quickly build the topology you need. Trident makes this set-up step even more simple.

Compared to Hadoop, Storm is meant for real-time processing. Some projects combine the two.

If you need a good framework for serializing data in Java, have a look at Apache Avro.


Jazoon 2013 – Rocket Propelled Java

25. October, 2013

Jazoon 2013 badgeRocket Propelled Java” is about being more productive by writing less boilerplate code (slides on slideshare).

In his talk, Andres Almiray showed some tools to make your code more compact while keeping or even improving readability.

The first one is lombok and lombok-pg which use Java annotations to generate a lot of boiler plate code (slides 3-6)

Similar, you can use Groovy AST transformations to create things like immutables or singletons correctly (“There are 5-6 ways to create singletons. Only two of them are correct”, slides 7-9)

Note: You might be worried to add Groovy to a pure Java project. You don’t have to. Just use it for the AST transformations to stop wasting time on writing code that only makes your compiler happy. Use Groovy as a “boilerplate code buster.”

If you ever wanted to use “Design by Contract“, GContracts is for you.


There is no Spoon: Changing Final Fields in Java

21. January, 2013

If you’re the guy in the team who solves the impossible problems, you will eventually run into the worst of all design patterns: Singletons. Which are implemented in Java using final (static) fields.

Sebastian Zarnekow came up with a way to change that. Following the timeless advice from the Matrix – there is no spoon -, he found a way to modify (some) final fields.

As I said before, this is a desperate measure, so use it wisely. But remember this tool next time when you need to mock a singleton for a test case.


Java Toolbox

9. November, 2012

 posted an article with some tools that you should know about when developing Java code: “A Software Craftsman’s Toolbox: Lightweight Java libraries that make life easier.

Along the same lines, Jeeeyul came up with an idea to make

System.out.println( "Hello World." );

produce this output:

(MyHelloWorld.java:10) : Hello World.

Just takes 34 lines of code: “Make System.out.println() Rocks!


Enums With More Than One Name

8. October, 2012

In Java, you sometimes encounter places where you need an enum with more than one name (or key). Here is the pattern that I use:

import java.util.HashMap;
import java.util.Map;

enum X {
    // "A" is the name of the enum, "a" is the second name/key.
    A("a"), B("b");

    private final static Map<String,X> MAP = new HashMap<String,X>();
    static {
        for( X elem: X.values() ) {
            if( null != MAP.put( elem.getValue(), elem ) ) {
                throw new IllegalArgumentException( "Duplicate value " + elem.getValue() );
            }
        }
    }

    private final String value;

    private X(String value) { this.value = value; }
    public String getValue() { return value; }

    // You may want to throw an error here if the map doesn't contain the key
    public static X byValue( String value ) { return MAP.get( value ); } 
}

Things to note:

  1. There are additional parameters in () after the enum name.
  2. You need a custom constructor which accepts the additional parameters. Like other Java classes, you can have as many constructors as you need.
  3. I’m filling the static map from a static block inside of the enum declaration. Looks odd but works. Java will first create all instances and then invoke the static code in my custom enum.
  4. You can look up enum values by using the static method byValue(). The name is not very good (it’s easy to get confused with enum‘s valueOf()). When the field is called code, I use byCode(). So in real life, it will be less confusing.

Xtend for Java Developers

2. October, 2012

There are a couple of common pitfalls when a Java developer starts using Xtend.

Java Xtend Description
String.class typeof(String) Get the class instance of a type
Long.MAX_VALUE Long::MAX_VALUE Accessing static fields
Foo.Bar Foo$Bar Accessing inner classes

Example: org.slf4j logging

private Logger log = LoggerFactory.getLogger(Foo.class)    // Java

        Logger log = LoggerFactory::getLogger(typeof(Foo)) // Xtend

Also, the .. or upTo operator has a severe bug. The code for i: 0..list.size won’t work as expected. First of all, it will iterate once too many.

The obvious fix for i: 0..(list.size-1) doesn’t work when the list is empty because it will iterate twice (0, -1) and it won’t iterate at all if the list has a single element.

Use .. only with constant operands (i.e. 1..5 is OK, list.size..0 isn’t). If you need to iterate over a range [start … end), use this gist instead.


Follow

Get every new post delivered to your Inbox.

Join 312 other followers