Cay Horstmann's Unblog

2016-10-05

blog image

A Play App on Google Compute Engine

Google gave my grad students some free credits to use Google Compute Engine. Here is how we set up a Play app with autoscaling and https support.
2016-05-06

blog image

Code Page 437 Refuses to Die

console: 1. to alleviate or lessen the grief, sorrow, or disappointment of; give solace or comfort. — That's what I need more of after trying to demystify the behavior of System.out in the Windows console. Read on if you want to be consoled and enlightened.
2016-04-20

blog image

The Post Office Hates Java

I am updating the section of Core Java that explains how to make a POST request. The service that I used in the previous edition was discontinued, so I tried using the USPS ZIP code lookup. The POST redirects to a GET, but that's ok—HttpURLConnection can handle redirects. But when the user agent contains the string Java, the post office redirects to a dead end!
2016-02-12

blog image

If You Don't Want Users to Use a Class, Give it an Ugly Name!

I spent the better part of a day trying to figure out why a clearly documented API call didn't work as advertised. It turns out that the library uses the same class name, but in a different package, for an implementation class with different methods, and Eclipse auto-completed to that package. That's reprehensible. Don't entrap your fellow programmers like that!
2015-12-16

blog image

Oh Goody—My New Build System Gives Me Stack Traces

My pet peeve from Java EE is the “stack trace from hell”, when the app server shares its pain with me, showing a stack trace, instead of telling me in which source file I messed up some setting. Oh goody—I just switched my Android build to Gradle, and it acts the same way. Hello, dev tooks makers. If you can't trace back your failure to the file name/line number of my artifact, you have failed.
2015-12-10

blog image

Some Small Details About Working with Play

In my last blog, I marveled how the dull pain of Java EE stacktraces melted away after I started using the Play framework, where each error was clearly reported with the file name and line number of the offending artifact. Here are some small details that I ran into.
2015-11-21

blog image

All Work and No Play

All work and no play makes Jack a dull programmer. And I just felt the dull pain of another stack trace from hell from my Java EE app server. There has to be a better way. So I ported the troublesome code to run on the Play framework, and it was all play. No stack trace from hell, just a few screens with clear error messages, and then sweet success.
2015-11-10

blog image

Updated Refcard

Years ago, I designed a “refcard” for DZone that tried to cram all of Java into eight pages. Now a Java 8 update is available, thanks to Bulgarian JUG leader Ivan St. Ivanov. Check it out!
2015-11-08

blog image

Arrows of Outrageous Fortune

At Java One, I overheard someone mentioning an outrageous trick to abuse the arrow -> of the lambda syntax. Of course I had to investigate. Here are the gory details...and please, kids, don't try this at home.
2015-11-07

blog image

Sayonara java.net Blog. Welcome Unblog.

For almost ten years, I had a blog on java.net. I am grateful for having been given a platform and a community for my thoughts, but sadly java.net has fallen apart. I still want to share the occasional tidbit of useful information and rant about the latest injustice, but I don't want to find a new home just to see it fall apart too ten years from now. So, I am starting an unblog on my very own website.
2015-07-26

blog image

Back from the JCrete Unconference

