How to Run the Eclipse Formatter From the Command Line

Today I’ve dug out an Eclipse 3.2 article that’s seven years old and is still valid. Considering how much Eclipse has changed since 2007 that’s pretty astonishing. So, if you want to know how to format an entire Java Eclipse project in no time, you may ask Peter Friese. Of course you’re invited to read on instead and learn some additional hints.
Continue reading “How to Run the Eclipse Formatter From the Command Line” »

Microservices – The New Silver Bullet?

Recently microservices are getting popular in the Java world. The general idea is our applications have become too complex. Better split them into smaller chunks, small enough to swallow for a small team or even an individual. They have “to be small enough to fit in your head”.

Actually, this idea is far from being new. When functions, classes, modules, portlets, SOA services and business processes were invented, people used pretty much the same words to advocate the new idea. Microservices add a new twist in that they contain the GUI, and in that every microservice uses it’s own database. The application is sliced vertically (as opposed to the horizontal slicing imposed by the MVC model). The result is a small library that can be deployed independently. The application consists of a collection of largely independent microservices working together.
Continue reading “Microservices – The New Silver Bullet?” »

Application Servers Are (Sort of) Dead!

Recently it crossed my mind there’s something wrong with Java application servers. You know, our team is still using them the way they’re meant. The way they were originally meant. We’ve got many applications running on a common application server that’s managed centrally.

I’m told we’re one of the last companies to do so. These days, most companies dedicate an entire application server to a single application and put them in a virtual machine.

In other words, application servers have become part of the application. Originally, it was meant to be the other way round, and that’s why Eberhard Wolff claims application servers are dead. His JAX talk was a real eye-opener, by the way. He expressed the thoughts that ware already lingering in the subconscious part of my mind. As usual, I’ll mention a few key points of his talk in this post, plus a few thoughts of my own. If you’re interested in the entire talk, have a glance at his slides. He also published an article in the Java-Magazin 7.2014 (in German language, and as far as I know, only available in print).

So what’s wrong with the original idea of applications servers? Let me put the question differently: Have you ever seen an application server that runs out of the box, without being modified?
Continue reading “Application Servers Are (Sort of) Dead!” »

BabbageFaces 1.0 RC2 Now Available for Download

Fork me on GitHubMy guts tell me BabbageFaces is ready to be released into the wild. Most of the time that’s a reliable measure. Today I’ve tested it with the new PrimeFaces 5 showcase. BabbageFaces passed the test without problems. There’s also a decent showcase example containing most of the elements of a typical business application, running both on Apache MyFaces and Mojarra. I’m optimistic all that’s missing is a couple of source code comments, tidying and documentation to call it a final version.

The showcase demo also shows BabbageFaces allows you to stop scattering ids all around your JSF code just to make AJAX efficient. BabbageFaces compares the response with the current DOM tree and sends only the minimum set of changes to the clients. If network load is giving you headaches, BabbageFaces may be your tool of choice. It reduces network traffic. At the same time it simplifies the programming model.
Continue reading “BabbageFaces 1.0 RC2 Now Available for Download” »

Value Types: Revamping Java’s Type System

This morning Brian Goetz revealed interesting news at the end of his talk at the JAX conference. Oracle is considering to extend Java’s type system. Did you ever wonder why there are no call by value parameters in Java methods? Why there’s no Array<int> in Java? Why functions return one – and only one – value at a time? Why there are no tupels in Java? Why arrays are created in such a weird way, making them effectively scattered all around the memory? Brian Goetz told us they might fix all this after adding value types to the language, which allow for a efficient implementation of these ideas. Truth to tell, he didn’t really promise value types. In particular, he says Java 9 will almost certainly not include the feature. However, judging from the quality and level of detail of his “State of the Values” paper I’m positive they are going to make it into a future version of Java.
Continue reading “Value Types: Revamping Java’s Type System” »

Announcement: BabbageFaces 1.0 RC1

Fork me on GitHubToday I’ve uploaded the new showcase demo of BabbageFaces.

After fixing every bug I know of, I made up my mind to call the current version a release candidate. Now it’s up to you: download BabbageFaces and tell me whether it works with your application.

