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.

[NFJS Denver] Richard Monson-Haefel and Groovy Programming

Groovy makes for easier for loops. As an example,

for (Iterator i = r.iterator(); i.hasNext();) {
    System.out.println(i.next());
}

... becomes ...

for (i in r) {
  System.out.println(i)
}

With Groovy, you can remove semi-colons and use dynamic typing. This means you can basically remove any types (i.e. List). The nice thing is that typing is a choice - you can use static typing like you do in Java write now.

One thing I forgot to mention about this conference. Jay Zimmerman (the organizer) has a pretty good idea. The full schedule is printed on the back of the conference badges attendees hang around their necks. This makes it very easy to find and decide what session to attend. I wish more conferences would do this.

Richard is going through closures, native list looping and how you can remove classes and method declarations. It seems to me that one of the coolest features of groovy is that all of the shortcuts are optional. This is huge IMO, because it means the developer has a choice - which is always nice. Richard says that in his experience, a program written in Groovy is about 1/5 the size of the same thing written in Java (an 80% reduction in code). Someone in the room asked about performance. I was surprised to hear Richard say that Groovy was a bit slower. After asking about this, it turns out that Groovy can be executed as a script or as native bytecode (if compiled first). So when Richard said "it's slower" - he meant the script version is slower - because it's interpreted - just like any scripting language.

Sweet - I just got a connection on the hotel's wireless network. I was in the midst of reading some RSS feeds in NetNewsWire and noticed a JRoller blog with additional coverage of this conference. ... Sorry, I got sidetracked for the last 20 minutes with the Spring developer's mailing list - talking about simplifying Spring forms in JSPs.

Back to Groovy. Richard, and several members of the audience, are talking about closures. I still don't really get what they are and why they're important. I guess I shoulda been paying attention. ;-)

Groovy has regular expressions built-in - based on JDK 1.4 Regex. In Groovy, == is the same as .equals() in Java. And === is equal to == in Java. Apparently, they did this because folks usually use == when they really want to get the functionality of .equals(). I like the idea that == in Groovy means the same thing as == in JavaScript, but I don't know how I feel about ===. I'm guessing that using .equals() is still possible.

Richard has a good presentation style. He does a lot of coding during his presentation - writing scripting, compiling and executing them. Unfortunately, since I got internet access, I haven't been paying attention as much as I should - but at least 75% of the class seems to be extremely engaged. An interesting thing about this conference vs. the MySQL Conference in Orlando. At MySQL, almost all the presenters had PC Laptops. In fact, I was one of the only ones with a PowerBook. At this conference, Bruce Tate is the first one I've seen that uses a PC. Almost all the presenters are using PowerBooks - mostly 15".

Groovy can be used for easily writing XML as well as enhancing your Ant build scripts. One thing I'm hearing at this conference, as well as seeing on blogs recently is that AppFuse's build.xml could probably use some refactoring. With Ant's new import feature and the ability to write scripts in build.xml - it's likely it could be greatly simplified. Then again, it ain't broke - so why should I fix it?

Richard's showing us how easy it is to write XML using Groovy's shell:

import groovy.xml.*;

x = new MarkupBuilder();
a = x.Envelope { Body("Hi")}

If you run this, you'll get:

<Envelope>
  <Body>Hi</Body>
</Envelope>

An interesting thing from the above demo. When Richard added "print a" as the last line in the script, it printed "Envelope" after the XML output. He said this is because the last line in Groovy is treated as the script output. That's kinda wierd IMO. GroovySQL - pretty cool and simplistic. A nice feature is that connections are automatically closed (when the script completes). Another thing Richard mentioned is that Files are also automatically closed - even when used inside an Iterator. It seems to me that Groovy is trying to stop many newbie Java developer mistakes, as well as do more automatic resource management (closing files and connection). This is actually similar to Spring in how its JDBC and ORM support manages closing connections behind the scenes. Good stuff - another tool to make life easier for Java Developers.

Posted in Java at May 22 2004, 10:34:13 AM MDT 7 Comments
Comments:

A closure is a piece of code that "completes" an algorithm. I'm sure you've noticed how much boilerplate stuff happens in JDBC code, for example. You set up the connection, do some "real work" and release the connection. The set up and release are always there, and they surround the "good stuff". Wouldn't it be nice to be able to be able to factor out the boilerplate into a method that has a hole in it, and supply the "good stuff" in a method call to this factored out method, and to do so without using the Template Method pattern and subclassing? That's what you can do with a closure. Think of Spring's JDBC Query framework without subclassing. In languages like Ruby (and Smalltalk, and now Groovy), it's trivially easy to define such structures. I'm at RMSS too. Have fun...

Posted by Mike Thomas on May 22, 2004 at 09:47 PM MDT #

for (i in r) {
  System.out.println(i)
}

A few more changes and, gosh that's looking a lot like Python. ;-)

for (i in r):
  print i

You may as well just give in now Matt.

P.S. Roller comments *really* need a preview button.

Posted by Anthony Eden on May 22, 2004 at 10:04 PM MDT #

Actually, you can even ditch the parenthesis in Python:

for i in r:
  print i

Posted by Anthony Eden on May 22, 2004 at 10:05 PM MDT #

You wrote: "...schedule is printed on the back of the conference badges..." BEJUG's JAVA conference (www.javapolis.com) also used this type of badges ;-)

Posted by koenvda on May 24, 2004 at 10:21 AM MDT #

Matt, Rod Cope gave an *AWESOME* talk on Groovy at the Basic Concepts for the last DenverJUG. I know you were sick as a dog and couldn't make it but the notes are available at: http://www.denverjug.org/presentations/200405_Groovy.zip It was sooo cool. I guess the new syntax for iterations is available in the latest JDK but with Groovy you can have it now. The other thing Rod mentioned is that it will compile existing Java Code. There are a few exceptions. The only drawback for Groovy was that it's still changing and there are people fighting over what it should look like. I like that I can have Groovy and not have to remember other syntaxes like Python, Ruby, et. al. Groovy has Java syntax so I thought that was cool. Are you going to be using Groovy for any projects you're doing for Rod at your new gig?

Posted by Greg Ostravich on May 24, 2004 at 06:30 PM MDT #

<em>> Are you going to be using Groovy for any projects you're doing for Rod at your new gig?</em>

I doubt it. Since I'm a contractor, he's likely to just pay me to do what I'm good at - developing webapps with open source tools.

Posted by Matt Raible on May 24, 2004 at 07:54 PM MDT #

FYI - James Strachan and Dion Almaer will be giving a Groovy presentations during this years JavaPolis 2004 conference. ;)

Posted by Stephan on July 21, 2004 at 07:45 PM MDT #

Post a Comment:
  • HTML Syntax: Allowed