Some time ago, I got an invitation from Heinz Kabutz (the man behind the Java Specialists newsletter, to which you should subscribe right away if you haven't already), to join the JCrete conference.
2015-06-22

blog image

The Curious Case of the char Type

It's been almost twenty years that Gary Cornell contacted me to tell me “Cay, we're going to write a book on Java.” Those were simpler times. The Java 1.0 API had 211 classes/interfaces. And Unicode was a 16-bit code.
2015-05-25

blog image

Trying out the Java 9 REPL

A REPL (read-evaluate-print loop) is an integral part of dynamic programming languages such as Lisp or Python. It's a great tool because you can experiment with language and library features without having to write complete programs. If all goes according to plan, Java 9 will have its own REPL. In this blog, I show you how to build the pre-release version and play with it.
2014-03-20

blog image

Hello Java 8 (and how it makes GlassFish speechless...)

After all these years, Java 8 is finally available. Just make sure you don't get tripped up by the change in the classfile format!
2014-01-16

blog image

Sign Your Applets, Or Else...

Remember applets? When Java was first introduced, applets were what excited everyone. No more desktop apps! Deliver code from the server!! Run it securely in the browser’s sandbox!!! That was then. Java 7 update 51, which was released January 14, 2014 will only run signed applets. If you still have any applets and haven’t gotten around to signing them, here is how.
2013-12-04

blog image

Java 8 for the Really Impatient

Java 8 is the biggest advance in the Java language since, well, Java 1, even bigger than the addition of generics in Java 5. I figured that every Java programmer would want to come up to speed quickly with these changes and wrote a short and snappy book “Java 8 for the Really Impatient”. A “rough cuts” version is now available on Safari.
2013-10-14

blog image

Scanners Live in Vain

In the bad old days. you had to turn an InputStreamReader into a BufferedReader if you had the desire to read lines of text. Java 5 introduced the Scanner class, and I never looked back. But the Scanner class is getting no respect. Java 8 makes you use a BufferedReader, with all that layering nonsense, if you want a stream of lines from a URL. Why not a Scanner? Or, if BufferedReader is so loved, why not add a few constructors?
2013-09-26

blog image

Java One for the Impatient

Here are my impressions from the 18th Java One. Java SE 8 is around the corner, Java EE 7 was just released, and both are a joy to use. NetBeans 7.4 is awesome. And yet, people were strangely blasé at the conference. I still remember how much excitement there was at Java One when Java was in its infancy, and the promises greatly exceeded the reality. (Do you remember Jini? Or the original Java EE?) Nowadays, that excitement is lavished on other technologies whose promises exceed the reality, and Java has grown up.
2013-02-02

blog image

I Didn't Ask for a Toolbar with That Java

In these unhappy days where Oracle is working hard to regain the trust of users, it seems a staggeringly bad idea that the Java updater installs the Ask toolbar by default. It's plainly bad for Java and can't possibly be worth the few clams in additional revenue. If you agree, sign the petition!
2013-01-21

An XML Macro

In my previous blog on Scala 2.10 macros, I showed you how to write a macro that can swap the contents of two variables. In this blog, visiting scholar Martin Christensen and myself try to solve a problem from our blog on dynamic types in Scala 2.10.
2013-01-14

The swap macro

The final version of Scala 2.10 was released on January 4, 2013. Martin Christensen, a visiting scholar in our department, and myself have been playing with some of the new features, and I'll be blogging about some of our discoveries in my copious spare time.
2012-12-10

blog image

Dynamic Types in Scala 2.10

This blog explores Scala dynamic types, a new feature of Scala 2.10, and provides some hopefully interesting exercises so you can try it out for yourself.
2012-06-07

blog image

Wildcards in the Wild

Generics and wildcards have invaded Swing, and I got an error message from hell when decorating my perfectly working code with those pesky angle brackets. This blog a nifty and self-referential tip on how to fix such errors.
2012-06-01

blog image

The Grand War is over, and what we can learn from it

The grand war between Oracle and Google over the Android API is over, unless Oracle prevails on appeal. The judge and jury have spoken, and this is what they said: Android doesn't infringe on the couple of patents that were at play in the lawsuit. (Other patents that Oracle asserted were invalidated by the USPTO or not included for tactical reasons
2012-04-10

blog image

BOMed out by Notepad and javac

I've been too busy to blog for quite some time, but today something happened that seemed strange enough to break my silence. A student came to me with a Java source file that the grading script rejected. We looked at it and couldn't figure out why. I unearthed the error message:
2011-12-12

blog image

The Sordid Tale of XML Catalogs

In this blog, I summarize what I found out about using XML catalogs with the Java SAX parser. I know, it's not the most riveting subject, but if your app waits for minutes untilthe parser delivers a perfectly ordinary XHTML file, you may find this useful. Or depressing.
2011-12-05

blog image

Operator Overloading Considered Challenging

In this article, I explain why I think that operator overloading is a good feature, even though it is hard to get right. To illustrate my point, I go into more detail of the operators in the Scala collection library than you want to know.

2011-10-10

blog image

A first look at Dart

Google released details about the Dart language today, and I am surprised how much more it is like Java than like JavaScript.
2011-10-06

blog image

JavaOne 2011 Day 4

Another day, another keynote. A fellow from IBM talked about cloud stuff. I sat through a lot of nebulous cloud talks, but this guy was good. He had a sensible slide on architectural alternatives, explained why we should all go out and buy a device for a ”data grid”—a memory device for sharing data among VMs—and he gave a demo of some software for configuring an app to run on their cloud server. Clear and to the point, like a tech talk should be. It had nothing to do with the “community” theme of the keynote, but you can't have everything.
2011-10-05

blog image

JavaOne 2011 Day 3

It's the third day of Java One. No keynote today, but I write about the thrills of the Script Bowl, alternative languages for Java EE, OpenEJB, and the GreenFoot and BlueJ projects for computer science education which I hope Oracle will continue to fund.
2011-10-04

blog image

JavaOne 2011 Day 2

Here I am, on my second day of Java One. I live in the residential part of San Francisco and get to the conference on a battered “express” bus that stops at every block, starting from the ocean until it reaches mine. Then it  goes straight downtown, but by the time that I get on, it is standing-room only. I make it to the keynote frazzled but just in time. Today, I realize that the empty chairs labeled “Oracle Press” are not for the publishing division of the Oracle corporation but for scribblers like me.
2011-10-03

blog image

JavaOne 2011 Day 1

Today, JavaOne started officially. With the traditional keynote. Except, traditionally, the keynote is in a huge room that has space for everyone. Today, people were shunted into overflow rooms where they could watch on monitors. In the age of the screencast, that seems pointless—why is that better than watching on your laptop?
2011-10-02

blog image

JavaOne 2011 Day 0

Once again, I got a blogging pass to JavaOne—my fifth year as the intrepid reporter at JavaOne, and my 15th JavaOne attendance. Sadly, that wasn't enough to get me the coveted Alumni badge—my email address wasn't in the right Oracle database, and showing my previous conference blogs didn't impress the conference staff. I complained to Sharat Chander, the marketing person at Oracle who is responsible for the tech tracks at JavaOne, and he told me he can't get an alumni badge either.
2011-09-02

blog image

Complexity is in the Eye of the Beholder

I just read through David Pollak's blog Yes, Virginia, Scala is hard. Now David has much more contact with developers in the trenches than I do, but I was a bit perturbed by his perspective.
2011-08-22

blog image

Scala for the Impatient—Free Chapters at typesafe.com

My hard-hitting, tell-it-as-it-is Scala book draft is coming along. No animals or fruit have been pressed into service for contrived examples. Free chapters are at typesafe.com.

2011-08-14

blog image

Whatever Floats Your Boat

I am in the process of revising a CS1 textbook. I made changes requested by users, added snazzy exercises and sample programs, and the publisher sent the draft out to reviewers. A couple of reviewers said in no uncertain terms that I was wrong, wrong, wrong in using double for my examples. I should use float instead. Another professor contributed a business problem set that used float where I would have used double, or, if I had been allowed, BigDecimal.
2011-08-05

blog image

Inner Classes in Scala and Java

When I used the Scala combinator library in earnest a few months ago, I got confusing error messages when I used classes that are nested inside other classes. There were several blog posts that made the feature look complicated, so I reserved a chapter of my upcoming ”Scala for the Impatient” to explain class nesting. It turns out that won't be necessary. It's simpler in Scala than in Java, and I can explain it in a few paragraphs.
2011-07-29

blog image

Java 7 Unsafe at Any Speed?

Java 7 got released, but there are rumors of hotspot crashes . It's probably a tempest in a teapot, but it reminds me of the 1994 Pentium floating-point bug.
2011-06-27

blog image

In Praise of Language Specs

An implicit conversion is only inserted if there is no other possible conversion to insert. If the compiler has two options to fix x * y, say using either convert1(x) * y or convert2(x) * y, then it will report an error and refuse to choose between them. It would be possible to define some kind of “best match” rule that prefers some conversions over others. However, such choices lead to really obscure code. Imagine the compiler chooses convert2, but you are new to the file and are only aware of convert1—you could spend a lot of time thinking a different conversion had been applied!

2011-06-20

Handwringing about Scala

There has been a flurry of blogs and email threads with hand-wringing about the fact that Scala hasn't yet achieved world domination.
2011-06-16

blog image

There Will Be Monads

My sabbatical is coming to an end, and I just finished off my “modern programming languages” course at the Ho Chi Minh City University of Technology with a dose of monads. The good news is that I am not going to tell you how monads are just like Vietnamese spring rolls. Just think of them as a design pattern for composing actions. 
2011-05-12

blog image

Easy Red-Black Trees

Users of one of my textbooks asked for a section on red-black trees. That makes sense—just lecturing about binary search trees leaves the nagging doubt what happens when a tree becomes unbalanced. Unhappily, the standard algorithms are a mess of fiddly special cases. Here is a simpler way of doing it, modifying the presentation by Chris Okasaki and Matt Might.

2011-05-05

blog image

A Dozen Concurrency Pitfalls

I needed some filler material for my lectures on concurrency. I googled around for Java concurrency pitfalls and came up with a nice mixture of golden oldies and new ones (at least new to me). I cleaned them up and translated them into Scala because that's what we use in the course. Here they are, for your puzzling pleasure.
2011-05-04

blog image

Parallel Arrays in Scala

In my programming languages class, I have come to the point where I talk about language and library support for concurrent programming. As I revise my slides about the fork-join framework, I need to do something about the bullet that Java 7 will have parallel arrays. Sadly, it won't, but Scala 2.9 does, and they are really easy to use. Read on if you want to see how to keep your cores busy with just a few keystrokes.

2011-03-22

blog image

Having a Racket with Pictures and Continuations

In this blog, I describe how the Racket language provides fun graphics and a nifty web framework. The  former is great for beginning students, and the latter is helpful for grasping the mind-bending concept of continuations.
2011-03-11

blog image

A Blog Uploading Tool for java.net

In this blog, I address my grief with blog uploading, following Paul Graham's advice about choosing technology.
2011-03-03

blog image

Ruby, Scala, and Complexity

In this blog, I ponder why Ruby and Scala are easy to learn and complex to master, and how their cultures differ.

2011-01-27

blog image

Scala for the Impatient

My next writing project is "Scala for the Impatient". Why yet another book? I became impatient with the books and blogs that seemed to be directed towards language enthusiasts, not programmers who need to get a job done. Watch out for the first drafts on Safari in a few weeks!

2010-11-24

blog image

A Report from the Sewer Hole: Cygwin, JLine, rxvt, and the Scala REPL

I have students running Windows, Linux, and Mac OS X, and I like to encourage students to choose whatever platform makes them most productive. But I also like to be able to give out one set of instructions, grading scripts, etc. to everyone. Fortunately, bash is available everywhere, even on Windows, in the form of Cygwin.
2010-11-22

blog image

A Condensed Monospaced Font

When the time comes for my graduate students to write their project reports, I give them a long checklist of do's and don'ts. One of the more vexing issues is the code font. I am astonished how many people who have been programming for years are unaware that computer code is usually presented in a monospaced font, like this.
2010-11-15

blog image

The Mystery of the PolicyNodeImpl Class

Google further denies that the document attached to Oracle's Amended Complaint as Exhibit J contains a true and correct copy of a class file from either Android or "Oracle America's Java." Google states further that Oracle has redacted or deleted from the materials shown in Exhibit J both expressive material and copyright headers that appear in the actual materials, which are significant elements and features of the files in question.

2010-11-12

blog image

A Geometry Problem in Scala

I ran into this blog about making a pretty drawing in C# and F#.
2010-11-05

blog image

The Voters Have Spoken

The votes are in, and the people have spoken. They are mad as hell and they want change. No, not those electionsI am talking about the JCP elections.
2010-10-24

blog image

Scala Scripting

In this blog post, I describe how I use Scala for mundane scripting instead of monadic computations.
2010-09-25

blog image

Java One from Afar

I have been at JavaOne since 1996, its inaugural year. In 1996, JavaOne was colocated with the Software Development conference, which has since fallen on hard times and vanished. But at the time, half of the exhibitors were from SD, and the other half from JavaOne. Weirdly enough, the JavaOne booths were all yellow with a bit of red and blue, so it looked as if the SD half of the exhibit hall represented the free world and the Java One half a totalitarian regime. This year, JavaOne is again colocated with another conference, Oracle OpenWorld, but I am on sabbatical in Vietnam, so I didn't get to enjoy the show.
2010-09-24

blog image

The Next Big JVM Language

Stephen Colebourne has a very interesting article on the Next Big JVM Language (NBJL). The comments are good too. (I was going to add this as a comment to his blog, but it was rejected as spam. Maybe jroller is onto something...)
2010-09-13

blog image

PrimeFaces works great with JSF 2.0/NetBeans 6.9

In 2002, JSF was introduced at Java One as Swing for the Web. The vision was that you would compose professionally designed components into web pages, add a bit of Java glue code, and presto, you would have a web app without having to worry about HTTP or the DOM.
2010-09-09

blog image

A puny Java 7 isn't the end of the world

Mark Reinhold just published a blog stating what has been painfully obvious to everyone following the JDK 7 development: There is no way that it will ship 2010. He thinks that mid-2012 would be realistic. Having followed the Project discussion, I can see where he is coming from.
2010-09-04

blog image

Scala, JSF 2, and NetBeans

I am working on a web site that will help students practice their Scala programming skills. As I labored along, writing my JSF app code, I thought this is sillywhy not practice Scala at the same time? But I like JSF and wasn't ready to jump to Lift or Vaadin.
2010-09-02

blog image

Independence Day for Java?

I am on sabbatical in Vietnam right now, and today the country celebrates independence day. (On September 2, 1945, Ho Chi Minh gave his declaration of independence speech.)
2010-06-28

blog image

The Horstmann Brace Style

There is a brace style with my name attached to it. In this blog post, I describe its merits and why I had to stop using it.
2010-06-27

blog image

JSF and Power Windows

My dad is visiting, and he just picked up his rental car. He proudly announced that he got a good deal on a compact car without power windows.
2010-05-28

blog image

Another Java Web Start Pitfall

Yesterday, I installed shiny new Ubuntu Lucid Lynx on a shiny new laptop. This morning, I launched a Web Start application, and I got the following screen:
2010-05-16

blog image

XML Processing with Scala

A few months ago, I had one of those unpleasant format conversion jobs. I had about 1,000 multiple choice questions in RTF format and needed to import them into Moodle.
2010-05-16

blog image

Transforming an XML Tree with Scala Partial Functions

In my last blog, I outlined how I found the Scala XML library a pleasant solution for unpleasant XML format conversion jobs. In those jobs, I had to completely transform the document from one grammar to another.
2010-03-28

blog image

Mercurial on OpenSolaris and GlassFish

I am working on rewriting a set of labs for our intermediate students at SJSU. Version control is something that everyone with a CS degree is pretty much expected to know these days, so I thought of digging up an old Subversion lab from my open source programming class.
2010-01-30

blog image

Composite Input Components in JSF

Composite components are a great feature of JSF 2.0. The canonical example is a login component with fields for the username and password:
2010-01-13

blog image

Project Stage and Openness

I am an observer at the JSR 314 (JSF 2.0) expert group, whose mailing list is open (but sadly not yet archiveddon't get me going...), and we had an interesting discussion about the project stage setting. The expert group's efforts to extend this useful setting to other parts of EE don't seem to go anywhere. I can't tell why, because those discussions sadly have not been open. If you believe that an app server should be a developer platform and not just a deployment platform, say so in the blog comments!
2010-01-12

blog image

A Flash in the Pan?

Last night, I awoke at 3 a.m. wondering whether David Geary and I should have given more coverage to the JSF 2 flash in our Core JSF book revision. Here is why I think your time is better spent learning about other, more powerful constructs, together with some thoughts about CDI and REST.
2010-01-03

How to stay away from the JSF API

A few weeks ago, Ed Burns posted a link to a blog on the JSF expert group mailing list, commenting A nice one, but it doesn't mention JSF 2. Ever the curmudgeon, I pointed out that it wasn't so nice that the blog's sample code used the JSF API in beans when it wasn't necessaryas does in fact a lot of sample code, even in the official Sun tutorials. Ed's response: Cay, a blog comment by such an eminent citizen as yourself would certainly be noticed. So, here is the curmudgeonly eminence's advice on how to stay away from the JSF API.
2009-12-28

JSF 2.0 and Tomcat

As I happily wrote about new features of JSF 2.0, my coauthor David Geary kept asking me how to run the examples in Tomcat 6. I kept putting it offhunting down all those JAR files and web.xml fragments is just too much like eating soup with a fork. I finally got around to doing the research and thought that others might benefit from the (unhappy) results, if only to realize that this may be the time for switching to GlassFish.
2009-12-21

blog image

Is @javax.faces.bean.ManagedBean Dead on Arrival?

Java EE 6 has three different ways of defining beans that are managed in one way or another. Here is a quick recap.
2009-12-07

blog image

Running PHP Apps on GlassFish

For the upcoming semester, I want to run a learning management system into which I can integrate an experimental feature for evaluating student programs. It needs to be open source so that I can modify it. I was first going to go with Sakai, which is based on Java, but just about everyone else is going to Moodle, and there are reasons for that.
2009-11-18

blog image

Closures? In Java 7???

Today, a tantalizing announcement by Mark Reinhold about closures in Java 7 has made its way through the twittersphere.
2009-10-20

blog image

Monitoring the HTTP Traffic in a JSF Redirect

I wanted to trace exactly what happens when a JSF page uses a redirect. Here are my experiences with the HTTP and TCP/IP monitors in NetBeans and Eclipse, and why I ended up using Wireshark instead.
2009-10-20

blog image

Another Small Step for JSF...

In the relentless fight against configuration boilerplate, JSF and Glassfish have taken yet another small step forward. As of Glassfish v3 build 68, you no longer need to declare the faces-servlet in WEB.XML.
2009-10-13

blog image

Recursive varargs methods in Scala

And now for something entirely different...one of my students asked how to write a recursive function in Scala with varargs. Apparently, the internet has lots of articles complaining about the challenge of calling Java varargs methods from Scala, but this particular issue did not google well. Here goes...
2009-10-12

blog image

Oracle OpenWorld Day 1

I got a blogger pass for Oracle OpenWorld. Here is my report from the show floor.
2009-10-11

blog image

Oracle OpenWorld Day Zero

Aaron Houston, the fearless leader of the Java Champions, got me a blogger pass to Oracle OpenWorld. Here is what I learned on the opening night.
2009-10-06

blog image

Java/CS1 Cheat Sheet

The next edition of my CS1/Java book is going to print soon. At the last minute, we decided to put the real estate of the inside covers to good use and include a cheat sheet with the most important Java control structures and libraries. Since it would be particularly embarrassing to have a typo here, I am hoping to enlist the aid of the community.
2009-10-03

blog image

How to draw simple diagrams the easy way (with Java2D)

When you need to produce lots of fairly straightforward graphs, Java2D is your friend. In this blog, I show you how you can render simple images as crisp-looking PDF or EPS files, provided you can draw them on a Graphics2D object.
2009-10-02

blog image

Recording and serving screencasts

I just learned how to make Flash screencasts on my Linux system and deliver them (with GlassFish) on a server that the computer science department received as a donation (thanks Sun!!!).
2009-09-28

blog image

Alice 3, CS1, and Quaternions

This semester, I am teaching the CS1 course again. If you just teach plain Java, it isn't easy to come up with interesting lab assignments. Some of the students have built exciting animations with Alice in the CS0 course. Somehow, they aren't as excited about printing prime numbers or digits of in CS1. But the latest version of Alice, now in beta, can be programmed in Java. This is very cool. Students can write Java code that directs the Alice models. For example, one assignment asks students to make a Car class whose drive method moves the car and reduces the gas in the tank. (I couldn't find a gas gauge, so I used the cat clock. The tail moves to the left as the tank gets emptier.) I provide the code for moving the car and rotating the tail, and the students compute the gas consumption.
2009-08-10

blog image

A spoonful of Scala

I write my lecture slides in XHTML, using the marvelous HTML Slidy package. I just dump the images into the same directory as the HTML files, which isn't so smart because it makes it hard to copy a presentation from one directory to another. I could change my habit, but hey, what is technology for? A couple of years ago I decided to write a script that simply generates a list of all images in an HTML file, so I can run
2009-08-07

blog image

Are you using static import?

I am rewriting a Java book for beginners, and it seems to make so much sense to use
2009-07-21

blog image

Add an XSD file to Eclipse and Eliminate Those Pesky XML Warnings

If you work with Eclipse and JSF 2, you too may be annoyed at the little that shows up next to all your faces-config.xml files (even those that are blessedly empty).
2009-07-21

blog image

Say Sayonara to sPAL!

When I teach my JSF crash course to my software engineering students, everyone nods, works through the lab, and I don't hear any JSF issues from them for a couple of weeks. Then they run into sPAL.
2009-07-08

blog image

Are Web Services the New CORBA?

I am updating the External Services chapter in Core JSF. There is lots of new and interesting stuff: How to use JPA, stateless session beans, and WebBeans. I ditched the LDAP sections (for which I hadn't received very few queries, even though the examples are notoriously hard to set up). I reimplemented the authentication example with a JDBC realm, which was no fun. Now I am at the web services section.
2009-07-06

blog image

WebBeans in Glassfish v3

As I am updating my share of chapters in the Core JavaServer Faces book (with the hard parts fortunately being tackled by my coauthor, David Geary), I started playing with WebBeans, erm, Java Contexts and Dependency Injection. I'll keep calling it WebBeansthe alternative JavaCandi is more than I can take. There are two features that are crucial for JSF users: Conversation scope and access to stateful session beans from JSF pages. (Seam users know all about this and can skip this blog.)
2009-06-29

blog image

A First Look at NetBeans 6.7

A few days after Eclipse Galileo, Netbeans released its latest offering, Netbeans 6.7. Here is a first look, as always from my entirely biased perspective.
2009-06-26

blog image

Upgrading to Eclipse Galileo

I just installed Eclipse 3.5 (Galileo)it seemed a more attractive thing to do than actually getting my work done. Fortunately, I only need three Eclipse plugins right now. Here is how they fared with Galileo.
2009-06-16

blog image

JSF 2.0 Refcard available

DZone just published the JSF 2.0 version of my JSF refcard. It provides updated summaries of the tags and attributes needed for JSF programming, along with a summary of the JSF expression language and a list of code snippets for common operations.
2009-06-15

blog image

My Department is Slashdotted

I teach computer science at San Jose State University. My department just ended up on Slashdot. One of my colleagues, Dr. Beesonwho, to his great credit, makes beginning students write lots of little homework programs until they get them rightgot into a tussle with Kyle Brady, an eager student who insisted on publishing his answers on the internet. I don't want to get into the personalities here. Beeson can be irascible and a bit overbearing, and the student's claim that he is doing this to increase his chances for employment rings a bit hollow. When is the last time you hired someone because of their TicTacToe program? Even if I did, I'd be wary about candidates who write if (foundEmpty == false) instead of if (!foundEmpty)...
2009-06-05

blog image

Java One 2009 Day 4

One of my favorite parts of Java One is the Friday morning toy show where James Gosling presents a random mixture of cool and inspirational projects. Of course, all these involve Java in some way.
2009-06-04

blog image

Java One 2009 Day 3

Like every year, I offer a quick script for packrats who want to download the slides for all the talks. Of course, you can just wait for them to become available online after the conference, but then you'd not be a true packrat. Here goes:
2009-06-03

blog image

Java One 2009 Day 2

I do this to myself every year. I go to the opening keynote on Tuesday. I suffer through the love-in-with-Sun-partners part, just so I can get to the good part with the important announcements. Then I go to the Wednesday keynote, which offers no such benefit, and vow never to go to any other keynote except for James Gosling's toy show.
2009-06-02

blog image

Java One 2009 Day 1

I am no fan of keynotes, but I figured I should earn my press pass (thanks Jacki!) and show up.
2009-06-01

blog image

Java One Day 0

Today is day 0 of Java One, AKA “Community One,” with a focus on open source and community projects. With the economy being what it is, and Java One stretching the definition of “early bird” specials past the breaking point—the discount was good until today—I was fearing for the worst, but there definitely were crowds today.
2009-05-28

blog image

The Fit and Finish of JSF

When I come across an article such as this one, I am overcome with melancholy. I really want to love JSF. Its heart is in the right place. It wants to let me drag and drop components onto a form, wire them up with JavaBeans, and give me AJAX with essentially no work on my part. And it comes so close.
2009-04-21

blog image

My Oracle Pronouncements for Java

As everyone knows from yesterday morning's news, Oracle has made an offer to buy Sun Microsystems, Sun has accepted, and the acquisition is expected to go through by the summer.
2009-04-06

blog image

Much A-do About Nothing

In general, a for loop may be used if the number of repetitions is known, as for example, when you need to print a message a hundred times. A while loop may be used if the number of repetitions is not known, as in the case of reading the numbers until the input is 0. A do-while loop can be used to replace a while loop if the loop body has to be executed before the continuation condition is tested.

2009-02-15

A Simple Servlet for Running JUnit in Glassfish

When teaching unit testing in the context of a simple EJB3.1 application, I was looking for an easy way of testing managed beans and session beans inside Glassfish. Of course, one can test out-of-container or use an embedded container (but I didn't quite figure out how to do that with Glassfish v3I'd appreciate hints), or a mock container (but that seemed to require a bit of setup).
2009-02-09

blog image

Long in coming...

A Thinkpad sale seduced me into upgrading my laptop. My feeble rationale was that I could stop dual-booting, use Linux on the new laptop and Vista on the old one. So, I got a shiny new Thinkpad T500 for under $1,000, blew away Vista Homeless Edition, and installed Ubuntu Jaunty Alpha 4. I expected the usual fussing with wireless networks, display adapters, and futile fights to activate exotic peripherals. I was totally disappointed. Everything, and I mean everything, down to the webcam, worked after a 30 minute install with one reboot and no fussing. With an alpha release.
2009-02-02

blog image

Towards Java EE Nirvana

Java EE 6 makes it pretty straightforward to crunch out a basic web + database application. This semester, my software engineering class is building web apps, and I decided it is simpler to have them use JSF + JPA in Glassfish v3 rather than some technology that seems easy at first and then lets them down.
2009-01-22

blog image

A Call to Fix the JCP Oberver Status

In this blog, I report on my disappointing experience with the JCP observer status, and suggest that another dose of glasnost is needed to fix the process.
2009-01-21

blog image

A simple JSF2+AJAX example

In this blog, I go over a very simple JSF2+AJAX example and show how one can spy on the inner workings with the TCP monitor and debugger.
2008-12-18

blog image

Baby Steps with JSF2

There are several blogs that tell you how to do fancy things with the upcoming JSF 2 (such as these by Ryan Lubke and Jim Driscoll). In this blog, I look at the other side of the coinhow the simplest things are working out. After all, if Ruby on Rails has taught us anything, it is that a technology that makes the simple things simple has a great shot at getting developer mindshare.
2008-12-03

blog image

What Worked for Our Blackberry Project

After many weeks of labor, my software engineering class is ready to deliver our BlackBerry project to Cinequest, the organizers of the San Jose Film Festival. Moviegoers will be able to check the schedule on their Blackberry devices, see when their favorite films are playing, and find out about the latest special events.
2008-12-01

blog image

Where is the source?

This semester, my software engineering class is working on a project to bring the San Jose Cinequest film festival catalog to the Blackberry. RIM has generously donated us some devices.
2008-11-17

blog image

Grief with Gantt charts

Occasionally, I have to put together a project schedule with a Gantt chart. In my software engineering class, I figured I should use something cross-platform and open-source, and not Microsoft Project, which I vaguely remember as a muddleheaded mess.
2008-10-17

blog image

Restless about REST

In my software engineering class, we are designing an application that shows films and events for the Cinequest film festival on Blackberry devices. We need to get film schedules and descriptions from a server onto the mobile phones. A typical query would be: “Show all movies playing today”.
2008-10-06

blog image

Core Java Refcard

My second "refcard" has been published by DZone. This time, the DZone team managed to cram an unbelievable amount of Core Java language and library facts onto a small PDF file. Check it out here.
2008-10-05

blog image

Know When to Fold

I am teaching an undergraduate course in programming languages. We build interpreters and compilers for toy languages, in the hope that students gain a basic understanding of syntax, semantics, and language translation.
2008-09-17

blog image

Teaching Software Engineering with BlackBerry

One of the best aspects of my job as computer science professor is that I keep learning new stuff. This semester, I am teaching a software engineering class. Cinequest, the organization that puts on the annual San Jose film festival, approached the CS department, asking for help with their mobile initiative. We jumped at the chance, and now my students are hard at work designing and prototyping a BlackBerry application for festival attendees.
2008-09-15

blog image

JSF Refcard available

When I traveled to the U.S. as a nerdy teenager, I was fascinated by those laminated reference cards. It seemed yet another example of boundless American optimism that one can cram an entire semester's worth of information into two pages.
2008-09-15

blog image

Applet Dragging in Linux

Being a Linux user, I watched those applet dragging demos with envy when they only worked on Windows. When the release candidate of JDK 6 update 10 (now there is a product name only a mother could love...) came out, I was eager to try it out on Linux. Initially, I was held back by a factor entirely beyond my control, i.e. my cluelessness and unwillingness to read the docs. Thanks to Aaron Houston and Ken Russell for helping me out. Here are the steps:
2008-09-10

blog image

Teaching Programming Languages with Scala

This semester, I am teaching the undergraduate programming languages course at SJSU, a required course for CS majors. The course has two objectives:
2008-09-05

blog image

Lessons from My Summer Vacation

In this blog I reflect on what I learned during my summer vacation, about standards, folding travel beds, and snatching defeat from the jaws of victory.
2008-07-30

blog image

Summer School in Switzerland

In this blog, I report on how I am spending my summer vacation (or at least a part thereof) as a guest lecturer in a summer program in beautiful Canton de Vaud, Switzerland.
2008-05-23

blog image

What do CS students learn?

On May 23, I gave a presentation at Sun about computer science students, and how a company can engage with them (audio | slides). Here are some of the questions that I was asked, and the answers that I gave (or wish I had given), and a question that I wish I had been asked.
2008-05-09

blog image

j1-2008-day4

The hardware, the OS, and the JVM are ready for large numbers of cores.

The languages, the tools and the programming community at large are not ready for large concurrent programs.

So... good luck, guys!

2008-05-08

blog image

j1-2008-day3

During a meeting in the Community Corner (java.net booth) with James Gosling, a participant asked an interesting question: "Which Programming Language would you use *now* on top of JVM, except Java?". The answer was surprisingly fast and very clear: - Scala.

2008-05-07

blog image

j1-2008-day2

Here is my report from day 2 of Java One. I continue to feel diffident about RIA and Java FX Script, the theme of this year's Java One, so I decided to make my own themes: Ease of development, and transparency.
2008-05-06

blog image

j1-2008-day1

Here is my braindump from Information Overload Central, AKA Java One 2008.
2008-05-05

blog image

j1-2008-day0

Last year, Java One Day 0 was Netbeans Day, in a cozy hotel. This year, the Java One week started much more grandly, with Community One, at the Moscone Center. There were tracks for a number of open source communities, including NetBeans, GlassFish, MySQL, OpenSolaris. Frankly, I preferred the cozy hotel, but I can see that it is savvy marketing by Sun to have a large-scale free community event.
2008-05-04

blog image

On Blue-Collar Languages

I ran across this tech tip on using wildcards in Java generics. Pretty basic stuff, I thought. But I was amazed by the comments:
2008-04-05

blog image

Is Computer Science the New Latin?

This Washington Post article reports on the elimination of underenrolled Advanced Placement (AP) courses in American high schools. The subjects affected are: Italian, Latin Literature, French Literature and, hold on to your hats, Computer Science AB. (The College Board designs high school courses that aim to be equivalent to college courses. High school students who take the course and pass an exam are often given college credit.)
2008-03-01

blog image

feel-of-java

Last time, it took me at least 10 hours to do one of the problem, but i got through #1 in less than 1/2 an hour. most of it was copy and paste. I didn't even need more than 1 class. am i missing something? It's almost as if you can lift the solution out of the labs. All I had to do was write 2 really really really simple closures.

2008-01-21

blog image

Swing for the Web--Are We Getting Closer?

When I first heard about JavaServer Faces, way back at the 2002 Java One conference, it was sold as Swing for the Web. That caught my attention. I was sick of assembly programming for the Web with HTML, JavaScript, HTTP, cookies, servlets, and that special form of tortureJSP custom actions. Ever since, I have pinned my hopes on JSF because it has one thing going for it: a component model. When I need, say, a progress bar, I want to leave it to someone more skilled than me to make such a thing out of images, JavaScript, or whatever. I just want to hook it up to some property that has a progress value and move on to the next task. After all, when I use a JProgressBar in Swing, I don't worry about the pixels and animations either.
2008-01-08

blog image

Dinosaurs Can Take the Pain

There has been much discussion on whether Java programmers are becoming dinosaurs, on an evolutionary dead end and overtaken by more nimble mammals. Bruce Tate has long abandoned Java for greener (or redder) pastures. Bruce Eckel has embraced Flex , Bill Venners favors Scala. Python is making inroads in college curricula. What is a Java programmer to do? In this blog, I argue that we need to focus on less on syntax and more on the pain points of Java programming.
2007-12-29

blog image

The OLPC and Java

With Java, I can replace my computer with a $500 Internet appliance.

2007-12-20

blog image

Properties Get No Respect

There has been another flurry of discussions about closures in Java and minor language enhancements, together with the usual flurry of leave the language alone lamentations.
2007-12-12

DSLs--Standalone or Embedded?

I am a reviewer for Java One. I have about 350 project proposals to plow through and not enough time to give each of them justice.
2007-08-17

blog image

Flying Saucer Comes Through with Flying Colors, or the Triumph of Infrastructure

I had to render a set of presentation slides in HTML Slidy format into images. This blog entry shows how to carry out this task with the excellent Flying Saucer XHTML renderer and concludes with some ramblings about infrastructure.
2007-08-01

blog image

A Bundle of Joy - NOT.

Today, I rant about Sun's blunder in their bundling of JavaDB in JDK 6. Executive summary: 1. Don't rely on JavaDB being present in the JDK. 2. A bungled bundle is worse than no bundle at all.
2007-07-14

The grass isn't greener on the other side

Today, I am in beautiful San Diego, at a NSF workshop on active learning and UCSD's Ubiquitous Presenter software. Ubiquitous Presenter lets instructors and students add pen-based markup to slides and share them with each other. It is a nifty tool to engage students in the classroom instead of just lecturing. The student part of the software uses Java, and students can use the mouse or a tablet pen (which just acts as a mouse) to add their notes. The instructor part of the software uses .NET because instructors need to be able to write nicely, and Java doesn't have any support for pens (pressure, erasing, etc.).
2007-07-07

blog image

Number melancholy

Changes in 1.6.0_02

The full internal version number for this update release is 1.6.0_02-b05 (where "b" means "build"). The external version number is 6u05.

2007-07-02

blog image

JSF Support in Eclipse Europa and NetBeans 6.0m10~

When Eclipse Europa was released on June 29 (together with the iPhone and the GPL 3 license), I wanted to know if it did anything about one of my many pet peeves: tool support for writing JSF apps. In this blog, I will compare Eclipse 3.3 and NetBeans 6.0 milestone 10 to see how they do on the world's most mundane JavaServer Faces application: the login example from Core JSF.
2007-06-11

blog image

The Single Thread Rule in Swing

Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread.

2007-05-11

blog image

Java One Day 4

This is my last day as the intrepid reporter at Java One. The press room, which had become my home away from home, was closed. Instead of snarfing up the baked goods and looking for the secret stash of booze, I chatted with lots of interesting folks in the halls of Moscone, attended a couple of sessions, and pondered what it all meant.
2007-05-10

blog image

Java One Day 3

This is my third day of reporting from the floor of Java One. I ran into a number of very interesting folks, got the chance to ask more hard-hitting questions, and had a mixed bag of sessions.
2007-05-09

blog image

Java One Day 2

This year, I got a genuine press pass from a kindly soul at Sun. While my quest for priority seating was still futile, I made progress on my quest to locate the stash of free booze, and I got the chance to ask more hard-hitting questions. Here is your intrepid reporter's take on day 2.
2007-05-08

blog image

Java One Day 1

This year, I got a genuine press pass from a kindly soul at Sun. I was excited about priority seating and unlimited free booze in the press lounge, neither of which I was able to locate. But I did get to ask hard-hitting questions in the press conference. Here is your intrepid reporter's impression of day 1.
2007-05-07

blog image

Java One Day 0

This year, I got a genuine press pass from a kindly soul at Sun, which entitles me to priority seating at the keynote, the opportunity to ask hard-hitting questions in the press conferences and unlimited free booze in the press lounge (I hope).
2007-04-17

blog image

What's so Taxing about Return?

Some responses to my blog on Neil Gafter's closures talk showed concern with the handling of the return statement in BGGA closures. Since I am done with my tax return, I am blogging about the intricacies of the return statement inside closures.
2007-04-12

Dr. Gafter comes to SJSU

I teach a graduate programming languages class at San Jose State University. In order to inject some topics of current interest, I had a lab about closures and the competing closure proposals for Java 7. I got an email from Neal Gafter: Hey, it's really cool to see your reference to BGGA in a SJSU lab assignment! I asked if he could give a talk at the department seminar, to which he graciously agreed. We had a packed room today. I am very excited that my students had a chance to witness a bit of history in the making. Here are my impressions of the talk.
2007-01-28

blog image

Microsoft Patents BlueJ Workbench

BlueJ is a tool for teaching OO programming in Java that is very well regarded in the CS education community. Microsoft engineers who were familiar with the BlueJ "workbench" added a similar feature to Visual Studio, didn't give credit to the BlueJ inventors, and filed a patent application. Not the way to win the hearts and minds of the education community.
2007-01-12

blog image

Properties are Design Features

The discussion about properties had reached a fever pitch in the last weeks, and there is a great deal of dissent about the nature of properties. Are they meant for tools, are they the tool of the devil to seduce us away from the goodness of OO, or are they just an irrelevant preoccupation of programmers who have no tolerance for boilerplate? In this blog, I would like to argue that properties are legitimate design features, and that it is the job of a programming language to allow faithful mapping of design intent to code.
2007-01-10

blog image

Pie in the Sky Properties

Jacob Hookom has been vocal about doing properties right rather than simply generating getFoo/setFoo methods. Of course, you still want the JavaBeans introspector to work correctly. I thought it would be interesting to run with this idea and see where it gets.
2007-01-07

blog image

Arrows in the Back

There has been a flurry of recent blogs on native property syntax, much of it rather emotional. This blog tries to get past the emotions, hoping to garner interest in the real issues that need to be solved for native properties.
2007-01-03

blog image

A JDK6 JavaScript Console Conundrum

I just discovered the JavaScript console (jrunscript) inside JDK6. Pretty nifty for running quick-and-dirty tests. Or so I thought until I ran into a bizarre problem with that most exotic of classes, java.lang.String.
2006-10-22

blog image

The World's Simplest Unit Testing Framework

I describe the world's simplest Unit testing framework for teaching Java to beginners.
2006-09-08

blog image

The Power and Pain of POJOs

I wrote a quick-and-dirty quiz application to check whether my software engineering students do their reading assignments (or at least google quickly). Can an Elvis-level programmer do this in a couple of days with EJB3 and JSF? Here is my experience report.
2006-08-23

blog image

How Not to Report an Internal Error

NetBeans pops up a dialog with an exception message when it finds an internal error. And again. And again. And again. And again. This blog reviews just how user-hostile this behavior is, and suggests alternatives.
2006-07-17

blog image

Track+ On GlassFish

Directions for setting up the Track+ bug tracking system on GlassFish. This is all boring, and I just put it up for reference. If you are looking for something fun, follow one of the links in the second paragraph instead.
2006-07-17

blog image

Installing GlassFish and PostgreSQL on Ubuntu Server Edition

I don't do LAMP, I do JELP (Java, EE5, Linux, PostgreSQL). Here are instructions for installing Java, GlassFish and PostgreSQL on Ubuntu 6.06 "Dapper Drake" Server Edition. No gotchas, just a bunch of steps that I hadn't found together in one place.
2006-07-12

blog image

Certified Insecurity

I used Java Web Start as a "poor man's installer" for a Java client app that allows students to check their homework assignments. The app needs "all permissions", so I simply signed it with a worthless self-signed certificate. The Web Start security dialog is complete gibberish to 99% of end users, which works in my favor. Something is wrong here. Should the JNLP API be less convoluted, so that it is easier to live in the sandbox. Should it be less of a hassle for an individual to get a real certificate?
2006-07-05

blog image

Railroad Diagrams

Does anyone still use railroad diagrams (AKA syntax diagrams)? If so, how do you produce them?
2006-07-03

blog image

Don't Lie to the Entity Manager

JPA is the new object-relational mapping standard that you can use in EJB3 or in standalone applications. For the most part, it is phenomenally easy to use. But there is a trap that has bitten more than one developer. If you ever lie because your fibbing won't affect the database, your lies can still come back to haunt you. This blog gives two examples.
2006-06-25

blog image

An EJB 3 Glossary for Elvis

I am working on a glossary of EJB 3 terms that gives both the official definitions and explanations that Elvis can understand. (Elvis is the programmer persona who is neither Einstein nor the point-and-click/drag-and-drop "just give me a wizard" Mort.) What other definitions would you like? Do you spot errors or inaccuracies? Please let me know.
2006-06-21

blog image

Why Java Developers Should Switch to Linux

It's summer again, people have more time on their hand, and they think about switching operating systems. I'd like you to consider switching to Linux. It's not cool, but you get to enjoy freedom from crapware and forced upgrades, keyboard shortcuts, and great Java support. There is just one drawback. Unlike the Mac crowd with their distinctive-looking hardware, you'll need a garish Linux sticker so that the world can see you aren't running Windows.
2006-06-13

blog image

Honey, I built the JDK! (on Ubuntu)

These are my notes for building Mustang on Ubuntu 6.06. Amazingly enough, this works with just a small number of easily fixed issues. This is good news if you want to tinker with the JDK on Ubuntu. Even if you don't, it is comforting to know that the Mustang build process is robust enough to allow the tinkerers to use it on their favorite platform, so that you can benefit from their labors.
2006-06-09

blog image

The innermost secrets of -javaagent:toplink-essentials-agent.jar revealed

I had been mystified by what exactly the magic incantation -javaagent:toplink-essentials-agent.jar does for JPA clients, and my experiments had been inconclusive. I finally figured it out. Here is the answer in terms that Elvis can understand.
2006-06-08

blog image

Say No to Properties Boilerplate!

Nobody likes to write properties boilerplate--the getter, the setter, the Javadoc for the getter, the Javadoc for the setter, you know the drill. Ok, you say, Eclipse writes it for you. But you still have to read it. Pages and pages of it in many real life classes. My graduate student Alexandre Alves implemented a Mustang compiler extension to remove the drudgery. We want to get this feature into Dolphin and need your help. Try it out and let us know what you like and what needs work!
2006-06-07

blog image

Programmer Productivity, JSF, and NetBeans

My first impression using NetBeans 5.5 for JSF 1.2 development: Not easy on the eyes, but the debugger, HTTP monitor, and GlassFish integration dramatically increased my productivity.