Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Why Java Desktop apps are better

Since I've been spending so much time with Microsoft Word lately, I decided to upgrade to the latest versions yesterday. Here's where products like IDEA really shine. If I buy a copy of IDEA, I get a copy for Windows, Linux and OS X. It's written in Java, so it's easy to create versions for different operating systems. I imagine it's just a matter of packaging each install differently.

So I went to CompUSA and had to buy 2 copies of Word - one for Windows and one for OS X. That's bullshit - I should only have to buy one software package. Oh well, it's already paying off since Word on Windows hasn't crashed yet.

Posted in Java at Aug 16 2004, 10:47:58 PM MDT 11 Comments

log.debug vs. logger.debug - which do you prefer?

This is probably a bit of a religious debate, but it can't hurt to ask. Do you prefer to use log.debug() or logger.debug() in your Java classes? A fair amount of open source projects use Commons Logging and many of them seem to use logger. Personally, I prefer log (esp. b/c it's shorter), but I'm willing to change based on what the community (particularly AppFuse users) prefer.

Here's another tip I learned today. I typically declare a log variable for each class, such as this one in BaseAction.java:

    protected static Log log = LogFactory.getLog(BaseAction.class);

A better design can be found in Spring's DaoSupport classes. They have a logger variable that all its subclasses can use - eliminating the need to initialize a log variable in each class.

    protected final Log logger = LogFactory.getLog(getClass());

Obviously this is cleaner than AppFuse's current design - so I'll be changing it for 1.6. Any reasons why I shouldn't?

Posted in Java at Aug 16 2004, 09:47:58 PM MDT 21 Comments

OmniGraffle

I've seen OmniGraffle diagrams show up in a blog entry and and an article in the last week. Both diagrams show how OmniGraffle can produce high-quality, professional looking diagrams. The best part is that (I believe) it comes out-of-the-box with OS X. I seem to remember deleting it off my hard drive a while back b/c I didn't know what it was for. After seeing these sites, and realizing what OmniGraffle can do - I'll be searching through my Panther CDs in hopes of finding it. Anyone know where it's at and what version it is?

Posted in Mac OS X at Aug 15 2004, 04:25:01 PM MDT 6 Comments

August Status after two weeks

It's been almost 2 weeks since I set out to make this a month to remember. My progress so far? I'm behind. I put in 60 hours in front of the computer last week and 70 this week. Here's the break down of where I spent my time:

  • Current Client: 80 hours
  • Raible Designs: 27 hours
  • AppFuse: 7 hours
  • Spring Live: 16 hours

You can see where the problem lies - in the time spent on Raible Designs stuff. This time was mostly due to fiddling with the new monitor and 17 hours on Monday trying to get Radeon DVI cards working on Linux. I guess I like thumping my head against the wall. The time I spent on Spring Live was doing editing for Chapter 6 and coding for Chapter 7. I was hoping to have Chapter 7 done by today, but that's not gonna happen - so I'll be working tomorrow and taking off Monday to try and it finish up.

My original goals for this month were to finish Spring Live and release AppFuse 1.6. For Spring Live, I still have to write 2 more Chapters after Chapter 7. That's 1 chapter next week and 1 chapter the week after. Yeah right. Chapter 6 took me the entire month of July and Chapter 7 has already taken me 2 weeks. I'm still hopeful I can come close to pulling it off. The problem is that I never account for editing - and that seems to take a few hours per week once I've turned a chapter in. Worst case, Spring Live 1.0 will be released in late September. This might happen anyways since the editing for the ERP took 3 weeks and I'd like to fix all the issues found in the first 5 chapters. Fixing issues will probably take a day since I need to setup JIRA, enter all the issues, and then proceed to make sure they're fixed.

As for AppFuse 1.6, I think the WebWork integration should only take a couple of days. But that's 2 solid days. The other big issues involve a lot of XDoclet hacking and modifying, so that's probably another day there. Give it another day for various other bugs and one more for documentation updates/tutorial writing - and I'm up to 5 days. Yet this is still possible too. My current contract is scheduled to end when the baby is born, but I think I'm going to end it on Friday, August 27th. This gives me the next week to work on AppFuse - if the baby doesn't come. The baby is due on Friday, September 3rd.