I still recommend to use the source code version from GitHub because then it’s easier to trace down potential bugs. However, you can also download the distribution file from the distribution folder on GitHub.

Please let me know about your experience. Report errors as a comment at the end of this page (don’t forget to provide the source code so I have a clue what’s going wrong!). But of course I’d also like to hear from you if you’re using BabbageFaces successfully :). In any case, be prepared to receive an e-mail if I need further information to reproduce your bug or to answer your question.

Newsflash: Can You Rely on System.nanoTime()?

If you’re like me, you’re concerned about your application’s performance. So you’re familiar with profiling your application.

The simplest way to measure your application’s performance is to time how long a method call takes. Most of you probably know System.currentTimeMillis(), but there’s a better alternative:

public long measure() {
  long startTime = System.nanoTime();
  work();
  return System.nanoTime() - startTime;
}

System.nanoTime() is a great function, but one thing it’s not: accurate to the nanosecond. The accuracy of your measurement varies widely depending on your operation system, on your hardware and on your Java version. As a rule of thumb, you can expect microsecond resolution (and a lot better on some systems).

Alexey Shipilev wrote a great article on the dos and don’ts of measure performance. Among other things he shows how multithreading can spoil the accuracy of performance measurements, reducing the resolution of System.nanotime() to 15 milliseconds under averse conditions.

Newsflash: React Speeds Up AngularJS Rendering

Today I’ve read about a small but interesting framework called React.js that convinced me to start a new series on this blog. Newsflashes are small articles, just two or three sentences, describing an interesting idea and providing a link to read on. They are less thoroughly researched than the full-fledged articles of BeyondJava.net. Instead I’ll go with my guts to choose interesting bits of information.

React is a lightweight Javascript framework focusing on the UI. According to the project page, using a virtual DOM difference algorithm makes it very fast. Thierry Nicola decribes in his article how to combine AngularJS and React to make your AngularJS application faster.

While the effect is impressive, chances are you’re going to benefit from React without having to use it yourself. My bet is many frameworks, possible even browsers, are going to use virtual DOM by default.

What’s New in PrimeFaces 5?

PrimeFaces 5.0 is going to be released any day now – most likely tomorrow (May 5, 2014). Çagatay Çivici, Thomas Andraschko and a few others invested a lot of work in the new version: The source code repository lists more than a thousand commits since the last version, PrimeFaces 4.0, which in turn has been released only half a year ago. So it’s time to look what’s happened since October, 3 2013.
Continue reading “What’s New in PrimeFaces 5?” »

AngularFaces 2: Even Better Steroids for JSF

Fork me on GitHubAngularJS and other fancy Javascript frameworks stir up the Java world. The Java world has been dominated by server side framework for more than a decade now. Times they are changing. Now everybody’s moving to the client side. The server’s reduced to a faint memory, such as a REST service.

Everybody? Not quite. A lot of developers want to steer a middle course. That’s AngularFaces for you.

By the way, the interest in AngularFaces is tremendous. The AngularFaces announcement has become the second most read article of beyondjava.net, being read a hundred times each day.

So I decided AngularFaces needs a strong grounding. You know, the first version hadn’t really been designed carefully. It just happened. Originally it was just a little experiment. Granted, it works fine, but it’s difficult to add new features to it. The second version is a complete re-write designed for the future. AngularFaces 2.0 has a lot of advantages over it’s predecessor.

And the nice thing about AngularFaces 2.0 is it’s already available as a preview version on GitHub.
Continue reading “AngularFaces 2: Even Better Steroids for JSF” »

Use Exceptions. Use’em Wisely!

The other day I’ve been reviewing another department’s code. Soon I was puzzled by the way they use exceptions. They use them very often and in unexpected ways. I examined a very small module, just a handful of classes, and the vast majority of the classes were exceptions. After a while it crossed my mind they followed an old style that’s come out of fashion for a good reason.

So I decided to write an article on how to use exceptions efficiently. In a way, this is a strange article: it’s a basic topic (actually a topic already covered by many, many other writers), but it’s not the newbies who do it wrong. It’s the old hands who walk into the trap.
Continue reading “Use Exceptions. Use’em Wisely!” »

