Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

AngularFaces 2.1: Apache License V2, AngularJS 1.3 and much more

Yesterday, I’ve published what I hope to be the last release candidate of AngularFaces on Maven Central. Basically, AngularFaces 2.1 RC5 already is the final version. I only called it a release candidate I did a few last-minute changes. I felt the need to run more tests.

AngularFaces 2.1 offers many new features. Today, I’ll present four of them: the new license, AngularJS 1.3, first-class divs and the new AJAX support contributed by Marco Rinck.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

A Child’s Garden of Cache Effects

One of these days Joshua Bloch twittered a link pointing to “a child’s garden of cache effects”. Igor Ostrovsky demonstrates the effect of CPU caches using a high-level programming language, such as C#. Highly recommended!

When I read his article, I wondered if we can demonstrate the same effects in Java. At first glance, the odds are against us: Java isn’t compiled to native machine code, but to an intermediate byte code, which in turn may or may not be compiled to native machine code (depending on the circumstances). So, can we show cache effects in a Java program?

Yes, we can!
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

A Java Programmer’s Guide to Assembler Language

Imagine a programming language without variables. A language without function parameters and return values. A language without floating point numbers, maybe even without multiplication and division. A language without type casting. Without types, actually. Not to mention classes or objects. Join me in a journey to the world of assembler languages.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

BootsFaces 0.6.0 Now Available on Maven Central

Maven coordinates

BootsFaces – the JSF framework that makes Bootstrap much more accessible to JSF programmers – is now available on Maven Central. To use it, add a dependency to your Maven pom.xml file:

<dependency>
    <groupId>net.bootsfaces</groupId>
    <artifactId>bootsfaces</artifactId>
    <version>0.6.0</version>
</dependency>

Gradle users activate BootsFaces by adding this line to their .gradle build file:

compile 'net.bootsfaces:bootsfaces:0.6.0'

Minified version and debug-friendly version

The version I’ve uploaded to Maven Central is a developer-friendly version containing minified Javascript and CSS code, but non-minified Java class files. In other words: you can debug it, and you can easily identify the offending line if you find an error in your production log.

There’s also a version of BootsFaces that has been minified more aggressively. Currently, the smaller and slightly faster version hasn’t made it to Maven Central yet. You can download it at our project showcase and the project GitHub repository.

License

BootsFaces 0.6.0 is available both under a GPL 3 and a LGPL 3 license.

But I’m already using another JSF framework!

BootsFaces coexists peacefully with PrimeFaces, AngularFaces and probably most other JSF frameworks. For example, you can use the layout components of BootsFaces (<b:row>, <b:column>, <b:panelGrid>, <b:panel>, <b:tabView> / <b:tab> and <b:navBar>) together with the powerful input and datatable widgets of PrimeFaces.

Of course you can also use BootsFaces as a full-blown JSF component framework, providing responsive design and native Bootstrap GUIs. It’s up to you.

Kudos

BootsFaces is an open source framework initiated and led by Riccardo Massera. Thanks to Riccardo, Emanuele Nocentelli and everybody else who contributed! This includes everybody who gave us feedback by reporting errors or feature requests by opening an issue on the GitHub repository. Your feedback matters!

Wrapping it up

Visit our project showcase and enjoy!

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Programming Over Convention Over Configuration?

The Java community moved to a new paradigm during the last five years, and nobody talked much about it.

Act 1: Programming

When I entered the enterprise Java world, every programmer did what was expected from them. They wrote programs.

Act 2: Configuration over Programming

Enter Spring. Or EJB before version 3.0, for that matter. Programming – they said – is bad. It’s OK to write small modules, building blocks of your application that can be glued together. But the glue code needn’t be code. It’s better to adopt a declarative programming style. Design configurable modules, and configure them in XML. That programming model has great advantages: you can replace modules by different module as seems fit. Configuration gives you a big boost of productivity.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

A Quick Guide to Writing Bytecode With ASM

My previous article gave you a short introduction on reading Java bytecode. Now let’s do it the other way round: today we’re going to write bytecode ourselves.

So grab your hex editor and get prepared to type endless sequences of cryptic numbers!

Wait – that’s not how we’re going to do it. Actually, I’m mostly interested in showing you the general idea. We’re going to cut a couple of corners. We’ll add code to an existing method of a class on your hard disk. And we’ll use a framework that does the hard work for us. You don’t have to download a hex editor. The Java class file format is a bit convoluted, so editing a Java class in a hex editor isn’t too much fun.

Observe the difference between a high-level language like Java and a low-level language like Java bytecode or assembler. Bytecode programmers have to think a lot smaller. A single line of Java code can translate to half a dozen bytecode instructions. Remember the for loop of the previous article: Depending on what you count, it consists of five to eight instructions. Programming in assembler is even worse: a single high-level instruction can trigger thousands of machine-code instructions, especially on older CPUs. Which in turn also means that high-level languages tend to be slow. They do a lot of things that could be streamlined in assembler. But nowadays hardly anybody wants to pay the price: your program may run faster, but you don’t program it quickly. The effort only pays in special areas such as games and hardware drivers.