The interesting thing about this week over the last was it was a coding week for Spring Live. When I write code, I prefer to have no deadlines - so I do it at night. If I did it in the morning, I'd have to quit coding around 8 and start my day job. By doing it at night, I'm pretty much giving myself the whole night to get stuff done. I've gone to bed b/w 3 and 4 every night this week. My problem is that I then sleep in until 9 or so. When I write, I find it's easier to get up in the morning, with a clear head and go to it. It's going to be tough making the transition from going to bed at 4 to getting up at 4. The good news is that I'm not just letting my body go to shit like like last time, I've actually been exercising. I feel great, but my fingers are starting to cramp from typing so much.

NOTE: If Julie goes into labor anytime in the next 3 weeks, all bets are off. ;-)

Posted in General at Aug 14 2004, 12:36:29 PM MDT 4 Comments

Tom McQueeney's Blog

What happen's when you're a Java Developer and your wife is a kick-ass designer? You end up with a rockin' Roller theme. Tom McQueeney is DJUG's President and his wife, Renee, is an awesome designer. Not only that, she's a Sun Certified Enterprise Architect. Tom and Renee, this site looks incredible - I especially like how the "blog" part of it is just another page and it looks so seemless. Tom's personal site looks a lot better than many corporate sites I've seen.

Posted in Roller at Aug 13 2004, 12:52:50 PM MDT 1 Comment

This site crashes a lot

It's plagued me before, and now it's back again. When I go to sleep at night, this site crashes. I've been up until 4 lately and it still seems to wait until I fall asleep. In fact, my 500 page is my top referrer this month. That's not good. The problem is probably not Roller - since JRoller seems to stay up and humming. Although it does die, I do have somewhere around 30 open database connections.

The truth is I need to run a profiler and figure out what's wrong. Unfortunately, I don't have the time and it doesn't really bother me that much. I just end up with a whole bunch of "your site is down" e-mails every morning when I wake up. Hopefully I can fix it soon. I've been telling people I'll have more time when the baby comes. They think I'm kidding - but I think it's true. My job will be handling Abbie while Julie nurtures the new baby. Abbie sleeps 12 hours at night, and 2-3 hours in the afternoon. I sleep 4-5 hours a night. That's a lot of time to get stuff done. ;-)

Posted in General at Aug 13 2004, 11:12:03 AM MDT 48 Comments

Quote of the Day

Julie: I wish I'd go into labor today so I'd quit having to deal with this house crap.
Me: Yeah, that would work out for me too, I could use a break.

Posted in General at Aug 12 2004, 09:20:26 PM MDT 2 Comments

[DJUG] The Google Guys

I'm sitting at the Denver JUG meeting and Joshua Bloch and Neal Gafter just finished a talk on "Java Puzzlers". I didn't show up until halfway through - but it was still a great half hour. They had a bunch of slides with problems that had seemingly easy answers. They'd both have a good dialog about their proposed answers - and then asked the crowd what they thought. The problems were mostly due to dumb (but real world mistakes) - the kind of thing you'd slap your fellow programmer for writing. These guys are definitely fun to listen to - next up is Tiger and what's new in 1.5 (I thought it was 5.0?). Boy, it's a full room tonight - I'd bet there's around 120-150 people here.

Taming the Tiger

Major theme of "JDK 5" is ease of development with features like generics, for-each loop, autoboxing/unboxing, enums, varargs, static imports and annotations. It's designed to make programs clearer, shorter and safer by providing linguistic support for commong idioms. Sidenote: Joshua said that Neal wrote the compiler - and they've basically made it more rigorous so it writes the boilerplate code for you. New features do no sacrifice compatibility or compromise the spirit of the language. Neal has been using these features for a couple of years now and he says he's really enjoyed them.

Goal of this talk is to make it easy for us to understand JDK 5 so we can start using it in our development. Let's look at the different features of 5.0.

Generics, For-Each and Autoboxing/unboxing

Generics allow you to specify the element type of collection. Rather than specifying a List - you specify it's contents - i.e. String. It's basically stronger typing with less typing which enforces the specification at compile time. For example, the following code using the new for-each syntax to iterate through a list of TimerTasks in a collection. Notice the lack of casting and easy-to-read loop syntax.

void cancellAll(Collection<TimerTask> c) {
    for (TimerTask task : c) {
        task.cancel();
    }
}

