Skip to content
accelerando

#Java20

24-May-15

Blogcake

My part of 20 years of Java spans at least 12 years and started somewhat in 2003.

I was hired after my apprenticeship and university by ENERKO Informatik where i still work. ENERKO back then was a totally Oracle shop, Oracle Database, Oracle Case and Designer and Oracle Forms, so no wonder that my first “own” project at the end of 2002 was a Forms 6i project.

I did some Java in university, but not much. My studies took place in FZ Jülich, we learned Fortran 90, C and some C++. What i see from Java Back then was slow, clumsy and after all, complicated .

Back at ENERKO, my Forms project went really well (actually, it was just replaced by a Vaadin application 3 weeks ago, more than 10 years in production oO). I remember my boss coming to me, drawing some lines on a paper, it must have looked something like this:

ihl

The black dots and lines are power rods and power lines and the “parallel” grey ones are the “right of the way” along the route. Question was, if I could image computing the right of the way and also display it in some way, preferable in SVG (someone else suggested that).

Thats where i really started digging into Java. Computation was easy and parts of the original algorithm are still alive. First application was a ugly, hacked together Swing thing with Apache Batik used for display SVG. It was awful, but it work.

I took a first Java course at trivadis to get Swing (and AWT, does anyone remember that?) right and things got slightly better. SVG didn’t work out for us and thus our Swing based Graphic Framework for drawing arbitrary things came into life (pretty much everyone created them at their first OO course, or?) which is still used today. My colleague Andreas did a great Job since 2010 getting new features into it and preparing it for the future.

I’d love to show some screenshot, but it’s a customers project. TransnetBW GmbH and Netze BW use it for nearly a decade now to support projecting their power grids (mainly 220-kV and 380-kV).

What i could used to was hearing “Java and Swing” is slow over and over again. Yes it was slow, not it isn’t slow anymore. And thats just it. It works really, really well.

IDEs. I wrote a lot about them in my NetBeans testimonial. Back in 2004 or so, Eclipse was my preferred tool and still i must say, kudos to all the Eclipse developers. I certainly cursed a lot over Eclipse, but in the end, it always did the Job get done and helped me a lot develop my skills.

Web development: Had my first Homepage by the end of 1999 and boy, i was so proud of the file based guestbook i had. Having so much success doing the Swing stuff i thought how hard could be doing Java for Websites, wasn’t that the stuff all those skilled developers where doing? Turned out, it could be very hard.

I remember a lecture i had taken by a pretty different Adam Bien. Comparing his patterns and suggestions from back then to the stuff he’s doing now is worlds apart.

It must have been 2004 by then and we as a company where struggling with the end of life for Oracle Forms 6i. Going to the DOAG yearly conference it was all about Jdeveloper, Oracle Forms 10, application servers and such. It seemed nobody had a clue. All that XML, configuration, configuration and then some… I struggled with Struts, J2EE 1.4 and lost. I really concentrated on the Desktop with Java and that paid very well for me.

In 2005 i started Daily Fratze, PHP then Ruby on Rails based. Had a look at Java, but didn’t want to go down the painful way of more config than code. Ruby on Rails was enlightening in December 2005. That was what i wanted to do for the web.

I never stopped using Java, quite the opposite. I even became an SCJP with a score near 100% in 2008, but in 2011 i heard old and tired regarding Java and i somewhat could relate.

Months before that my frustration with Java and the Web ended with me having a look Spring MVC again. I’m stubborn and i wanted to make that work for me. And so it did. Spring has been in my portfolio since the end of 2010 and helped a lot getting Java fun for me again in that time.

Everything that happened for Java and me after that time was just great. I did Java on the Desktop, Server, Middleware and even inside databases. Maybe it was always “write once, run everywhere” but it was “learn once, run everywhere”. We at ENERKO have proven that one can do a full blown GIS system nearly 100% Java. I’ve written several web facing Java based sites that run without a hickup for months.