Apart from showing you the different state of mind you need to adopt to program in a low-level language, the article also shows you how to get started with the ASM library. I picked a very small task: modifying a method of a class at runtime.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

A Java Programmer’s Guide to Byte Code

It’s funny how this article came into being. I only wanted to write about such a simple thing as how CPU caches influence Java programs. But then, I couldn’t help but notice the topic isn’t quite as simple. Simple to me, who has written lot of assembler code (granted: decades ago). But many Java developers – actually, most Java programmers I know – don’t know much about things like CPUs, registers, let alone caches and out-of-order-execution, which play a crucial role in my article. So I decided to write an article explaining assembler programming to Java programmers. But the most simple approach to Java programmers is the HotSpot compiler, which in turn deals a lot with Java byte code. That became article number three, the article you’re reading.

So I ended up with three articles. You’re lucky: three article for the price of one!

Four articles, actually. I started to investigate how to write byte code, and wrote an article about it. Another interesting topic is what the JVM does to optimize your code on the fly, and how you can watch it. But this article has yet to be written.

Today I’d like to start the series with a short and cursory instruction to Java byte code. I’ll tell you what byte code is, how to see it in your editor and how to read it. But it’s not a text book: I’ll try to bring you to speed fast, which means the article is exhausting, not exhaustive. You can read the text books later. This article is about getting the gist of it.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

How to Make Your WordPress Blog Fast

Many bloggers know the problem: at first, their WordPress site is fast. After a while it starts to get slow. The same happened to BeyondJava.net. Time to do something about it. I didn’t want to wait until the Google rankings began to drop.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Newsflash: BootsFaces 0.6 released

Yesterday, BootsFaces 0.6 has been released. You can download it at the BootsFaces documentation pages.

Among other things, there are six new components (checkbox, combobox, panel grid, tab and a password input field). BootsFaces now is compatible to both Oracle MyFaces and Apache MyFaces 2.2. The next version 2.1 of AngularFaces will also support BootsFaces (and vice versa).

BeyondJava.net will report about BootsFaces in more detail soon. By the way, I (Stephan Rauh) joined the BootsFaces team recently, so I can give you first-hand informations about the project.

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Happy New Year 2015 – the Year of the Palindrome!

You readers rock!

In 2014, BeyondJava has been read more than 400.000 times. That’s 400.000 reasons to carry on.

What’s in score for you in 2015? Time will tell… but there are a few articles I’ve already prepared, so I can pique your curiosity. BootsFaces 0.6 has just been released, so it deserves an article or two. Soon I’ll release AngularFaces 2.1. That’s the first version of AngularFaces that has extensions specifically for BootsFaces. JSF will remain a hot topic, as well as AngularJS and AngularDart. I’d like to write a couple of philosophical articles. “How to Abuse a Framework” is the working title of one of those articles.

I’m also preparing a series of articles dealing with how the JVM works. Did you know your Java program is compiled to machine code – sometimes, that is? Did you know how to read and analyze this assembler code? Did you know which optimizations the JVM performs? Stay tuned!

Maybe I’ll also include articles about WordPress. That’s the platform of this website, so I’ve learned a lot how to do thing and how not to do things. During the last couple of days I’ve started to make the website faster again. Chances are I’ll write an article about how to optimize WordPress performance.

Oh, just in case you didn’t read the geeky part of Twitter: 2015 is a palindrome. Written as a binary number, it’s 11111011111.

Welcome to the year of the palindrome!

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Newsflash: Generate Random Test Data With jPopulator

Writing unit tests is hard work. Much of the hardship is preparing the test data. In my daily work life, I often deal with large business objects you can’t really mock. Refactoring might help, but it’s not an option: I don’t own the data structure.

I encountered this scenario more often than not, so I suppose it’s a scenario familiar to most of you, too.

Another difficult scenario is load and performance test. Wouldn’t it be nice to populate the database with thousands or millions of records to see what happens to the performance?

jPopulator comes to the rescue. jPopulator is a small framework written by Mahmoud Ben Hassine” (together with a couple of contributors).

The nice thing about jPopulator is it deals with complex data structures. The example on the jPopulator GitHub page consists of four classes, related to each other by 1:1 relations. I didn’t try the framework with other test scenarios yet, but judging from the source code jPopulator also supports much more complex data structures. Be that as it may, even writing tests for those four classes is a pain if done manually: they consist of 15 attributes that have to be filled.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

AngularJS: What About Adding ng-type?