Bytecode is the same as it is in 1.4 - 5.0 merely converts the code for you. One question that these guys have heard a lot is why ":" rather than "in". The answer is twofold - because "in" is already a keyword (for example, System.in) and they didn't want to introduce a new keyword. Because 'in' is an identifier that is already in widespread use, and thus they could not make it a keyword without serious impact. Only new keyword in JDK 5 is enum.

The Collection Interface has been Generified. All existing code should still work, but you can also use the new stuff if you like. I haven't listened much to what's new in 5.0 - but this is wicked cool. You might say it sucks because now you end up with strongly typed stuff, but at least you won't have any more ClassCastExceptions.

  • autoboxing: automatic conversion from int to Integer (or from double to Double, etc.)
  • unboxing: automatic conversion from Integer to int

For example, you can now easily do the following:

Integer i = new Integer(5);
Map map = new HashMap();
map.put("result", i+1);

Notice that the Integer type is converted to an int for the addition, and then back to an Integer when it gets put into the Map. Cool, huh?

JDK 5 also simplifies reflection. Class Class has been generified - Class literal Foo.class is of type Class<Foo>. This enables compile-time type-safe reflection w/o casting. The following used to return an Object and required casting.

Foo foo = Foo.class.newInstance();

This enables strongly typed static factories. I wonder if this can be used with Spring so you don't have to cast a bean when grabbing it from the ApplicationContext?

When should you use Generics? Any time you can - unless you need to run on a pre-5.0 VM. The extra effor in generifying code is worth it - especially b/c of increased clarity and type safety.

When to use for-each loop? Any time you can b/c it really beautifies code and makes it much easier to write. It's probably the smallest new feature in 5.0, but likely to be a favorite. You can't use for-each for these cases:

  • Removing elements as you traverse a collection (b/c there's no iterator)
  • Modifying the current slot in an array or list (b/c the index is hidden)
  • Iterating over multiple collections or arrays

The lack of an index seems to rub the crowd wrong. Joshua and Neal's response is they tried to design something very simple that would capture 80% of usage. If you need an index, just use the old for loop - it ain't that hard; we've been doing it for years!

If you want to use for-each in your APIs - i.e. if you're writing a framework, a class should implement the new Iterable class.

When should you use autoboxing? When there is an impedance mismatch b/w reference types and primitives. Not appropriate for scientific computing. An Integer is not a substitute for an int. It simply hides the distinction between wrappers and primitives. A null unboxes by returning a NullPointerException. They did consider setting it to the primitive's default, but the community voted 50-1 to for NPE.

Enums

JDK 5 includes linguistic support for enumerated types. Advanced OO features include the ability to add methods and fields to enums. Much clearer, safer, more powerful than existing alternatives (i.e. int enums).

enum Season { WINTER, SPRING, SUMMER, FALL }

I just noticed that it's boiling in here - A/C must be out again in the auditorium. It's 8:20 right now, I hope this is over soon, I can feel sweat beading on my forehead.

Enums are Comparable and Serializable. Enum constants should be named similar to constants. Enums are basically a new type of class. As far as I can tell, I have no use for Enums in my code. There's lots of gasps from the crowd as Joshua is describing the features of Enums (i.e. constant-specific methods). Sure it looks cool, but I still don't think I have a use for it. Maybe framework developers will find this useful. BTW, there's two high-performance collection classes: EnumSet (bit-vector) and EnumMap (array). EnumSet replaces traditional bit-flags: i.e. EnumSet.of(Style.BOLD, Style.ITALIC).

When should you use Enums?

  • Natural enumerated types: days of week, phases of moon, seasons
  • Other sets where you knkow all possible values: choices on menus, rounding modes, command line flags
  • As a replacement for flags (EnumSet)

Quote of the night: "It's extraordinarily rare that you'll need to cast when programming with JDK 5".

Varargs

A method that takes an arbitrary number of values requires you to create an array. Varargs automates and hides the process. James Gosling contributed the ... syntax. Varargs always has to be the last parameter. MessageFormat.format has been retrofitted with varargs in JDK 5:

public static String format(String pattern, Object... arguments);

String result = MessageFormat.format("At {1,time} on {1,date}, there was {2} on planet "
                                     + "{0,number,integer}.", 7, new Date(),
                                     "a disturbance in the Force");

Reflection is now much easier with Varargs - so you can call c.getMethod("test").invoke(c.newInstance()) instead of c.getMethod("test", new Object[0]).invoke(c.newInstance(), new Object[0])).