Tweaking the Hot Spot Compiler’s Settings

A couple of days ago Chris Newland published two interesting articles. He’s looking at the JVM’s Hot Spot compiler settings, looking for possible optimizations.

Regular readers of my blog may remember I analyzed the JVM optimizations two years ago. At the time I found out you can help the optimizing compiler to get to speed, but it doesn’t matter on the long run. After 10.000 invocations methods are compiled to machine code, and after that there’s nothing left to optimize. However, if you happen to work on one of the vast number of algorithms that call methods frequently, but less than – say – 1.000 times, low-level optimizations may help.
Continue reading “Tweaking the Hot Spot Compiler’s Settings” »

AngularFaces Mentioned by Oracle’s Aquarium

It’s astonishing how much attention BeyondJava’s AngularFaces project gets. It has been mentioned in the November issue of the JSF central postcast – at a time when AngularFaces was a far cry from being mature. Last Thursday Reza Rahman mentioned AngularFaces in Oracle’s Aquarium (JSF + AngularJS = AngularFaces?).

I’m very pleased by your tremendous feedback. It’s a great motivation to carry on.

Just in case anyone of you is puzzled by the apparent lack of progress in the repository: progress is there, it just happens in another repository. When I wrote BabbageFaces – which basically was meant to be a small exercise – I noticed many folks in the JSF community want to reduce network traffic. BabbageFaces is nice, but it isn’t compatible to AngularFaces, and it won’t be.

So I decided to tackle the challenge from another angle.
Continue reading “AngularFaces Mentioned by Oracle’s Aquarium” »

How to Display PDF Files in the Browser

PDF files are very popular in web applications. They make it possible to deliver documents that can’t be easily tampered, and you know in advance how PDF documents look like when printed. That’s a major advantage over HTML page: printing an HTML page will almost invariably result in surprises. In many cases cross-browser compatibility – which is always a challenge – comes to a screeching halt when it comes to printing the page. You can avoid a lot of headache by simply using PDF files.
Continue reading “How to Display PDF Files in the Browser” »

Recent Improvements of Java’s String Implementation

Three days ago, I wrote an article about Strings in Java 8. I claimed they’d rewritten java.lang.String from scratch, supporting a 64 bit encoding that can be processed by the processor’s FPU. Of course, it was an April prank. So I was pretty surprised to learn there really are improvements of Java’s string implementation. They aren’t even subtle.

Java 7 Update 6 introduced a new implementation of java.lang.String that’s better suited for large numbers of Strings. As you may or may not know, the former implementation had been designed with optimizing the substring() method in mind. It was super-fast because it didn’t copy the characters of the substring. Instead it created a new pointer to the old String. Sometimes this prevents effective garbage collection, and it makes the intern() function extremely expensive.

So they opted to implement a new version that’s simpler. As a result of the new implementation substring() has to copy the character array. In the age of multi-gigabyte PCs and servers that’s more efficient than trying to save a few bytes.

In Java 7 they also abandoned 8-bit Strings. Now 16-bit Unicode strings are always used. That’s funny because it almost matches my April prank, where I claimed they abandoned the 16-bit character encoding in favor of 64-bit encoding. I wonder if java.lang.String makes use of the FPU?

Read the full story at Attila Balazs article on the state of strings in Java.

How to Write Your Own SonarQube Plug-In

You already know SonarQube, I suppose? If you don’t, don’t waste your precious reading this article. You’d rather have a look at their live demo first. Nemo shows the result of SonarQube’s analysis of quite a few popular open source projects.

But wait, I’d like to tell you what Sonar is about first. After that I’d like to tell you it’s possible to write your own Sonar plugin.

What’s it all about?

Sonar (which recently has been renamed to SonarQube) is an open-source1 tool to improve the quality of your code. In a nutshell, it’s a combination of three popular tools: Checkstyle, PMD and FindBugs. It’s a common user interface to the three tools, plus a great GUI on top. The GUI is where Sonar excels: Never before has it been so much fun to discover errors and faults in your program!
Continue reading “How to Write Your Own SonarQube Plug-In” »

  1. There’s also a professional version. See http://www.sonarsource.com/.