I found an interesting search keyword in the visitor statistics: ng-type. Looking at the AngularJS doc, you’ll never find ng-type. Every input field they show uses the plain old HTML attribute type.

Introducing ng-type adds the option to change an input field’s data type dynamically. Why hasn’t ng-type been added to Angular?
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

The Double Curly Braces Idiom – a Poisoned Gift

Lukas Eder has an interesting story: The popular double braces idiom is a poisoned gift. It causes memory leaks.

Let me start with a quick note on my article. Originally, I simply wanted to provide a link to the article written by Lukas. However, there are several points I disagree with him. You need some background to understand my contradictions, so I ended up with an article that covers almost the same story as the original article. That said, I recommend to read The Double Curly Braces Anti Pattern as well as reading my article. There’s a lot of shared content, but there are also differences.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

How to Modify JSF Library Load Order

Why ordering matters

Every once in a while it’s important to control the order in which JSF libraries are loaded1. For instance, loading the LiferayFacesBridge 6.1 before PrimeFaces 5.x breaks the AJAX features of PrimeFaces. Both libraries replace the same Mojarra or MyFaces base class by their own, improved implementation. Unfortunately Liferay doesn’t cope with the implementation of PrimeFaces. Loading PrimeFaces first fixes the problem.

There are many more examples. JSF libraries such as OmniFaces, AngularFaces and BabbageFaces don’t provide widgets. Instead, they modify the way JSF requests are processed2. Those processors stack behind each other like a pipeline. It’s easy to imagine situations in which the reordering the pipeline makes a difference. For instance, it’s important that BabbageFaces is the last stage of the pipeline: it optimizes the HTML code generated by the previous stages.

This article shows how to modify the load order of JSF libraries.


Continue reading

  1. more precisely: the order in which the libraries are configured and activated. However, the difference isn’t important for this article, so I’ll stick with the more common notion of “load ordering”.
  2. At this point, I deliberately oversimplify things a bit to keep language simple
Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Build Your Own Dependency Injection Framework!

Let’s bust a myth. There are very good reasons to use CDI or Spring, but dependency injection isn’t one of them. There are a lot of alternatives. And I’m not talking about Google Guice, although that’s a very fine DI framework indeed. Why don’t we write our own DI framework? Can’t be difficult, can it?

It’s true: today’s open source libraries make writing your own DI framework incredibly simple. But even without such a library writing a DI framework isn’t difficult (at least if you’re ready to learn something about class loaders). I’ll develop a sketchy DI framework in this article. In theory, you could finish my work to implement a full-blown DI container and put it into production. Even if you don’t, you’ll understand how CDI and Spring work after reading this article.

But first I’d like to present you an alternative you’re probably not aware of.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Newsflash: OmniFaces 2.0 released

OmniFaces 2.0 has been released today (Nov 24, 2014).

What is OmniFaces?

For those who don’t know OmniFaces yet: OmniFaces is… different. It’s a JSF library that doesn’t focus on providing GUI widgets. Instead, it integrates into your existing JSF ecosystem and adds functions lacking in JSF. OmniFaces 2.0 offers 90 components, give or take a few, most of them dedicated to non-GUI components. My favorite OmniFaces features are the CombinedResourceHandler, which accelerates the delivery of most JSF pages tremendously, the SelectItemsConverter which makes JSF comboboxes a lot less scary and the FullAjaxExceptionHandler, which make exceptions occurring during an AJAX request visible.

What’s new in OmniFaces 2.0?

Many things. In this article I’ll focus on two interesting new features: Bean validation at class level and simplified display of images.

JSF 2.0 added support for the Bean Validation API (aka JSR 303). Sad thing it didn’t support the API completely. Neither does the current version, JSF 2.2. To fill the gap OmniFaces adds <o:validateBean />. Among other things, this allows you to implement cross-field validations. Add <o:validateBean value="#{myBean}"> to your form to have the bean validated. In my opinion, this solution still doesn’t fulfill the promise of JSR 303 (which says a simple annotation to the class does the trick), but to be fair, it’s not easy to meet the requirements of the JSF lifecycle. The JSF specification requires that invalid values are not written to the bean. Therefore framework developers have to copy the bean to implement things like class level or cross field validation. By this measure OmniFaces does a pretty good job. Read the full story here.

Have you ever tried to display an image stored in a database? That’s one of those things that are simple using basic servlets, but horrendously difficult using JSF. <o:graphicImage> saves you from learning about ResourceHandlers. All you have to do is do define a CDI bean returning the image as a byte array:

@Named
@ApplicationScoped
public class MyImage {
    public byte[] getImage() {
        return /* the image as byte array */;
    }
}
<o:graphicImage value="#{myImage.getImage()}" />

See more details explanations and examples at the OmniFaces showcase on o:graphicImage.

Increased requirements