When should you use Varargs?

  • If you're designing your own APIs - use it sparingly.
  • Only when the benefit is compelling. Don't overload a varargs method.
  • In clients, when the API supports them: reflection, message formatting, printf

Static Imports

Clients must qualify static members with class name (Math.PI). To avoid this, some programmers put constants in an interface and implement it. BAD - "Constant Interface Antipattern". They've made this mistake in the JDK - java.util.jar has this pattern. Static import allows unqualified access to static member w/o extending a type. All static fields, methods, etc. will be available for your class using static imports. For example:

import static java.lang.Math.*;
r = cos(PI * theta);

When should you use Static Imports?

  • Very sparingly - overuse makes programs unreadable.
  • Only use it when tempted to abuse inheritence.

Metadata

Decorates programs with additional information. Annotations don't directly affect program semantics. They *can* affect treatment by tools and libraries. Can be read from: source, class files, or reflectively. Ad hoc examples: transient, @deprecated. Tiger provides a general purpose metadata facility.

Why Metadata?

  • Many APIs require a fair amount of boilerplate - i.e. JAX-RPC.
  • Many APIs require "side files" to be maintained. Examples: BeanInfo class, deployment descriptor.
  • Many APIs use naming patterns, i.e. JUnit.

Metadata encourages a declarative programming style - tell a computer what to do, now how to do it. Annotation Type Declarations are similar to interface declarations. Special kinds of annotations include Marker annotations and Single-element annotations. The main reason for annotations is for tools providers.

Neal thought that JDK 5 Beta 3 or Release Candidate was available at http://java.sun.com/j2se/1.5.0, but it looks like Beta 2 is the latest release. The fact that he said that implies that a new release should be available shortly. Neal also mentioned that JDK 5 (final) would be shipping soon.

Random fact: Google uses a lot of Java - entire Ads front-end is done in Java.

This was a great talk about all the new features of JDK 5 - I can't wait to start using them. It might be awhile before I can convert AppFuse to JSP 2.0 and JDK 5, but it'll be a good day when I can write my apps using these technologies. Tonight was the best overview of JDK 5 that I've seen so far - in print or person.

Update: Presentations PDFs have been published: Programming Puzzles and Taming the Tiger.

Posted in Java at Aug 12 2004, 01:01:48 AM MDT 5 Comments

PostgreSQL 8 with AppFuse

I agree with Dion that PostgreSQL is a good database. Thanks to his post, I found the new Windows installer for 8.0. Using it, I was able to quickly setup a database for AppFuse, change my database settings in build.properties and run "ant test-all" successfully. Total time? 5 minutes. That's the way a database installation should be.

I've setup PostgreSQL on OS X before using this package, but now when I try to run it, I get an error "could not read shared memory segment". Time to start digging into config files.

5 minutes later: Using these update instructions, I got everything working again on OS X. To ensure good PostgreSQL support, I'm going to run AppFuse against PostgreSQL (on OS X) from now on.

Posted in Java at Aug 11 2004, 11:56:23 AM MDT Add a Comment

VW Days

58 Bus This weekend, we attended the annual VW show out at Bandimere Speedway. I was in heaven with so many nice bugs and buses around.

I was so inspired by the show that I tried to attend the Colorado Bus Club meeting tonight (30 miles south). I made it about 5 miles before the wipers quit working. It wasn't raining, but the road was wet and I definitely needed wipers. So I pulled off the road and tried to figure out what went wrong. It seemed to be something had gone wrong with some sort of voltage changer I had in my dash. It's a square piece of porcelain that acts as a conductor of sorts for 3 different cables (lights and wipers I think). Anyway, it was cracked pretty bad and hot. I could tell it'd been repaired before, as there was melted glue all over it. I tried to fix it, and I did get the wipers working again - but soon noticed a plume of smoke from my dash. At this point, I decided to abandon ship, disconnected the wires and drove back home.

The funny thing is that this is just the day in the life of an old VW owner. Hopefully in the next few years, "Daddie's Bus" will become a new VW and these problems will be a thing of the past. Yeah right.

Posted in The Bus at Aug 10 2004, 08:48:55 PM MDT Add a Comment