Actually, i used a lot of programming paradigms, languages and tools the last years, but i’ve alway came back to Java and with all good relationships, it has seen all sorts of high and lows. At the moment, Java and i are at an all-time high. Since Java 8 the language is just great, i learned a lot about functional programming (which maybe doesn’t look as fancy and cool as in other languages, but so what?) and did some great things (some you find at that blog here).

The solutions I create with Java are paying my bills and are even fun to create, but the best are the people that are part of the Java ecosystem. So many kind and brilliant people. All sort of. People creating great IDEs, libraries that are useful in every day usage or people that are just fun to talk to and discuss with. Thanks to all of you.

Cheers to you, Java 🍻, onto the next twenty years:

2014-09-30_big

Change of perspective: A NetBeans testimonial

23-Apr-15

This post is long overdue since JavaOne 2014. I’m not getting payed for it, it’s more a thank-you to the whole NetBeans team for bringing some fun back into my everyday coding life.

I’ve been an Eclipse user for a long time, i think way back 10 years ago when it didn’t have a name but only version numbers. Back in 2005 it was for us the only real viable Java IDE around. I remember NetBeans as pretty much unusable for us back then and IntelliJ too expensive. Eclipse felt native, fast and actually, intelligent supporting our development.

What we never did was platform development on either Eclipse or NetBeans.

Back then we often had the problem, that some projects were only deployable from the IDE. Or worse: From one developers IDE. Came ANT, things changed for the better, came Maven (downloaded half of the internet) things got even better. Today i wouldn’t touch a thing that is not build able with standard command line tools. I’m actually a big Maven fan, but Maven and Eclipse relationship has been complicated, at least to say, but I made it into a requirement that every productive project or module should be buildable by maven. Having that, we ran into a lot of problems with M2Eclipse over the years, it never was fun. Also updating any installation of Eclipse is a sad thing. Sometimes it works, more often not.

Anyway, we did great stuff with it and with Spring Tools Suite appearing somewhere in 2011/12 for me many problems with Eclipse vanished with the nice pre bundled stuff.

By the end of 2013 i was (and actually, i still am) pretty bad frustrated by project that involves a framework I prefer never ever touching again and some AspectJs that repeatedly crashed *only* in the IDE.

Looking for something relaxing, inspiring i aimed for a clean and simple Java 8 project and i ended up with this. By February / March 2014 the only IDE offering good Java 8 support was NetBeans 7.4 and in March, NetBeans 8, so choosing a new IDE was pretty easy.

Not wanting to change everything, that was one of the first steps:

keys

Setting the profile to “Eclipse” allowed me to keep my old habits regarding shortcuts, navigation and stuff. By now, I’ve switched to the NetBeans profile.

Working out of the box is the great Maven support. Without adding anything to a project (apart from a project specific settings file), everything works as is. Didn’t have any problems regarding lifecycle management or a plethora of additional xml files per dependency like IntelliJ creates. Great.

Learning: NetBeans did help me (and now my coworkers) to get my head around Java 8 lambda expression and basic use case cases:

learn1

into this

learn2

Pretty basic, sure, but everybody needs a starting point and replacing anonymous inner classes is an immediate win.

Some day i was rewriting a complex computation and i discovered “Use functional expression” hint. I didn’t expect it to work as the variables used weren’t effectively final but NetBeans pretty much did something like this:

learn3

The Reduction was actually way more complex than this. I was pretty sure that this was working because I had written tests and already added the JaCoCo Maven plugin which is detected by NetBeans and ensures me that everything is green as described here.

Speaking of code quality: I actually like the NetBeans code formatter, adding curly braces for every branch of control flow and so on. I guess one of the only things i’ve changed are spaces to tabs (yes, i use tabs. I want semantically correct empty space, not spaces).