Talking of which – yes, I said you need a CDI bean, and I meant it. OmniFaces 2.0 requires Java 1.7, JSF 2.2, EL 2.2, Servlet 3.0 and CDI 1.1. Spring users have to stick with CDI 1.10. The good news is OmniFaces is going to supports the 1.x branch for a while, but they don’t intend to implement the new features into the 1.x branch.

Dig deeper

OmniFaces 2.0 released! by Arjan Tijms
OmniFaces 2.0 released! by OmniFaces lead Bauke Scholz (aka BalusC)
OmniFaces showcase

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Does Your Programming Language Influence Code Quality?

These days Twitter had a couple of interesting tweets about programming languages. Which one is the best one? According to the tweets the question has been settled:


(click the image to see the original tweet)
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Eclipse Compiler Surprises

I guess you know exactly what the class file of this Java source code looks like:

public class MyClass {
   public void myMethod() {
     I do not compile
   }
}

You don’t have to know anything about byte code to know this class doesn’t compile. Asking for the byte code is a moot point: obviously there’s no class file. Let’s have a look at the binaries folder, just for the fun of it:

Oops. Eclipse does a clever trick: it generates class files of invalid classes.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

AngularJS 2.0: Sneak Preview on Data Binding

The AngularJS team presented a straw-man’s proposal for AngularJS 2.0 syntax one or two weeks ago. According to the proposal, AngularJS 2.0 is going to look substantially different from what we used to consider Angular, and nothing shows this better than the overhauled core of AngularJS: data binding. It’s a fresh new take on AngularJS, or, like Cagatay Civici tweeted, it’s almost like a new framework that just happens to have the same name.

He isn’t the only one to think so. Developers protested against the changes, and soon discovered several issues with the syntax. This article shows the original ideas nonetheless – I consider them interesting, even if they’re likely not to come.

Evolving W3C standards open new opportunities

So they decided to make a new start, dropping compatibility to AngularJS 1.x. And why not? I suppose the Angular team learned a lot about HTML and Javascript along the way, so they now know how to make things better. Who might have envisioned the flexibility of HTML concerning attribute names? Back in 2000, valid HTML attribute names were basically characters, digits, underscores and colons. By 2009, the W3C organization had added a lot of flexibility. Now, almost every Unicode character can be used in attribute names – this even includes Chinese and Devenagari characters (such as क्तु):

<div myAttribute[index] = ""
     ^[myAttribute]     = ""
     seño(ra|rita|r)    = ""
     क्तु                 = ""
     你好               = "">

AngularJS 2.0 makes a lot of use of this flexibility. The team invented a new system of data bindings that’s more logical than the previous system. It uses special characters to distinguish between different types of attributes. We learned from several Scala frameworks that ran havoc that using special characters tends to be a bad thing because special characters don’t do much in the way of explaining their meaning. I hope the AngularJS team has learnt the lesson and uses special characters carefully and sparsely. Changing the data binding syntax and dropping compatibility is a bold decision that may or may not work out. However, the current drafts look fascinating enough.

Update Nov 23, 2014

During the last couple of weeks the AngularJS team dropped the idea of using special characters. There were many obstacles: using special characters may be valid HTML, but that doesn’t mean browsers can deal with them. Even worse, many third-party tools don’t cope with special characters. However, it’s clear that the syntax will change. At the moment, there’s no agreement on the new syntax, so this article sticks with the straw man’s proposal. The details may change, but the ideas remain the same.
Continue reading

Privacy note: BeyondJava stores cookies in your browser to keep track of your visit (for statistical purposes). You can disable tracking on the privacy declaration page.

Newsflash: BootsFaces Now is Open Source

The BootsFaces team have published the source code of the BootsFaces JSF library on GitHub.

BootsFaces is a JSF widget library that translates Bootstrap code to a dialect more familiar to JSF programmers. For instance, a navigation bar is written like so:

<b:navBar brand="Brand" brandHref="#" inverse="true">
    <b:navbarLinks>
        <b:navLink value="Home" href="#"></b:navLink>
        <b:navLink value="Link" href="#"></b:navLink>
        <b:navLink value="Link" href="#"></b:navLink>
    </b:navbarLinks>
</b:navBar>

Source code and screen shot copied from the Bootstrap documentation.

This converts to the NavBar component familiar from many Bootstrap pages:

BootsFaces offers widgets for the basic tool set of web applications: apart from the NavBar there are menus, panels, buttons, button groups (aka tool bars), input texts, date pickers, modal dialogs, sliders and several more. While the tool set isn’t complete yet, the BootsFaces project seems to be very active, so chances are missing components such as check boxes and combo boxes (aka editable drop down menus) are added soon. In any case, it’s possible to use a standard JSF check box and use some CSS to align it with the bootstrap look and feel, so this shouldn’t be to much of a problem.

At first glance, BootsFaces seems to be an interesting framework for everybody who wants to use both Bootstrap and JSF.