Java 8: Major Speed Boost by Overhauled String API

April 1st, 20141 2 Java 8 is out for a week or two now, and we all have been puzzled by the tremendous speed improvements of Oracle’s newest coup. String operations in particular have improved a lot. It’s time to look into the guts of Java and to analyze what’s going on.

Along the way, I also found out why Pattern.compile() has been deprecated in Java 8. Please stop using it. It’s a big performance penalty.

It took me a while to find out. Only when I looked into the byte code generated by Java 8, I realized what has happened. Oracle has overhauled its String implementation. Actually they have rewritten it from scratch. They need to retain the backward-compatibility, so it wasn’t that easy to see the trick: they abandoned 16-bit Unicode, replacing it by a more modern encoding. A major step to a more memory-efficient design! The Java community has been longing for this move since ages.
Continue reading “Java 8: Major Speed Boost by Overhauled String API” »

  1. Yes, this was this year’s April fool’s hoax.
  2. But read my follow-up article to learn about the real improvements of the string implementation.

Your IDE Supports Java 8 From Day One

Yesterday the lambda revolution has been released: Java 8 is there. Java programmers can finally benefit from closures, function pointers and multiple inheritance. Or rather, limited versions of these features that are almost as useful. BeyondJava.net has a series of articles on the topics (see method references, lambda expressions, functional programming and closures vs. lambdas). There’s even an interesting (and very unique) approach to type inference in Java 8: target typing.

For the first time in Java history each of the major IDEs support Java 8 from day one. In earlier times we had to wait roughly half a year until Eclipse supported the new version of the language. This time, there’s a feature patch you can install in Eclipse 4.3.2 (aka Kepler SR2). To install it, click “Help > Install new software”, enter the URL http://download.eclipse.org/eclipse/updates/4.3-P-builds/ into the “Work with” field and proceed the usual way.

According to netbeans.org NetBeans 7.4 also supports Java 8. And of course IntelliJ IDEA does: I tried it more than a year ago with a preview version of Java 8, and the IDE supported lambdas, method references and defender methods flawlessly.

An interesting question is the future of Java. Which impact will lambdas have on our programming style? Here’s an early assessment: when I write in other programming language such as Groovy, Scala or Dart, I use closures a lot. My programming style changes considerably. In general, programs become shorter and more readable. I doubt this will happen to Java. There’s no doubt Lambda expression fill a gap (almost a gaping chasm, to tell the truth). Framework programmers like me were suffering from not being able to pass algorithms as parameters to methods. This has become possible at last. Many features that have been solved by sophisticated approaches can now be solved by simple methods. For instance, until Java 7 you needed annotations and AOP to implement transaction in a decent way. With Java 8, a simple method does the trick just as well. Nonetheless, my first impression is Java will remain a non-functional programming language until Oracle adds more syntactic sugar to the language.

Angular 2.0: Courageous Plans

This morning the AngularJS team published their plans on AngularJS 2.0. Among lots of minor and major improvements there are two courageous ideas: AngularJS 2.0 is written in ECMAScript 6, a language that hasn’t been defined yet. Plus, they are dropping support for older browsers. The only browsers to be supported are evergreen browsers, i.e. browsers that update themselves automatically. This might be a dangerous decision: many companies are very reluctant to update their browsers.
Continue reading “Angular 2.0: Courageous Plans” »

Announcement: AngularPrime/Dart

Fork me on GitHubLast week I have begun to port Rudy de Busscher’s Javascript widget library, AngularPrime, to Dart. AngularPrime/Dart aims to take PrimeUI and AngularJS to another level. It’s going to simplify Single Page Applications considerably. The applications have the same look and feel as PrimeFaces or PrimeUI applications, have the simplicity of AngularPrime and of course the wealth of features of AngularJS. Or rather, the wealth of features of AngularDart, the Dart port of AngularJS that’s currently slightly more advanced than AngularJS itself.

At the time of writing I’ve finished half a dozen components.
Continue reading “Announcement: AngularPrime/Dart” »