JavaDukeTeach_larger (Image from Coding Dude) More teaching and learning: NetBeans has an excellent build-in HTML, JS and CSS editor and all of them work hand in hand. The HTML editor proposes CSS classes the platform finds in css files in the projects, as does the JavaScript editor. The later knows about AngularJS functions, attributes and more. Some of my coworkers always look for WYSIWYG editors: I didn’t even bother, i’m way faster with that kind off assist and i learn stuff with it. Also, the pom editor: It completes group and artifact ids and also suggest the most current version. If i do need a GUI editor (for example creating FXML files), NetBeans knows how to call JavaFX scene builder.

The power of content assist also shines with the nb-springboot-configuration-support, which is demonstrated by Geertjan at Oracle.

Other things i’ve used repeatedly: The very fast local history, the ability to restore unversioned files from local history and fast file compares. Fast navigation between classes and corresponding test classes and certainly the good Git integration.

I’ve encountered only some minor problems so far: Sometimes my installation hangs during download of JavaDoc for whatever reason i don’t know. There seems to be a problem with Java 8 parameter names sometimes, but for the last year no bigger deal.

We at ENERKO have used NetBeans 8 through 8.0.2 for the last year creating two successful Spring Boot projects in the energy / commodities market. One an AngularJS application and the other one a traditional, server side rendered Java project. There’s wast knowledge around another Oracle product in our company, namely Oracle Database, but not that much modern Java web stuff, so being able to teach without distraction by tools was essential.

NetBeans IDE helped me a lot learning and teaching modern Java technologies without wasting time on configuring, explaining build failures due to configuration errors etc. and instead concentrating on stuff that actually matters to us: Creating great software. Reducing unnecessary complexity in tooling is an invaluable asset for modern software development.

So, the change of perspective brought by changing our main IDE changed actually more than an IDE.

(By the way, another great application based on the NetBeans platform is the Oracle SQL Developer, useful not only for Oracle databases but for many other databases with JDBC connectors.)

First talk at EuregJUG Maas-Rhine: “Building Modular Java Applications in the Cloud Age”

20-Apr-15

May i bring the first talk at the newly founded EuregJUG Maas-Rhine to your attention: “Building Modular Java Applications in the Cloud Age” will be held by @bertertman on Thursday, May 28th, 2015 at BitStars HQ, Hanbrucher Str. 40 in Aachen:

talk-poster-2015-05-28

Would be great to meet some of you, i really hope we get this JUG going. Thanks a lot to Stefan Pfeiffer aka @dl1ely for all his engagement, i’m happy to be part of it.

What’s the fuss with Java 8 Optional?

15-Apr-15

I’ve been asked several times lately by colleagues what the Optional<T> is good for, so today some more basic stuff.

You can use the Optional class is as an elaborate null check like

  Optional<String> optionalString = Optional.ofNullable(someString);
  if(optionalString.isPresent()) {
    String string = optionalString.get();
  }
 
  // Or worse
  // String string = optionalString.orElse(null);
  // null check here

but most of the time, a computed value based on a possible null input value is much more interesting. Here comes map and flatMap.

If the optional value is present, map is used to compute a new value (which is turned into an optional), flatMap has the same purpose but is meant for computations that already return an Optional, otherwise you would end up with an Optional<Optional<T>>:

// Compute the length of a string which could be null
int length = Optional.ofNullable(someString).map(String::length).orElse(0); // Which value is used as default is surely debatable

Here’s a real world example from biking. Spring framework supports Optional request parameters and path variables since 4.1, so i can write a controller method that takes two optional range variables (start and end) like this:

I can use these two parameters to filter a map containing LocalDates as keys without null checks like so:

bikes
    // Stream the bikes 
    .stream()
    // and flatMap (concat) their periods into a new stream
    .flatMap(bike -> bike.getPeriods().entrySet().stream())
    // we're only interested in periods before 1.1 of the current year
    .filter(entry -> entry.getKey().isBefore(january1st))
    .filter(entry -> {
	final int year = entry.getKey().getYear();	    		
        // No need for null checks, the optional parameters are mapped to booleans
        // if the values are present, check if the current year is after start respectivly before end
        // otherwise the interval is open and i can map them to true
	return yearStart.map(v -> v <= year).orElse(true) && yearEnd.map(v -> year < v).orElse(true);
 
        // Using possible null values the the filter would look like
        // (yearStart == null || (yearStart <= year)) && (yearEnd == null || (year > yearEnd))
    })

Now, it’s actually debatable which expression brings the intention more clearly, but i like the fact that i just can use the parameters as is.

Another interesting Optional method is filter. It takes a predicate and turns a non-empty optional into an empty optional if the predicate doesn’t match. I use it for example for an “default if blank string method”:

/**
 * Returns {@code defaultValue} when {@code value} is empty or blank.
 * 
 * @param value A string
 * @param defaultValue A default value when the input string is empty.
 * @return value or defaultValue
 */
public static String defaultIfBlank(final String value, final String defaultValue) {
    return Optional.ofNullable(value).filter(Strings::isNotEmpty).orElse(defaultValue);
}
 
/**
 * @param value Value to be checked if empty
 * @return True if trimmed value is not empty
 */
public static boolean isNotEmpty(final String value) {
    return !value.trim().isEmpty();
}

Do you have interesting use cases for Java 8s Optional?

Destroying what you love to do…

14-Apr-15

This is probably gonna be an exceptional personal post.

I love coding. I live and breath this. My mind is a bastard, it seldom sits down and does nothing. There are endless possibilities out there, coming to it through my wonderful timeline, blogs, reddit and more. New technologies i want to learn, new things i want to try out. I often have this feeling that Fabian pointed out:

Also, isn’t it cool, getting up as early as possible with lots of ☕️☕️☕️ and pulling all-nighters, either private or at work? I mean, all the rock stars are doing it.

Lately i’ve found myself in the weird position of being Prokurist in a small company doing many other things than coding and at the same time drowning in stuff that just “needs to be done” because no one else cares or is able to do, or tasks which are merely a draft on a whiteboard (if any).

Then there’s is this thing: I’m turning 36 this year and more and more, I’m feeling like having a bad midlife crisis since about last year which i don’t want to smother by buying stuff or pouring alcohol down my throat. I’m struggling to put myself in a position where i have the feeling to stay relevant in geezer town.

And first and foremost, I am a father of two great kids. I don’t want to be one of those parents who barely sees their kids. I’m so happy and proud that we have a great relationship and i want it to stay that way.

I got this email recently from a person i only met years ago on the internet, telling me how impressed he is with the stuff i’ve achieved and how he is wondering from where “persons like me” (whatever that is) take the strength to manage all this.

Honestly, i don’t know. When i’m with my family or creating stuff for dailyfratze.de or the various parts of my biking project i feel great. I also feel great doing housekeeping with my wife or dull work at work, but more often than not, at the times where there isn’t stuff to do, there’s no rest for me. Feeling physically and psychically exhausted, my brain keeps wandering.

Often those professional achievements are not a result of too much strength but from an imposter syndrome. The mere facts should and do tell me that i am good at what i’m doing, but even at the age of nearly 40 i have a hard time believing it and one of the ways i’ve “learned” to prove this to myself is just being better, learn more, do more.

So, why this posts title? I need to reduce the amount of coding that leaks into my life. Dramatically. I want the weekends to feel like weekends again, not just like any other week day. The most effective (and probably also the most efficient) way for me to stay relevant is doing less, not more. Do i want to define myself as an overworked coder, pouring coffee (or what ever else legal drug is available) or do i want to be a father of a family and software craftsman doing the right stuff?

My twitter bio says “Father of two, Husband, Geek, Programmer, Biker.” for about 2 years now. It’s about time to order those priorities in real life that way again.

How do you set your priorities? Which persona do you want to be? Is your online persona much different than your real life self? Really, i’d love to hear from any of you.