<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Cay Horstmann&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/" />
<modified>2008-05-10T02:51:24Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2008, cayhorstmann</copyright>
<entry>
<title>Java One Day 4</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/05/java_one_day_4_2.html" />
<modified>2008-05-10T02:51:24Z</modified>
<issued>2008-05-10T02:51:16Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9776</id>
<created>2008-05-10T02:51:16Z</created>
<summary type="text/plain">Day 4 of Java One is over. Even without huge announcements or great
surprises, it was a great conference. Here are my impressions from the cool
stuff keynote and my takeaway what it all means.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p>Day 4 of Java One is over. Even without huge announcements or great
surprises, it was a great conference. Here are my impressions from the cool
stuff keynote and my takeaway what it all means.</p>

<h2>The Cool Stuff Keynote</h2>

<p>My mind wanders during most keynotes, but I always enjoy James Gosling's
cool stuff keynote on the last day of Java One. No marketing, just one
amazing Java-powered piece of hardware or software after another. Here is
what caught my attention:</p>

<ul>
  <li>Tor Norbye demoed the JavaScript support in Netbeans. Here is a man who
    can give a better presentation typing code on the screen than most people
    can with the slickest slides. (Not wanting to name names [Hi, Ed...] but
    this is not something most presenters should try...) He types a line of
    code, something cool happens effortlessly, whoops, he makes a typo...no,
    that wasn't a typo but a calculated manoeuver to show off error handling.
    A few years ago, I saw him briefly flustered by a bug which he fixed on
    the fly, talking all the time as if nothing happened, and then he
    continued the demo. 
    <p>Those Java-powered micro-sensors draw so little energy that they can
    be powered by ambient vibration. The presenter gave one convincing
    application: sensors in beer coasters that would communicate through the
    mesh network which glasses were empty or not cold enough. I suppose the
    sensors ask each other: &ldquo;Do you come here often?&rdquo; A bit
    off-topic...so many engineering colleges persist in teaching C++ to
    freshmen because obviously nobody would use Java for embedded
    development. With the sensors, smart cards, and industrial controls that
    we saw today, I am not sure how much longer that will be the wise choice.
    My guess is that the users of those technologies are willing to pay for
    the Java layer because it gives them <em>ease of development</em>, my
    personal theme of this Java One.</p>
  </li>
  <li><img alt="" style="float: right; margin-left: 1em;"
src="http://weblogs.java.net/blog/cayhorstmann/archive/java-pen1.png" />James Gosling asked the fellow who showed off the Java-powered <a
    href="http://www.livescribe.com/">Pulse pen</a> the exact question that
    was on my mind: &ldquo;Why would anybody want a computer in a pen?&rdquo;
    But the demo was very impressive. Check it out on the video, starting at
    56:15. Too bad the docking requires Windows.</li>
  <li>The keynote ended with some big science: <a
    href="http://jmars.asu.edu/">JMars</a> and the use of Java at CERN. When
    Gosling visited a control room at CERN that was filled with monitors, he
    asked whether they had any Swing apps. Well, all of them were Swing apps.
  </li>
</ul>

<h2>Concurrency</h2>

<p>Unfortunately, I managed to miss two good talks by Brian Goetz, which does
not stop me from pontificating about concurrency, of which I know very
little. Check out the excellent slides for TS-5515 and TS-6206. TS-5515 is
about the fork-join framework that lets you parallelize certain tasks (such
as searching or combining array elements) with a fairly reasonable syntax
(which, BTW, would look quite a bit more reasonable with closures). The
reason I am getting concerned about this issue is neatly summarized in the
overview slide of TS-6206:</p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/mountain-climbers.jpeg"
style="float: right; margin-left: 1em;" /></p>

<blockquote>
  <p>The hardware, the OS, and the JVM are ready for large numbers of
  cores.</p>

  <p>The languages, the tools and the programming community at large
  <strong>are not ready</strong> for large concurrent programs.</p>

  <p>So... good luck, guys!</p>
</blockquote>

<p>Last year, Brian had suggested that I check out actors and software
transactional memory. I managed to learn a bit about actors, by the expedient
device of assigning my students lab work with Scala actors. </p>

<p>Actors share no state...except when I am a knucklehead. The Scala actors
are closures and&mdash;Josh Bloch will love this one&mdash;more than once I
accidentally captured a variable from an enclosing scope in an actor. Ok,
they don't share state, and they communicate by sending messages. So, you
break up your task into actors, each of them does a bit of work, and then
they send a message to some other actor that combines the results. How does
it know when it is done? You send some other message with a total count. It
takes a bit to get used to it.</p>

<p>I then solved the task with Java locks&mdash;tedious as usual, and the
nagging feeling that I overlooked something, as usual. Finally, I used
<code>java.util.concurrent</code>. That was pretty easy...for me. Judging
from some very blue-collar comments on the class discussion group, some of my
students had a much harder time with the Java constructs than with actors.
So, maybe actors are good, and in Scala, they can certainly scale. But
concurrency utilities are also good, if you know what you are doing. (Buy
Brian's book...)</p>

<p>In the presentation, Brian writes: STM (Software Transactional Memory) is
a not-yet-here technology that takes locking decisions out of the users
hands. </p>
<ul>
  <li>Commonly compared to "garbage collection for concurrency"</li>
  <li>With a name like that, who wouldn't want it?</li>
  <li>Despite widespread enthusiasm, still a research subject </li>
</ul>

<p>I'll suppose my students will learn more about that next year :-)</p>

<h2>Web Services...Not!</h2>

<p>When SOAP web services first appeared, I thought simple...object...who
wouldn't want them? Well, when I was bombarded with JAX-this and WS-that,
when all I wanted to do was get some stuff from a server, I felt like those
people in the &ldquo;future Java features&rdquo; BOF. I knew I wanted
something...just not that. I looked at the TS-5425 slides to see whether REST
would save me, and I am cautiously baffled. </p>

<p>So...here is my test to see when web services have truly arrived... Today,
being a packrat, I downloaded all the presentation PDFs. I manually logged in
to the schedule builder, queried for all sessions, did View Source, saved the
source to a file, and ran </p>
<pre>for f in `grep -o "/[^/]*.pdf out.html` ; do echo wget --user contentbuilder --password doc789 http://www35.cplan.com/cb_export/$f ; done</pre>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/scraping-paint.jpg" width="225" height="161"
style="float: right; margin-left: 1em;" />I know that web services have truly
arrived when that most pathetic of tools, Sun's schedule builder, publishes a
web service (SOAP or REST&mdash;their choice) that lets me get the schedule
data as objects and stash away the presentations, without scraping HTML.</p>

<p>In the meantime, if anyone has a pointer to some tool that records browser
activity over multiple pages and gives me Java code to replay it (for
HTTPUnit or something similar), I'd be very grateful. I have to do HTML
scraping all the time with the IT systems at my university. Nobody there is
telling me &ldquo;just call this web service&rdquo;.</p>

<h2>What Does It All Mean?</h2>

<p>Another Java One is over. I had a great time meeting a lot of interesting
people, I learned a lot, and I think it is an excellent conference even when
there are no huge announcements or great surprises. Here is my personal
take-away. </p>

<p><img alt=""
src="http://www.spd.de/show/1683621_l1/plakat_bundestagswahl_wehner_1969.jpg"
style="float: right; margin-left: 1em;" /></p>
<ul>
  <li><strong>Incremental improvements.</strong> One of Germany's great
    post-war politicians, Herbert Wehner, likened politics to the tenacious
    drilling through thick pieces of wood. The Java community has that
    tenacity. Bad stuff gets fixed, and good stuff just get better every
    year. If you hated Java technology X, have another look. Chances are it
    is much better today. The Swing app framework, JPA 2.0, Web beans, ever
    more amazing IDE support, are all very good at reducing drudgery and
    increasing productivity. </li>
  <li><strong>Multiple languages on the JVM.</strong> As much as I would
    personally like to see more vigorous evolution of the Java language, I
    can appreciate that the majority of Java users don't share that
    eagerness. Mixed-language use will become a fact of life. It is just a
    matter of time when I'll start a project in my IDE and, instead of
    choosing &ldquo;Java project&rdquo; or &ldquo;Scala project&rdquo;, I'll
    check multiple boxes. </li>
  <li><strong>Healthy skepticism, transparency, and community.</strong> As an
    Apple developer, you better like Kool-Aid. As a Windows developer, you
    are stuck with what is handed down from the top. In Java, you don't have
    to love everything, decision making is by and large not a black box, and
    the community gets to participate.</li>
</ul>]]>

</content>
</entry>
<entry>
<title>Java One Day 3</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/05/java_one_day_3_1.html" />
<modified>2008-05-09T06:57:53Z</modified>
<issued>2008-05-09T06:57:37Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9757</id>
<created>2008-05-09T06:57:37Z</created>
<summary type="text/plain">My day 3 at Java One ranged from the Nimbus UI and the future of JSF to interesting discussions about closures and Scala. Details below. </summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p>My day 3 at Java One ranged from the Nimbus UI and the future of JSF to
interesting discussions about closures and Scala. Details below. </p>

<h2>Nimbus</h2>

<p>The presentation on the <a
href="https://nimbus.dev.java.net/spec/index.html">Nimbus look and feel</a>
was packed. Nimbus is a pretty L&amp;F, and it will be the standard for Java
FX. Everything is vector-drawn, so it will scale nicely to high-resolution
displays. (Check out this nifty <a
href="https://laffy.dev.java.net/">sampler</a>.) I would like to tweak the
colors a bit, perhaps make the <code>nimbusSelection</code> less green. In a
Java program, or in a L&amp;F JAR, I can do that by calling
<code>UIManager.put("nimbusSelection", new Color(...))</code>. I asked what
the story for end-user tweaking was, and was told that I'd have to edit
<code>swing.properties</code>. Ok, but how do I specify a color? </p>

<p><img alt=""
src="http://nimbus.dev.java.net/spec/images/JTable-Example.png" /></p>

<h2>JSF 2.0 (JSR-314)</h2>

<p>The JavaServer Faces 2.0 presentation was also packed. Ed Burns and Roger
Kitain listed some of the pain points (which I amplify a bit):</p>
<ul>
  <li>Component authoring is too hard</li>
  <li>Component kit producers had to invent mechanisms for resource loading,
    AJAX, that sometimes conflict with each other</li>
  <li>Configuration is way too tedious and dispersed over too many
  artifacts</li>
  <li>The need to frequently redeploy, and the &ldquo;stack trace from
    hell&rdquo; are productivity killers <img alt=""
    src="http://weblogs.java.net/blog/cayhorstmann/archive/2006-09-08/hell.png"
    style="float: right; margin-left: 1em;" /></li>
</ul>

<p>JSF 2.0 will be based on facelets, which should really help with error
messages. </p>

<p>There were demos of a page description language and the ability to author
components using Groovy (see also <a href="http://blogs.sun.com/rlubke/">this
blog</a>), and also some AJAX stuff that went over my head. </p>

<p>There was no information about how configuration will look like.
Hopefully, we'll get a Seam-like navigation option and annotations for
managed beans. Or better, Web beans. I asked Ed about the strategy for
Seam-like Web beans, but it all seems still very much in the planning stage.
It is all supposed to be done by Java One 2009, so hopefully things will get
moving soon :-)</p>

<h2>Blue-Collar Types</h2>

<p><img alt=""
src="http://weblogs.java.net/blog/cayhorstmann/archive/blue-collar.jpeg"
style="float: right; margin-left: 1em;" />When discussing the complexities of
wildcards and closures, the issue of types kept coming up. I really like
compile-time typing. It enables the compiler to catch stupid mistakes, and it
enables the IDE to do auto-completion. Of course, there is a tradeoff: I
can't share code like the duck-typers do. For example, no</p>
<pre>max(x, y) { return x &lt; y ? x : y }</pre>

<p>But I don't want to catch everything at compile time if the cost is too
high. For example, C++ checks for <code>const</code> at compile-time. It is a
pain in the rear, and Java wisely decided not to do that. I am not sure that
the various experiments with compile-time checks against unintended null
pointers are worth the trouble. I am not even sure that checked exceptions
are so great. In particular, I am mightily tired of propagating the
<code>InterruptedException</code>. </p>

<p>I find that Java arrays (with covariance and the array store exception)
are a reasonable compromise. A number of people who feel strongly about this
gasped when I expressed that sentiment, admonishing me that this is
<strong>unsound</strong>. Well, life is unsound. </p>

<p>Every language makes tradeoffs between compile time and run time checking.
I think with generics, we may have tried to check too much at compile-time.
Consider <a
href="http://blogs.sun.com/abuckley/en_US/entry/new_t_is_not_possible">this
blog</a> by Alex Buckley where he explains why we can't have a generic
<code>new T()</code>. The type system cannot ensure that there is a no-arg
constructor. Ok, but that doesn't mean that we can't have the feature. One
could make a run time check. My feeling is that the type system should be my
servant, not my master. </p>

<h2>Closures </h2>

<p>Martin Odersky and I chatted about the wildcard syntax and the history of
generics. He said that the Sun folks approached the introduction of generics
very cautiously because they did not want to repeat the disaster of inner
classes! At the time, inner classes were perceived to be a short-sighted
reaction to C# delegates, with ugly syntax and initially underspecified
semantics. Indeed, it took many years for the generics proposal to mature.
Wildcards were literally tossed in at the last minute. (The <code>? super
T</code> syntax was suggested at Java One, shortly before the Java 5 release,
by someone in the audience of Gilad Bracha's presentation, to replace the
proposed <code>T extends ?</code>.) </p>

<p>Now, of course, we have people urging caution with closures so that we
don't repeat the disaster of generics. </p>

<p>Alex Buckley told me that he asked in the &ldquo;future language
features&rdquo; BOF how many people wanted closures. Lots of people, more
than half the room, raised their hands. How many wanted BGGA? Maybe 6. CICE?
Maybe 6. FCM? Maybe 5. </p>

<p>I ran into Josh Bloch, and he walked me through a presentation about some
nasty aspects of BGGA closures. Among them: </p>
<ul>
  <li>To properly do a control structure where a variable can be either one
    of the 8 primitive types or a reference type, one would need to declare 9
    variants. Make that 81 variants if two variables are involved. Or somehow
    throw more autoboxing at the problem. I agree this is nasty. I sure wish
    Java didn't have those 8 primitive types.</li>
  <li>Non-local return is bound to be confusing. I agree. The trouble is that
    there are two use cases: the &ldquo;snippet of code&rdquo; use case and
    the &ldquo;control structure&rdquo; use case, where Java programmers have
    opposing intuition what <code>return</code> means. I still hope that this
    can be salvaged. Perhaps by outlawing <code>return</code> outside control
    invocations, but Neil Gafter doesn't like that.</li>
  <li>Capturing a non-local variable can be surprising. Josh had an
    unpleasant example where a closure captures a <code>for</code> loop
    index. I can see how this would be baffling to a programmer who is
    unaccustomed to closures, i.e. most Java programmers. </li>
  <li>There is no way to implement the Java <code>for</code> loop with BGGA
    syntax. For example, you couldn't do <code>myFor(int i = 0, j = 0;
    ...)</code>. True enough, but it doesn't bother me. I'd still like
    <code>with</code>, <code>withLock</code>, <code>doLater</code>, even if
    they don't have 100% the same syntax as <code>for</code>.</li>
</ul>

<p>Josh doesn't think that there is much in terms of the &ldquo;etc.&rdquo;
Is a handful of control structures worth the considerable hassle? He makes a strong case that the hassle is considerable.  I still
prefer closures over inner classes, and I am holding out some hope that a
clearer syntax will emerge. </p>

<h2>Scala</h2>

<p><img alt="" src="http://www.scala-lang.org/images/scala_logo.png"
style="float: right; margin-left: 1em;" />If the Java language is
increasingly resistant to large-scale evolution, what is a programmer to do?
Is it time to plan the escape from the Java prison? Like so many other
people, I have been looking at <a
href="http://www.scala-lang.org/">Scala</a>. Martin Odersky has given his
Scala talk again. I liked the talk much better this year than last. 
Maybe because the Scala syntax looks much more familiar after I had used it a
bit. Maybe because I now believe his claim that a typical Scala program uses
half the lines of code as the equivalent Java program--because that is
exactly what happened to me. It is so liberating to do without all that
boilerplate that you have in Java. </p>

<p>Clearly, Scala is not a blue-collar language, and I cannot see every Java
programmer flocking to it. But I would like to get more experience working
with a project that mixes Scala and Java. Preferably with IDE support. There
is an Eclipse plugin that is &ldquo;getting better&rdquo;, and just recently
Caoyuan Deng has made <a
href="http://blogtrader.net/page/dcaoyuan/entry/scala_for_netbeans_screenshot_11">amazing
progress</a> with a Netbeans plugin. <a
href="http://www.adam-bien.com/roller/abien/entry/java_net_javaone_which_programming">Adam
Bien</a> relates this story: </p>

<blockquote>
  <p>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: - <strong>Scala</strong>.</p>
</blockquote>
]]>

</content>
</entry>
<entry>
<title>Java One Day 2</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/05/java_one_day_2_1.html" />
<modified>2008-05-08T15:28:08Z</modified>
<issued>2008-05-08T07:30:53Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9744</id>
<created>2008-05-08T07:30:53Z</created>
<summary type="text/plain">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&apos;s Java One, so I decided to make my own themes: Ease of development, and transparency.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p>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.</p>

<h2>Swing App Framework (JSR-296)</h2>

<p><img alt="" src="http://appframework.dev.java.net/images/swing-logo.png"
style="float: right; margin-left: 1em;" />Hans Muller gave a presentation on
the <a href="https://appframework.dev.java.net/">Swing app framework</a>, a
great example for ease of development. Some people think Swing is dead, but
there are more people crunching out Swing apps than VB apps. I imagine mostly
corporate stuff. The presentation was pretty well attended. </p>

<p>To customize and internationalize components, set their <code>name</code>
property (either programmatically or in the GUI builder), and then populate
resource files with instructions such as</p>
<pre>infofield1.font=Arial-PLAIN-12
infofield1.icon=dynamite-stick.png</pre>

<p>For actions, define a method, tag it with the <code>@Action</code>
annotation, and then set accelerators such as </p>

<pre>submit.Action.accelerator=control S</pre>

<p>This is something I have been waiting for for a looong time&mdash;it
surely has been reinvented a million times (at least twice by me). Now it
will finally be a part of standard Java. The framework has many nice touches:
support for background tasks, pesky Mac OS X issues, and saving of session
state. If you write Swing apps, check it out! (Also check out <a
href="https://beansbinding.dev.java.net/">beans binding</a>.)</p>

<h2>JPA 2.0 (JSR-317)</h2>

<p>JPA is one of my favorite &ldquo;ease of development&rdquo; technologies.
I design my object model in Java, toss in a few <code>@OneToMany</code>
annotiations, and presto, I get a database schema, entity caching, and an OO
query language. I am not the only one who feels that way&mdash;the session
filled completely. Of course, there are a few issues in JPA 1.0 that even a
casual user such as myself runs into, mostly because the API was designed by
database wizards but it increasingly used by people who think in Java, not
SQL. I was glad to see that all my pet peeves are being addressed in JPA
2.0:</p>
<ul>
  <li>Ordered lists (e.g. a <code>Quiz</code> class with a field
    <code>ArrayList&lt;Question&gt; questions</code>). The order of questions
    matters to me, and I want an index column to be generated automatically.
    JPA 2.0 will have <code>@OrderColumn</code></li>
  <li>There will be support for sets of basic and embedded types, and better
    support for maps. </li>
  <li>There will hopefully be better support for prefetching lazy
    relationships. For example, when I detach a <code>Quiz</code> object into
    the web tier, I will want to prefetch the <code>Question</code> entities,
    and for each multiple-choice question, I want to prefetch the
    <code>Choice</code> entities.) The details are still being worked
  out.</li>
</ul>

<h2>Web Beans (JSR-299)</h2>

<p><img alt=""
src="http://qcon.infoq.com/london-2007/file?path=/QCon2007/photos/speakers_photo/gavin_king.jpg"
style="float: right; margin-left: 1em;" />Gavin King talked about Web beans.
I wanted to know whether/when we have will have something like <a
href="http://www.jboss.com/products/seam">Seam</a> as part of EE 6. For me,
the key feature of Seam is that I can hook a EJB session bean immediately
into a JSF page. (It is painful to access JPA entities in a JSF managed bean,
so right now, I shlep a bunch of stuff from JSF beans to EJB beans. Seam
avoids that tedium.) </p>

<p>Gavin is an opinionated and charismatic speaker, but he was opionated and
charismatic about a general-purpose plumbing mechanism that, once it becomes
part of Java EE 6, will make Seam-like components possible. It was quite
interesting if you are into meta-annotations, and the design looked very
clean. But I still don't know whether I will get Seam-like ease of
development when EE6 ships. </p>

<h2>JCP Roundtable</h2>

<p>Through the power of my press pass, I got into a &ldquo;JCP Roundtable
Discussion on Open Source and Open Standards&rdquo;. The table was actually
not round, just your usual long table with speakers <a
href="http://blogs.sun.com/pcurran/">Patrick Curran</a> (the <a
href="http://jcp.org/en/home/index">JCP</a> Chairman), <a
href="http://blogs.sun.com/abuckley/">Alex Buckley</a>, <a
href="http://www.jroller.com/scolebourne/">Stephen Colebourne</a>, <a
href="http://blog.springframework.com/rod/">Rod Johnson</a>, and other
luminaries. </p>

<p>Some things I learned:</p>
<ul>
  <li>It isn't just me who can't figure out what goes on behind the closed
    doors of some JSRs. One of the Java EE expert group members has trouble
    getting onto the internal email list of the servlet JSR. </li>
  <li>Everyone agreed that transparency should be the default for all JSRs,
    but it simply isn't so today. JSR-166, which Doug Lea ran completely in
    the open, just to show that it can be done, is still the exception. </li>
  <li>Alex Buckley said that one important part of transparency is for JSRs
    to not just publish a spec but to give the rationale for their decisions.
  </li>
</ul>

<p>All of this may be rather arcane for most users of Java, but as a book
author, I feel the pain caused by a lack of transparency. And, ultimately, so
do you. There are some JSRs that are best left unmentioned (such as <a
href="http://jcp.org/en/jsr/detail?id=127">JSR-127</a>) that would surely
have produced better specs if they had received more broad-based input. </p>

<h2>Java Champions BOF </h2>

<p>The Java Champions are a motley assortment of (Java luminaries|whiners and
complainers), including yours truly. <img alt="" src="http://weblogs.java.net/blog/cayhorstmann/java-champions.jpg"
width="106" height="106" style="float: right; margin-left: 1em;" />It is to
Sun's great credit that we get access to their executives, and that they even
listen to us (in <a
href="http://www.sun.com/aboutsun/media/ceo/bio.jsp?name=Robert%20Brewin">Bob
Brewin</a>'s case, not for very long :-)). Today, we had a BOF where we got
to do what we do best, and one of the common complaints was lack of
transparency. </p>

<p>Consider the case of Java FX. I am rooting for Sun and FX. You can't win
if you don't fight, and I give Sun a lot of credit for fighting. </p>

<p>I don't see what good it does to develop behind closed doors, and only
show a preview to a select few who <a
href="http://javafx.com/htdocs/signup.html">sign up and get chosen</a>. That
may work if you really know what you are doing (e.g. the iPhone but not the
Newton). But there is a reason that open source projects succeed with a
transparent development process where everything is out for anyone to see.
Let people whine and complain early and often, and you get great feedback
what you need to fix, before it is too late. </p>
]]>

</content>
</entry>
<entry>
<title>Java One Day 1</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/05/java_one_day_1.html" />
<modified>2008-05-07T07:36:00Z</modified>
<issued>2008-05-07T07:35:51Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9725</id>
<created>2008-05-07T07:35:51Z</created>
<summary type="text/plain">Here is my braindump from Information Overload Central, AKA Java One 2008. Java FX Script. EJB 3.1. Defective Java. Java Language Evolution.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p>Here is my braindump from Information Overload Central, AKA Java One 2008.</p><h2>Java FX Script</h2><p>The day started with, you guessed it, another keynote. I just can't stay focused during them, so FWIW, here is what I got out of it.</p><ul>  <li>Sensors let you figure out whether people leave a keynote early. </li>  <li>RFID tags are a mixed blessing. In passports, maybe not...Chief    scientist John Gage: &ldquo;Hi, I'm an American. Can you detonate the    closest device?&rdquo;</li>  <li>Sun's VP for software Rich Green promises huge announcements, great    surprises. He also says that Sun is the <strong>world's</strong> largest    open-source software provider <strong>on earth</strong>. </li>  <li>A fellow from Amazon (the shopkeeper, not the river) demonstrates the    <a href="http://www.amazon.com/kindle">Kindle</a> which, as it turns out,    is a Java ME device. I never knew that. Actually, I think that is good    news. Amazon quietly picked what they perceived to be the best technology    for the job. That's a much more credible validation than the usual    co-marketing arrangements (like those tacky &ldquo;Intel inside&rdquo; or    &ldquo;Designed for Windows&rdquo; stickers.). </li>  <li><span style="float: right; margin-left: 1em"></span><img alt=""    src="http://horstmann.com/corejava/cj8v2.png"    style="float: right; margin-left: 1em;" /><span    style="float: right; margin-left: 1em;"></span>Here is what was best    about the Amazon demo. The fellow demonstrated how to buy a Java book.    And which book did he pick from the multitude of choices? Yes, my    friends: <a href="http://horstmann.com/corejava.html">Core Java</a>,    authored by yours truly. He mumbled that it seemed to have good reviews.  </li>  <li>One thing that always bugs me about keynotes is when partner from    company X appears on the stage to share ... absolutely nothing. Can    anyone tell me what value the fellow from Sony Ericsson added?</li>  <li>The highlight of the keynote was Java FX Script. The pitch was that    there is intense competition for consumers' eyeballs, and that rapid    prototyping and frequent iterations are essential to develop the killer    UI that captures those eyeballs. </li>  <li>There was a cool demo where an applet was dragged off the browser and    dropped onto the desktop. I really liked that part. The    applet&mdash;written in Java FX Script&mdash;also ran (somewhat degraded)    in a low-rent ME phone. There was another cool demo with spinning video    players, all running at a good speed. </li>  <li>Delivery timeline: July 2008: JFX SDK EA. Fall 2008: JFX Desktop 1.0.    Spring 2009: JFX Mobile 1.0</li>  <li>The Glassfish 3.0 kernel is 98K. </li>  <li>Open JDK ships in Ubuntu. (To my delight, there was a fair amount of    applause from the audience.)</li>  <li>Sun is working on Project Hydrazine. Find. Merge. Deploy. Share.    Monetize. Huh. It has something to do with instrumenting Java FX apps and    sending data back to the trustworthy service deployer, not the evil    technology vendor. </li>  <li>Jonathan Schwartz is much better at explaining stuff. His take on Java    FX:    <ol>      <li>More devices: Linux, Mac, Windows, embedded devices</li>      <li>Performance (better VM)</li>      <li>Insight (instrumentation) </li>      <li>Free</li>    </ol>  </li>  <li>The keynote ended with Neil Young, a bard who pitched a multimedia    project that chronicles his life work on a set of Blu-Ray disks. The UI    was very pretty...Java-powered, of course.</li></ul><p>A few months ago, I had asked Bob Brewin at Sun about the situation about audio and video codecs in Java and FX. He hemmed and hawed and mumbled something about how Ogg Vorbis wasn't really going to work out. The good news is that Sun now licensed the same codecs that are used in Flash, and there will be decent multimedia support going forward. It is just extremely annoying that codecs are so patent-encumbered, and it is yet more evidence that patents hinder, and not promote, the progress of science and the useful arts.</p><p>At the press cocktail hour, James Gosling was kind enough to give me some inside dope on JFX development. One of my graduate students, Sadiya Hameed, is working on reimplementing Java FX Script as a DSL. Whenever she showed me some code that she found in the wild, I thought &ldquo;Whoa! That's a lot ofmath.&rdquo; (Which, BTW, one of the keynote speakers said today as well.) As it turns out, a lot of the math is apparently auto-generated when a set ofAdobe Illustrator files is transcoded into Java FX Script. The work flow is that the creative folks work in the tools that they like (and not so much in Java FX Script), and that the programmers work in the tools that they like (maybe Java FX Script for the front end, and definitely Java on the backend). Gosling also said that some of the tools were still pretty rough, which is why the keynote didn't show them off. That all made perfect sense. They should let him give the keynote next year. </p><h2>EJB 3.1</h2><p>I am a definite fan of JPA and EJB3, so I was keen on learning what is new in EJB 3.1. Fortunately, much of it centered on my pet topic, ease of development.</p><ul>  <li>No more boilerplate local interfaces. Session beans can be POJOs.    Hooray.</li>  <li>Packaging complexity bites the dust. No more EJB JAR inside the EAR.    Hooray.</li>  <li>Work in progress:     <ul>      <li>Standardized JNDI lookup </li>      <li>Component testing in lightweight container</li>      <li>Using EJBs in single SE client (lookup, injection)</li>    </ul>  </li></ul><p>It surprises me how many people still don't realize that EJB3 was a game-changer. Last year, it was still ok to complain about EJB bloat. This year, not so much. </p><h2>Defective Java</h2><p>Bill Pugh gave an amusing talk about &ldquo;WTF code&rdquo;. He is the inventor of the nifty <a href="http://findbugs.sourceforge.net/">Findbugs</a>tool and regularly trolls for dysfunctional code (in unsavory places such as <a href="http://thedailywtf.com/Series/CodeSOD.aspx">this one</a>) to add more bug-finding rules. Here are some of the beauties that he presented:</p><ul>  <li><pre>while ((c = (char) in.read()) != -1) { ... } </pre>    <p>A <code>char</code> is a value between 0 and 65535, never -1...</p>  </li>  <li><pre>private final String lock = "LOCK";synchronized (lock) { ... }</pre>    <p>Literal strings are interned, so hopefully two programmers don't have    that bright idea...</p>  </li>  <li><pre>synchronized(getClass()) { myStaticCounter++; }</pre>    <p>Let's hope nobody calls this from a subclass...</p>  </li>  <li><code>DateFormat</code>&nbsp;is not threadsafe...</li>  <li><code>java.sql.Timestamp</code>&nbsp;is not symmetric... <br/>The    audience's collective eyes glazed over at this point. An informal poll    revealed that a large fraction was blissfully unaware of the    <code>instanceof</code> vs. <code>getClass()</code> controversy in the    <code>equals</code>&nbsp;method. This seems to be a lost cause. Maybe    anyone who overrides <code>equals</code> in a non-final class needs to    supply an annotation <code>@IKnowWhatIAmDoing</code>. </li></ul><h2>Java Language Evolution</h2><p>An interesting presentation about what to expect in Java 7 and beyond. </p><p>Rules:</p><ol>  <li>Respect the past. No new global keywords (like <code>enum</code>,    <code>assert</code>). &ldquo;Restricted&rdquo; keywords are ok    (<code>module</code>, and hopefully, <code>property</code> :-))</li>  <li>Respect the future. Leave room for syntax to breathe. Counter-example:    Maybe we'd like to have named parameters for ordinary methods in the    future. When annotations with named parameters were introduced    (<code>@Foo(name = "fred")</code>), the choice of <code>=</code> was a    mistake, because you can't do <code>foo(name = "fred")</code> for    ordinary methods. Had the Java 5 designers respected the future, they    would have chosen something like <code>@Foo(name : "fred")</code>. Or    not...wouldn't that conflict with BGGA control invocation? </li>  <li>Respect the model. Java is a general purpose OO language. </li></ol><p>Principles:</p><ol>  <li>High-level. (Express the idea, not the bits)</li>  <li>Covet clarity</li>  <li>Static typing</li>  <li>Loose coupling between language and API</li></ol><p>Likely to be in Java SE 7:</p><ul>  <li><pre>// Multi-catch
try { .... } catch(X1, X2 e) { ... }</pre>  </li>  <li>Modules</li>  <li>Annotations in more places </li></ul><p>Definitely won't be in Java ever:</p><ul>  <li>Operator overloading</li></ul>
<p><span style="float: right; margin-left: 1em;"></span><img alt=""
src="http://weblogs.java.net/blog/cayhorstmann/archive/boilerplate.jpg"
style="float: right; size: 50%; margin-left: 1em;" />I want the multi-catch.
Modules and better annotations are noble but dull. Did I ever mention that I
want native properties? That I am sick of the <a
href="http://weblogs.java.net/blog/cayhorstmann/archive/2006/06/say_no_to_prope.html">boilerplate</a>?
I asked James Gosling. He said that there is a long stack of proposals on
what to do with properties. And they all run against a
brick wall when they try to deal with bound properties. (I know...one of my students, Nikolay Botev,
compiled a long list of them, and another, Alexandre Alves, implemented a
<code>javac</code> extension to implement one.)  I agree...bound
properties are a lost cause. Let's just admit that and move on, with simple
properties and a &ldquo;restricted&rdquo; <code>property</code> keyword!</p>

<p>Too bad I didn't have a chance to ask about that in the BOF. I had been a
reviewer for the tools and languages track, and Sharat Chander, the track
chair, took out all of the reviewers for a great dinner. Potentially little known
facts: (1) Competition for slots at Java One is intense. We had over 300
proposals for maybe 20 slots. (2) Most of the reviewers&mdash;at least in our
track&mdash;are not from Sun. </p>]]>

</content>
</entry>
<entry>
<title>Java One Day 0</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/05/java_one_day_0_1.html" />
<modified>2008-05-06T06:22:31Z</modified>
<issued>2008-05-06T06:18:57Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9697</id>
<created>2008-05-06T06:18:57Z</created>
<summary type="text/plain">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. My mind wandered during the keynote speech, but I was enchanted by the enigmatically named EclipseLink and robots that had cockroach reflexes and were programmed in GreenFoot.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p>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. </p>

<p>Ian Murdoch (the ian in <a href="http://debian.org">Debian</a>) gave the
keynote speech. My mind wanders in keynotes, and here were some of its
destinations. <img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/poster_napoleon_.gif" width="291" height="185"
style="float: right; margin-left: 1em;" /></p>
<ul>
  <li>His boss, <a href="http://blogs.sun.com/jonathan/">Jonathan
    Schwartz</a>, likens open source to the thousand tributaries giving rise
    to the mighty <a
    href="http://en.wikipedia.org/wiki/Amazon_River">Amazon</a> river (not
    the <a href="http://amazon.com">shopkeeper</a>, although that too might
    be a valid analogy)&mdash;the reverse of <a
    href="http://www.edwardtufte.com/tufte/graphics/poster_OrigMinard.gif">this
    image.</a></li>
  <li>Maybe the MySQL acquisition makes more sense than I thought. As a
    card-carrying member of the chablis and brie set, I had always preferred
    PostgreSQL, but MySQL is a blue-collar database, just like Java is a <a
    href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/05/on_bluecollar_l.html">blue-collar
    language</a>.</li>
  <li>Core + edge. There is an open-source core (Java, OpenSolaris, etc.),
    and vendors add value at the edge. I thought of <a
    href="http://www.informit.com/articles/article.aspx?p=1193856&amp;rll=1">Donald
    Knuth</a> and TeX, and how he insisted (wisely, I think) that it be the
    immutable core, whatever its flaws. Maybe that's what will happen with
    Java, and innovation will come at the edges, with new languages and
    technologies. </li>
  <li>This doesn't work so well with a closed-source core. Amen. At my
    university, we use the wretched <a
    href="http://blackboard.com">Blackboard</a> software that is sold to
    CIOs, not users. Over the weekend, I googled to find out how to import
    quiz questions to Blackboard. I got a zillion hits on how to do this for
    <a href="http://moodle.org">Moodle</a>, an open-source alternative, in a
    variety of formats. With Blackboard, there is a solitary third party
    product for the job that uses Windows. Too bad I don't.</li>
  <li>One problem with the <a href="http://laptop.org/">OLPC</a> is that the
    coders aren't it's users. Amen. <img alt=""
    src="http://weblogs.java.net/blog/cayhorstmann/archive/olpc.jpeg" /><span
    style="float: right; margin-left: 1em;"></span></li>
  <li>Open source lets you be brilliant faster. Amen.</li>
</ul>

<p>Charles Nutter gave an interesting overview of languages that run on the
JVM. There were the usual suspects: Groovy, Jython, JRuby, Rhino, Scala, and
some more exotic ones. (Note to self: Check out <a
href="http://clojure.sourceforge.net/">Clojure</a> and see if it makes <a
href="http://en.wikipedia.org/wiki/Software_transactional_memory">software
transactional memory</a> easier to understand.) Charles' advice: The era of
doing everything in a single language is over. Be a polyglot.</p>

<p>Sadly, the Netbeans talks were far from riveting. Instead, I walked off to
the exhibit area and had a chat with <a
href="http://blogs.sun.com/winston/">Winston Prakash</a> and a very friendly
fellow from the Prague office about the JSF visual designer. The Netbeans 6.1
editor isn't bad, provided you don't use absolute positioning and ignore the
useless backing bean that it insists on generating. But it could be so much
better. An improved visual editor is being planned, but apparently <a
href="https://jsf-metadata-spec-public.dev.java.net/">JSR 276</a> is going
nowhere. That's too bad. Wouldn't it be nice if you could use your favorite
JSF library (<a href="http://www.icefaces.org">ICEfaces</a>, <a
href="http://www.jboss.org/jbossrichfaces/">RichFaces</a>, <a
href="http://www.oracle.com/technology/products/adf/adffaces/index.html">ADF
Faces</a>/<a
href="http://myfaces.apache.org/trinidad/index.html">Trinidad</a>, <a
href="https://woodstock.dev.java.net/">Woodstock</a>) in your favorite IDE,
with visual builder support? It has taken far longer than I expected for
these components to appear, but now that they are there, I want to drag and
drop them, and not be stuck with the drab standard components. (Check out <a
href="http://ashlesha-woodstock.blogspot.com/">this blog</a> by my graduate
student Ashlesha Patil...)</p>

<p>There was a very nice presentation on <a
href="http://www.eclipse.org/eclipselink/">EclipseLink</a>. It looks like a
great JPA provider, blazing the trail to JPA 2.0 and offering amazing
configurability. But it surely takes the prize for the most confusingly named
product of the day. Recall that Toplink WateredDown, erm, Essentials, is the
JPA provider in GlassFish. The original Toplink is now open-sourced with the
Eclipse foundation, hence the name. Where can you find it? In Glassfish 3,
which you can install into NetBeans (!). The Eclipse IDE has not yet caught
up. </p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/TrackBotBasic300x200.jpg" width="300" height="203"
style="float: right; margin-left: 1em;" /></p>

<p>My favorite event was a fun presentation about using robots in computer
science education. These aren't your usual Lego robots. They have several
processors on board for &ldquo;cockroach reflexes&rdquo;, and they can be
equipped with a Java-powered <a
href="http://www.sunspotworld.com/">SunSpot</a> for its brains. The
presenters demoed a nifty development environment based on <a
href="http://www.greenfoot.org/">Greenfoot</a>. You can prototype your robot
in the safety of your laptop, and then download the program into the SunSpot
to control the actual hardware. There is a <a
href="https://robohaccontest.dev.java.net/">maze-solving contest</a> going on
at Java One. If you have any brain cycles left for coding at Java One, give
it a try!</p>]]>

</content>
</entry>
<entry>
<title>On Blue-Collar Languages</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/05/on_bluecollar_l.html" />
<modified>2008-05-05T05:16:58Z</modified>
<issued>2008-05-05T05:16:37Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9685</id>
<created>2008-05-05T05:16:37Z</created>
<summary type="text/plain">A recent column on Java generics drew a collection of decidedly blue-collar comments, which made me think how hard it is to design a blue-collar language. </summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p>I ran across <a
href="http://blogs.sun.com/CoreJavaTechTips/entry/using_generics_with_wildcards_and">this
tech tip</a> on using wildcards in Java generics. Pretty basic stuff, I
thought. But I was amazed by the comments:</p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/blue-collar.jpeg" width="119" height="127"
style="float: right; margin-left: 2em;" /></p>
<ul>
  <li>Great post!! never knew about wildcards</li>
  <li>I cant believe this. I cannot think how a wild card in generics fits
    into the java OOP theme. Upto now <strong>the rules were always simple
    and straight forward</strong>. In this case list object should have
    accepted all objects of sub classes by default. I feel generics in Java
    has made things complicated and confusing for the programmer.</li>
  <li>If you find yourself writing way too many ? extends constructs and
    think you shouldn't need to, you probably should re-think whether you
    actually want an abstract class or whether an interface would do the job
    for you. [Huh?]</li>
</ul>

<p>For the first time, I really understood what it means to be a blue-collar
language. In a blue-collar language, the rules are always simple and
straightforward. If something doesn't work, there is a clear error message,
either at compile-time or at run-time. Overall, Java did a great job with
that. Consider covariance of arrays. </p>

<p>Joe Bluecollar can convert a <code>Employee[]</code> array to an
<code>Object[]</code> array, and he never even worries whether that is safe.
If he then stores a <code>Watermelon</code> instance in the array, he gets an
<code>ArrayStoreException</code>. But that's not very common, and when it
does happen, Joe can see what the problem is. </p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/rocket-scientist.jpeg" width="107" height="140"
style="float: right; margin-left: 2em;" /></p>

<p>Java generics? Not so simple. Check out <a
href="http://gridgain.blogspot.com/2008/04/java-executor-service-rocket-scientists.html">this
blog</a>. Even a concurrency rocket scientist can be baffled by generics.</p>
<ul>
  <li>Why in the world do I need to specify <code>&lt;? extends
    SomeInterface&gt;</code> for generics? What else am I going to do with an
    interface other than <strong>*extend*</strong> it. Well... I guess I can
    stare at it, but I don't think it counts.</li>
</ul>

<p>I am teaching a <a
href="http://www.sjsu.edu/faculty_and_staff/course_detail.jsp?id=3996">graduate
course in programming languages</a> at San Jose State. One of the topics is
generics in Java and Scala. I thought my students would enjoy a topic of
current interest, but they are not happy. Variance and wildcards seem to
belong to that category of mind-benders that most people find impossibly
challenging, similar to the <a
href="http://www.cs.nuim.ie/~jpower/Courses/parsing/node18.html">pumping
lemma</a> or 2D array types in C. </p>

<p>(When teaching C, I used to patiently explain, with many examples, why the
type of an array declared as <code>int a[3][4]</code> is <code>int
(*)[4]</code> and not <code>int**</code>, but I was rarely successful. )</p>

<p>What is it about these topics that makes otherwise perfectly capable
programmers stop thinking and start guessing randomly? Maybe we all use
intuition more often, and formal reasoning less often, than we think? A
language that wants to capture the hearts and minds of the blue-collar
programmer needs to work very hard to have rules that are always simple and
straightforward. In Java, arrays are simple and straightforward. Wildcards
are not. I now appreciate how challenging it is to develop a blue-collar
language, and how much thought must have gone into the design of Java. </p>

<p>I don't mean to say that everything in the language has to be easy as
pie&mdash;we all know easy languages that lack power and expressiveness. But
the rocket science stuff ought not to be in everyone's face. In Java, the
rocket scientists can use annotations, reflection, and byte code engineering,
to deliver constructs that the blue-collar programmer finds intuitive to use.
The problem with Java generics is that they are too weak. For example, it is
not possible to implement a covariant array with an array store exception
(because of erasure). Instead, the wildcards leak out and give the
blue-collar programmer a headache.</p>

<p>What does that mean for closures? How leak-proof is the rocket science
stuff? With <a href="http://javac.info/">BGGA</a>, for the most part, I think
it is pretty good, particularly when it comes to control invocations. Of
course, you'd never know from looking at all the blogs that show complex
syntax for writing closures. Well, using reflection, dynamic proxies, and
annotation processors is no picnic either. What counts is whether the
resulting artifacts are &ldquo;always simple and straightforward&rdquo;.</p>]]>

</content>
</entry>
<entry>
<title>Is Computer Science the New Latin?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/04/is_computer_sci.html" />
<modified>2008-04-05T18:02:28Z</modified>
<issued>2008-04-05T18:02:15Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9480</id>
<created>2008-04-05T18:02:15Z</created>
<summary type="text/plain">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. This blog tells you what that all means and why it is deplorable.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>Programming</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/livius.jpeg" width="106" height="141"
style="float: left; margin-right: 1em; " />This <a
href="http://www.washingtonpost.com/wp-dyn/content/article/2008/04/03/AR2008040303925.html">Washington
Post article</a> 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 <a href="http://www.collegeboard.com">College
Board</a> 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.) </p>

<p>Has computer science become as unpopular as Latin for American teenagers?
That would have serious consequences for our industry. As it happens, I just
finished serving on the Development Committee for the AP Computer Science
courses, so I have a little more inside information.</p>

<p>The number of computer science majors has dropped substantially after the
dot-com bust (see the graph below). At the same time, U.S. employment in the
IT sector is solidly up, outsourcing nonwithstanding, and there is widespread
concern about a looming skills shortage. </p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/cs-enrollment.jpg" width="540" height="424" /></p>

<p>Why don't students major in CS? Nobody knows for sure. The Dilbert image
of working long hours in cubicles, only to have your job outsourced, surely
doesn't help. We do know that most students have made up their mind by the
time they reach college, so the way to their hearts and minds is in secondary
school.</p>

<p>That's where the AP program comes in. In the past, there were two courses,
AP CS A and AB. The A course covers college-level CS1, the AB course covers
college-level CS1+CS2. </p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/mit-robot.png"
style="float: left; margin-right: 1em; " />That, of course, begs the question
what college-level CS1 and CS2 are. In most universities, CS1 is an
introduction to programming, and CS2 covers data structures (linked lists,
trees, hash tables, etc.) While CS2 is fairly standardized, there is quite a
variety of approaches for CS1. The most popular programming language is Java,
followed by C++, but there are enthusiastic proponents of Scheme, Python, C,
assembly, and just about any language other than Intercal. Some CS1 courses
are &#x201c;breadth first&#x201d;, covering a bit of networking, databases,
software engineering, and theory rather than diving deeply into programming.
MIT starts out with robotics, mixing hardware, software, and systems design.
That sounds like a lot of fun but it is so expensive and labor-intensive that
it is unlikely to become mainstream. </p>

<p>AP CS must have a single curriculum, so they go with the
middle-of-the-road approach: Programming and data structures in Java. That
doesn't make them popular with the (intrepid experimenters|lunatic
fringe)&#x2014;see <a
href="http://www.nytimes.com/2007/04/17/science/17comp.html">this
article</a>. Some of that criticism is below the belt. You can't judge the
quality of a course by the weakest question on the final exam. But not all is
well with AP CS. There needs to be more room for excitement and fun, not just
teaching to the test. </p>

<p>Enrollments in the course have declined somewhat less than at the college
level. Here are recent numbers of test-takers, courtesy of Dave Reed, the
Chief Reader who administers the CS exams: </p>
<pre>YEAR      A      AB
---------------------
1998    6,478   4,057
1999    12,218  6,619
2000    13,646  6,876
2001    15,827  7,595
2002    15,660  7,799
2003    14,674  7,071
2004    14,337  6,077
2005    13,924  5,097
2006    14,662  4,939
2007    15,049  5,064</pre>

<p>Compared to other AP subjects, the CS numbers are not very impressive. In
2007, Physics had over 60,000 test-takers, and US history over 250,000. Latin
had about 5,000. </p>

<p>The College Board decided to cut their losses. Without bothering to ask
any CS people, they eliminated the AB exam, leaving AP CS as a one-semester
course. (As the VP in charge, Trevor Packer, emailed me: &#x201c;We do not
see this as a decision dependent upon disciplinary input.&#x201d;) This is
rather unfortunate since the kids taking AB are the ones most motivated to go
into computer science.</p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/Salamander.jpg" width="200" height="143"
style="float: left; margin-right: 1em; " />There is some talk by the College
Board administrators about growing CS A back into a two-semester sequence,
but that is pretty dubious. Who would heal themselves by first cutting off
their healthy limbs and then waiting for them to regrow? (Trivia fact of the
day: According to the April 2008 Scientific American, Salamanders are unique
in their ability to regrow severed limbs.)</p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/alice.png" style="float: right; margin-left: 1em; " />As
you can see, CS in American high schools is in bad shape. That is a problem
for all of us in the computing industry. What can you do? If you have kids in
school, make your voice heard with the school board. Volunteer in the CS
club. (They don't have one? Start one. I fondly remember my high school days
in the <a href="http://ptag-eutin.de/">physics and technology club</a>, the
refuge of the nerds. We were a proud group of nerds, and many of us ended up
with a Ph.D.) Get your company to send speakers, volunteers, and equipment.
Get kids into your company so they (hopefully) see that it's not Dilbert
land. And remember, what got you into CS may not be what excites them, so be
on the lookout for new approaches such as <a
href="http://www.alice.org/">this</a> or <a
href="http://worldwind.arc.nasa.gov/">this</a> or <a
href="http://greenfoot.org/">this</a>. </p>]]>

</content>
</entry>
<entry>
<title>Feel of Java Revisited</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/03/feel_of_java_re.html" />
<modified>2008-03-02T05:22:15Z</modified>
<issued>2008-03-02T02:20:11Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9298</id>
<created>2008-03-02T02:20:11Z</created>
<summary type="text/plain">On February 28, James Gosling gave a presentation in Sun&apos;s Santa Clara Campus auditorium (formerly a part of the Agnews Insane Asylum :-)), entitled “Feel of Java Revisited”. The talk promised to revisit the classic Feel of Java paper that famously declared “Java is a blue collar language”. I went with my graduate programming language class from SJSU, and here is what I learned.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>Community: Java User Groups</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<body>
<p><img alt=""
src="http://www.nps.gov/history/nr/travel/santaclara/buildings/agn2.jpg"
style="margin-right: 2em; float: left;" /> On February 28, James Gosling gave
a presentation in Sun's Santa Clara Campus auditorium (formerly a part of the
<a href="http://www.nps.gov/history/nr/travel/santaclara/agn.htm">Agnews
Insane Asylum</a> :-)), entitled &ldquo;Feel of Java Revisited&rdquo;. The
talk promised to revisit the classic <a
href="http://doi.ieeecomputersociety.org/10.1109/2.587548">Feel of Java</a>
paper that famously declared &ldquo;Java is a blue collar language&rdquo;.
(SJSU students: Go <a
href="http://www.sjlibrary.org/research/databases/sguide_subjectList.htm?subID=18&amp;catID=1&amp;getType=2">here</a>
for free access to the paper.)</p>

<p>I teach a graduate class in programming languages at San Jose State University. Instead of covering
denotational semantics or logic programming, I decided to cover what is hot
in <a href="http://dzone.com">dzone</a> (closures, metaobject protocols,
etc.) and smuggle in the theory under the radar. My class has been learning
about the various closure proposals for Java, and we played with the <a
href="http://www.javac.info/">BGGA</a> and <a
href="http://slm888.com/javac/">CICE</a> implementations in the labs. (If you
want to play along, go <a
href="http://www.sjsu.edu/faculty_and_staff/course_detail.jsp?id=3996">here</a>
for a guest login. Sorry, no <a
href="http://www.jroller.com/scolebourne/entry/fcm_prototype_available">FCM</a>
yet. The implementation came after I designed the lab.)</p>

<p><img alt=""
src="https://java-champions.dev.java.net/images/Duke-Champion.jpg"
style="margin-left: 2em; float: right;" /></p>

<p>Aaron Houston, the tireless champion of the <a
href="https://java-champions.dev.java.net/">Java Champions</a>, got my class
tickets for the event, with reserved seating, free T-shirts <em>and</em> a
Sun Spot kit for the CS club. Thanks Aaron!!! We all had an amazing time. </p>

<p clear="left"><img alt=""
src="http://weblogs.java.net/blog/cayhorstmann/feel-of-java-1.png" /></p>

<p>Much to my disappointment, the presentation did not engage in mudslinging
about competing closures proposals :-) Instead, James revisited his personal
journey to Java. It was very interesting to see how his experience with prior
scripting languages and compiler projects shaped his thinking. When Java was
created, the &ldquo;blue collar&rdquo; language was C. Used by Real
Programmers who were manly enough to spend weeks tracking down obscure memory
corruption errors. Garbage collectors were used by <a
href="http://www.pbm.com/~lindahl/real.programmers.html">quiche eaters</a>.
James explained his goal of combining a familiar syntax with the features
that are required for security and reliability. He also recounted his many
years of experience with virtual machines, from industrial and academic
projects. It became apparent how Java&mdash;the happy marriage of blue collar
and quiche eater programming&mdash;was no accident but the result of a
careful design process.</p>

<p>Of course, closures came up in the Q&amp;A. James said that he personally
loves closures and would like to use them in Java if and when they become a
part of it. (There had been some speculation in the blogoshpere whether
closures fail the &ldquo;blue collar test&rdquo;, which James refuted in <a
href="http://blogs.sun.com/jag/entry/closures">this blog</a>.) I asked about
the decision process that governs the evolution of the Java language. In
response, James grumbled a bit about issues with the JCP process. James made
it clear that he considers generics a great win, despite some of the ugly
corner cases. Kirk Pepperdine asked about Java FX and whether it was
competitive with Flex and Silverlight. James gamely said that it will be an
interesting battle. There was some discussion about the successor of Java,
and James said that the JVM is more important than Java itself.</p>

<p>This all left me thinking about closures and blue collar programmers. 15
years ago, only the super-rich had a <a
href="http://www.plasmatvscience.org/plasmatv-history1.html">plasma TV</a>,
and only eggheads used a garbage collector. Now, flat screen TVs are
everywhere, and I can't think of a recent programming language that doesn't
have garbage collection. Time marches on, and what was once a luxury becomes
commonplace in blue collar households.</p>

<p>Consider this example from my homework assignment. Instead of <a
href="http://horstmann.com/sjsu/cs252/SwingWorkerTest.java">this mess of code</a>,
use BGGA closures to put work on a background thread or the event dispatch
thread like this.</p>
<pre>            Scanner in = new Scanner(new FileInputStream(file));
            onBackgroundThread()
            {
               int lineNumber = 0;
               while (in.hasNextLine())
               {
                  String line = in.nextLine();
                  lineNumber++;
                  onEDT()
                  {
                     statusLine.setText("" + lineNumber);
                     textArea.append(line);
                     textArea.append("\n");
                  }
               }
               onEDT()
               {
                  openButton.setEnabled(true);
               }
            }</pre>

<p>Note how much clearer the code has become. Put time-consuming work on the
background thread, and put the UI update on the EDT. Java FX needs special
keywords for this. With closures, you just define a couple of utility
functions. It is so easy that one of my students wrote: </p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>It doesn't get more blue collar than that :-)</p>
]]>

</content>
</entry>
<entry>
<title>Swing for the Web--Are We Getting Closer?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/01/swing_for_the_w.html" />
<modified>2008-01-22T06:10:49Z</modified>
<issued>2008-01-22T06:10:37Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.9032</id>
<created>2008-01-22T06:10:37Z</created>
<summary type="text/plain">When I first heard about JavaServer Faces, way back at the 2002 Java One conference, it was sold as “Swing for the Web”. Many years later, the reality is far from perfect, but are we getting closer? I report how NetBeans, GlassFish, JSF, and JPA worked for me in a recent -h-a-c-k-, erm, agile development project.  </summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>Community: Java Tools</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p><img alt="swinging twins"
src="http://www.horstmann.com/twins/mountain-lake-swings.jpg"
style="margin-right: 1em; width: 20%; float: left;" />When I first heard
about JavaServer Faces, way back at the 2002 Java One conference, it was sold
as &ldquo;Swing for the Web&rdquo;. That caught my attention. I was sick of
&ldquo;assembly programming for the Web&rdquo; with HTML, JavaScript, HTTP,
cookies, servlets, and that special form of torture&mdash;JSP custom actions.
Ever since, I have pinned my hopes on JSF because it has one thing going for
it: a <em>component model</em>. 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
<code>JProgressBar</code> in Swing, I don't worry about the pixels and
animations either. </p>

<p>In that regard, the first release of JSF was a cruel disappointment. The
standard JSF components are very primitive. The most sophisticated one is the
data table, and it pales in comparison with a Swing <code>JTable</code>. No
progress bars, trees, menus, popups, or any of the other building blocks that
you want for a snazzy application. I don't want &ldquo;FORTRAN for the
Web&rdquo;. </p>

<p>In the last couple of weeks, I had to hack together a simple system to
support classroom discussions. The instructor puts up a question, students
give anonymous answers, and then the class looks at the collective wisdom and
has a (learning insight|good chuckle). Many instructors use
&ldquo;clickers&rdquo; for this purpose&mdash;special hardware devices with
voting buttons. But I wanted students to send text and images, not just
multiple-choice answers. (Also, they all already have a laptop, but they'd
have to buy the clicker.)</p>

<p><img alt="elephant"
src="http://today.java.net/images/tiles/111-elephant.gif"
style="margin-right: 1em; float: left;" />At first, I thought, oh no, don't
make me <a href="http://today.java.net/pub/a/today/2004/06/15/ejb3.html">eat
the elephant again</a>, and I longingly looked at <a
href="http://www.rubyonrails.org/">Rails</a>, <a
href="http://grails.codehaus.org/">Grails</a>, or <a
href="http://liftweb.net/index.php/Main_Page">Lift</a> for my salvation. But
then I googled for "Rails progress bar", and the results were depressing. I
noted that NetBeans 6 has a perfectly good progress bar in the <a
href="https://woodstock.dev.java.net">Woodstock</a> component set, so I
decided to go with JSF once again. This time, Swing for the Web seemed within
reach. Here is what worked and what didn't.</p>
<ol style="clear: left;">
  <li><img alt="up" src="http://weblogs.java.net/blog/cayhorstmann/archive/up.gif" width="14" height="14" /> The Woodstock
    components look pretty nice&mdash;much nicer than anything that I could
    put together with my limited CSS skills. For example, the alert component
    has some shading, some graphics, all that stuff that I am too busy to
    work on. Exactly what you want from a component set.</li>
  <li><img alt="up" src="http://weblogs.java.net/blog/cayhorstmann/archive/up.gif" width="14" height="14" /> The progress bar
    worked great. I didn't have to know anything about AJAX. That's good
    because I really don't want to know any more about AJAX than about <a
    href="http://asn1.elibel.tm.fr/">ASN.1</a>. For an application
    programmer, this should just be plumbing.</li>
  <li><img alt="down" src="http://weblogs.java.net/blog/cayhorstmann/archive/down.gif" width="14" height="14" /> The <a
    href="https://woodstock.dev.java.net/Documentation.htm">documentation</a>
    for the Woodstock components is totally wretched. </li>
  <li><img alt="left" src="http://weblogs.java.net/blog/cayhorstmann/archive/left.gif" width="14" height="14" /> The NetBeans
    form designer is adequate for dragging together a basic UI, but it
    insists on the &ldquo;Creator&rdquo; model where each JSF page has a
    backing bean with bindings for each component. That may make sense for
    ASP.NET programmers, but I hated it. Apparently, this will go away in
    Netbeans 6.1. I used the form designer for the initial layout, then
    converted everything to plain JSF. I also had <a
    href="http://www.nabble.com/visual-web-JSF-page--jsp-and-design-out-of-sync-td14750202.html">other
    issues</a> that hopefully will get addressed in a future version of the
    UI builder.</li>
  <li><img alt="down" src="http://weblogs.java.net/blog/cayhorstmann/archive/down.gif" width="14" height="14" /> Achieving a
    common page layout, with a title bar on top and a menu on the left, is
    still way too hard. I want the framework and tools to guide me, not fuss
    with page fragments. </li>
  <li><img alt="up" src="http://weblogs.java.net/blog/cayhorstmann/archive/up.gif" width="14" height="14" /> I used the XML JSP
    syntax and XHTML for the pages, and NetBeans caught all my silly
    formatting errors&mdash;a big help. (Why don't I follow that good advice
    in Core JSF? I tried, but my co-author and the reviewers all felt
    nostalgically attached to ye olde syntaxe.)</li>
  <li><img alt="up" src="http://weblogs.java.net/blog/cayhorstmann/archive/up.gif" width="14" height="14" /> NetBeans is pretty
    good about keeping the various configuration files in sync, and I didn't
    have to fuss much with <code>faces-config.xml</code>.</li>
  <li><img alt="left" src="http://weblogs.java.net/blog/cayhorstmann/archive/left.gif" width="14" height="14" /> If I had used
    <a href="http://www.jboss.com/products/seam">Seam</a>, I could have
    ignored <code>faces-config.xml</code> altogether, but I ran into some <a
    href="http://forums.java.net/jive/thread.jspa?messageID=253975&amp;#253975">GlassFish
    problems</a>. Once <a
    href="http://jcp.org/en/jsr/detail?id=299">WebBeans</a> is integrated
    into NetBeans/GlassFish, I will definitely go that route.</li>
  <li><img alt="up" src="http://weblogs.java.net/blog/cayhorstmann/archive/up.gif" width="14" height="14" /> JPA was a winner.
    Having the ORM and caching for free is nice, and JPQL is far less tedious
    than SQL. I spent essentially no brain cycles on persistence. Mostly,
    that was because my app is so simple that I never felt the need to export
    any entities outside the managed environment. Again, Seam/WebBeans would
    make this even nicer. </li>
  <li><img alt="down" src="http://weblogs.java.net/blog/cayhorstmann/archive/down.gif" width="14" height="14" /> I still got
    the <a
    href="http://weblogs.java.net/blog/cayhorstmann/archive/2006/09/the_power_and_p.html">Stack
    Trace From Hell</a> far more times than I wanted to. NetBeans did a
    fairly creditable effort in trying to scrape what little useful file
    name/line number data it could find. This still needs lots more work. For
    example, errors in session beans are silently swallowed.</li>
  <li><img alt="up" src="http://weblogs.java.net/blog/cayhorstmann/archive/up.gif" width="14" height="14" /> The NetBeans
    debugger saved my bacon many times. It is very savvy about tracing from a
    JSF bean to a session bean, bypassing the intermediate layers. </li>
  <li><img alt="down" src="http://weblogs.java.net/blog/cayhorstmann/archive/down.gif" width="14" height="14" /> I tried my
    best to use hot deployment, and even hot-switched code whenever possible.
    But every time that I edited a JSF page or even a CSS file, I had to
    redeploy, redeploy, redeploy, and each time, I stared at the console for
    what seemed like an eternity. I hated that. My Rails friends tell me that
    they can keep tinkering with their code without ever redeploying. </li>
</ol>

<p>Overall, I felt that I still had to focus far too much on the care and
feeding of the app server. GlassFish programmers&mdash;remember that the app
server is not just a tool to run perfectly working applications, it is also a
part of the development environment!!! We need good error messages and
red-hot deployment to be productive. </p>

<p>Swing for the Web is getting closer. Woodstock, <a
href="http://labs.jboss.com/jbossrichfaces/">RichFaces</a>, <a
href="http://myfaces.apache.org/trinidad/">Trinidad</a>, all show promise.
But do we really want all of them? After all, there is just one Swing. And if
we must have them all, they should all play nice in a web GUI builder. <a
href="http://jcp.org/en/jsr/detail?id=276">JSR 276</a> should get us
there&mdash;that started in June 2005. How time flies!</p>

<p>Apart from the UI components, we need more architectural guidance for
mediating between the UI and persistence layer. I think JPA with
Seam/WebBeans is our best bet, and NetBeans should support it ASAP.</p>

<p>All these issues are solvable, and I am hopeful they will be solved. I did
enjoy having the Java API for all those other things I needed to do (such as
crypto, zip file management, image manipulation, and so on). In the end, I
was able to hack together a somewhat nontrivial application using NetBeans,
GlassFish, JSF, and JPA, in a couple of weeks, while at the same time
contending with sick infant twins and a broken clothes dryer. Not bad...but
it could have been one week without the Stack Trace From Hell and redeploy,
redeploy, redeploy. </p>]]>

</content>
</entry>
<entry>
<title>Dinosaurs Can Take the Pain</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2008/01/dinosaurs_can_t_1.html" />
<modified>2008-01-08T17:33:08Z</modified>
<issued>2008-01-08T17:32:12Z</issued>
<id>tag:weblogs.java.net,2008:/blog/cayhorstmann/334.8947</id>
<created>2008-01-08T17:32:12Z</created>
<summary type="text/plain">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.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/dinosaurs.jpg" style="margin-left: 1em; float: right;"
width="110" height="111" />There has been much discussion on whether Java
programmers are becoming dinosaurs, on an <a
href="http://www.artima.com/weblogs/viewpost.jsp?thread=221903">evolutionary
dead end</a> 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.</p>

<h2>Pain vs. Discomfort</h2>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/pain.jpg" style="margin-right: 1em; float: left;"
width="98" height="122" />Let us go back in time, to 1995, when Java first
appeared. We were programming in C++, Visual Basic, and &ldquo;fourth
generation&rdquo; languages such as FoxPro. Since I was a C++ programmer, I
remember exactly what my pain points were:</p>
<ul>
  <li>Memory management</li>
  <li>Access to database and GUI features</li>
</ul>

<p>Memory management was intensely painful. One bad pointer could wreck your
entire program in mysterious ways and condemn you to many days in debugging
hell. Writing a GUI that accessed a database in C++ was (and is) like eating
soup with a fork. </p>

<p>When Java came along, I got garbage collection and an API that let me do
stuff. I was sold. </p>

<p>I was (and am) surprised when people tell me how they hated operator
overloading and multiple inheritance in C++. In the grand scheme of things,
these caused me discomfort but not agonizing pain.</p>

<h2>Deckchairs on the Titanic?</h2>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/deckchairs.jpg" style="margin-right: 1em; float: left;"
width="116" height="109" />Now let's look at C++ in 2008. It is still alive
and kicking. There is an effort to make sweeping changes in the language and
library: templates on steroids, &ldquo;smart&rdquo; pointers, multithreading
support, even optional garbage collection. The folks who work on that stuff
eagerly discuss the merits of the various proposals while the rest of the
world looks on with wonder. Even if all these efforts come to fruition, can
you imagine banging out a web application in C++? C++ has become a niche
language, but I talk to many C++ programmers who live in total denial about
that fact. </p>

<p>How about Java? Are we living in denial? Are our discussions about
closures simply arguments on how to rearrange the deck chairs on the Titanic?
What about the point of view that Java should be &ldquo;stabilized&rdquo;?
Does that mean &ldquo;fossilized&rdquo;? </p>

<p>I think that there has been way too much discussion whether this or that
proposed language feature is elegant, ugly, or confusing. Java, its APIs, and
its development environment are tools to produce software. Where there is too
much pain, we should evolve to address the pain, or the rest of the world
will look on with wonder about our silly syntax discussions. </p>

<p>It is futile to hope for stability. There always will be pain since we are
bound to take any technology and push it beyond its limits. </p>

<h2>My Pain in Java</h2>

<p>Here I am, a Java programmer in 2008, and I know perfectly well what I
hate.</p>
<ul>
  <li>Boilerplate, boilerplate, boilerplate</li>
  <li>Web applications</li>
  <li>Concurrency</li>
</ul>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/small-boilerplate.jpg"
style="margin-right: 1em; float: left;" width="114" height="117" />From an
emotional point of view, the boilerplate is what I feel every day. Every time
I write a stupid getter/setter, an event listener with that wretched inner
class syntax, or another long-winded type declaration that the compiler could
perfectly well infer, I cringe. But that isn't enough for me to change
languages. It is discomfort, not pain.</p>

<p>But when I embark on another web application (which is what I should be
doing this morning instead of writing this blog), I groan. I use JSF in the
forlorn hope that someone else has given me <a
href="https://woodstock.dev.java.net/index.html">components that make me not
worry</a> about AJAX and GET vs. POST, all of which have nothing to do with
the problem that I want to solve. But then I read descriptions such as <a
href="http://www.netbeans.org/kb/60/web/pagefragments.html">this</a> or <a
href="http://www.netbeans.org/kb/60/web/web-jpa.html">this</a>, and I
despair. If I have to paste random pieces of code to make things work, I just
know I'll be hosed when things <a
href="http://blog.rainer.eschen.name/2007/04/01/when-theres-bad-smell-in-your-jsf-tag-soup-due-to-facelets/">don't
work</a>. </p>

<p>Come on, folks, When I write a web application, I want to be able to say
"This is the common layout of my pages, give me a standard login screen, I
want a menu here, and fill that table with those database values, but add a
column with buttons..." I can do it in JSF, but it is like eating soup with a
fork.</p>

<p>Why is it that Sun can't give me a decent web framework? Is it a
shortcoming of the Java language? Or crummy API design? Rails uses the
metaobject protocol to good effect in Active Record, but as it turns out,
that isn't my problem. JPA works ok for me. The rest of Rails doesn't attract
me&mdash;I want components, not RHTML files. I think in this case, the Java
language is sufficiently powerful, but we are hobbled by backwards
compatibility with JSP and JSF, both of which are simultaneously complex and
underpowered. Or could a language enhancement such as <a
href="http://www-128.ibm.com/developerworks/java/library/j-cb03216/">continuations</a>
make web programming dramatically easier? If so, why does Rails get all the
buzz and not <a href="http://www.seaside.st/">Seaside</a>? </p>

<p>Finally, concurrency scares me. I am not smart enough to write a
nontrivial concurrent program where I can say with confidence that it won't
ever deadlock and that it won't have any race conditions. Just like I was not
smart enough to write a nontrivial C++ program where I could say with
confidence that it won't ever leak or corrupt memory. So far, I just stick my
head in the sand. But as multicore becomes more prevalent, that won't work.
Do we need a language change or a better API, such as actors in Scala? </p>

<p>I'll suffer through the boilerplate discomfort, but if something doesn't
happen with web applications and concurrency, I'll eventually bail. Dinosaurs
can endure pain, but I can't.</p>

<p>What are your pain points? Can the Java ecosystem change to address them?
</p>]]>

</content>
</entry>
<entry>
<title>The OLPC and Java</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2007/12/the_olpc_and_ja.html" />
<modified>2008-01-06T00:21:09Z</modified>
<issued>2007-12-31T17:28:24Z</issued>
<id>tag:weblogs.java.net,2007:/blog/cayhorstmann/334.8903</id>
<created>2007-12-31T17:28:24Z</created>
<summary type="text/plain">I got myself (and another deserving child somewhere out there) a &quot;One Laptop Per Child&quot; for christmas. Here is my experience with Java on the device, followed by some year-end musings what this all means.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/olpc.jpeg" style="margin-left: 1em;float: right" width="138" height="110"
/>I got an <a
href="http://laptop.org/">OLPC</a> for the holiday season. No, it wasn't for
the Horstmann twins&mdash;after all, it is <em>one</em> laptop <em>per
child</em>, so the child must be myself. I got it through the &ldquo;give
one, get one program&rdquo;. For $400, I got mine and a much more deserving
kid somewhere out there got one as well. (Hurry if you want to get
yours&mdash;the program ends today.) </p>

<p style="clear: right;"><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/Core_Java.gif" style="margin-left: 1em;float: right"
width="88" height="115" />Twelve
years ago, in Chapter 1 of the first edition of Core Java, Gary Cornell and
myself wrote this in the section entitled &ldquo;Common Misperceptions about
Java&rdquo;:</p>

<blockquote>
  <p><em>With Java, I can replace my computer with a $500 &ldquo;Internet
  appliance.&rdquo;</em></p>
</blockquote>

<blockquote>
  <p>Some people are betting big that this is going to happen. We believe it
  is pretty absurd to think that people are going to give up a powerful and
  convenient desktop for a limited machine with no local storage...We can
  envision an Internet appliance as a portable adjunct to a desktop. Provided
  the price is right, wouldn&rsquo;t you rather have an Internet enabled
  telephone with a small screen to read your e-mail or see the news. Because
  the Java kernel is so small, Java is the obvious choice for such a
  telephone or other internet &ldquo;appliance.&rdquo;</p>
</blockquote>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/twins1.gif" style="margin-left: 1em;float: right" width="92" height="123"
/>So, now I have my $200 internet
appliance. It works like a charm. I can browse the web and read my email. The
keyboard is not great, but it is spillproof, which is just the thing when
reading the news while the Horstmann twins are up to no good. Here is what I
love about the OLPC:</p>
<ul>
  <li>The price. It's a steal at $200.</li>
  <li>The form factor. It is small (but not too small) and rugged.</li>
  <li>The screen. It morphs from a standard backlit color screen into a
    grayscale screen that can be read in bright sunlight&mdash;very
  nifty!</li>
  <li>The silence. There is no fan and no whirring hard disk.</li>
  <li>The openness. I don't have an epic power struggle against a
    manufacturer who cares more about &ldquo;digital rights
    limitations&rdquo; than my ability to use the device.</li>
</ul>

<p>But Gary and myself were wrong in one teensy detail. The internet
appliance is not Java-powered. The OLPC uses Linux, and the browser is
Firefox, converted to the kid-friendly &ldquo;Sugar&rdquo; environment.</p>

<p>I am not too thrilled about that part. I'd love to put more software onto
the OLPC, but not if it means doing it in C++ and some goofball X11 window
manager. I am glad that other people don't feel as squeamish about these
things as I do, but it made me think about the role of Java in this new class
of devices. </p>

<p>I really believe that the OLPC, the <a
href="http://eeepc.asus.com/global/">Asus Eee</a>, and the <a
href="http://www.everex.com/products/gpc/gpc.htm">Everex gPC</a>, are the
forerunners of a new category of devices that are truly useful and important.
What would it take for Java to be an essential part of these devices?</p>

<p>First off, these are not crippled ME devices. I ran Java SE apps on the
OLPC (see below for details), and the performance was ok for JEdit and the
Violet UML editor. I didn't try Netbeans :-) </p>

<p>So, why didn't the OLPC folks put Java on the machine? A major reason is
surely that Java was not open source software when the OLPC was designed. </p>

<p>Then there is the issue of SE bloat. Or maybe not. I thought about what
parts of SE one could place into separate extension libraries. There is
RMI/CORBA. And the sound stuff that very few people use because it isn't very
good. What else? Maybe SQL, web services, scripting, NIO? Beyond that, I
don't think one can drop entire packages. Some crypto is needed by platform
security. Some XML is used by logging and preferences. Last Java One, I heard
some people say that they were looking into this issue, and I am curious what
they found. My hunch is that there may be a smallish core for console
applications, but as soon as you let in Swing, you are probably at 2/3 of
rt.jar. </p>

<p>Anyway, there has been this huge effort to make Java play nicely with
Vista's throbbing buttons. Maybe that's yesterday's battle. The OLPC shows
quite starkly what you can do for $200 if you dispense with those throbbing
buttons and instead give people something more useful for a specific
task&mdash;such as browsing the web around the house and in the garden. I
once read that when electric motors were first sold, they were expensive
high-tech equipment. People would buy one motor that could be attached to
various devices. Maybe one day people will chuckle when they hear about the
personal computer era when we bought one computer to run all sorts of
programs on a single device. </p>
<hr />

<p>This appendix contains the gory details&mdash;skip it if you don't have an
OLPC.</p>

<p>To install Java, go to a non-XO machine and visit <a
href="http://java.com/en/download/linux_manual.jsp">http://java.com/en/download/linux_manual.jsp</a></p>

<p>Download "Linux RPM (self-extracting file)". Use <code>scp</code> or a USB
stick to move to the XO. Then ssh into the root account of the XO, and run</p>
<pre>chmod a+x jre-6u3-linux-i586-rpm.bin 
./jre-6u3-linux-i586-rpm.bin </pre>

<p>(The exact name may differ.)</p>

<p>By the way, here is the result of running <code>df</code> before </p>
<pre>mtd0 1048576 346408 702168 34% /</pre>

<p>and after</p>
<pre>mtd0 1048576 428820 619756 41% /</pre>

<p>On another computer, use <code>ssh -X</code> to get a shell on the XO. (If
you use Cygwin, be sure to have X11 installed.) Try running a Web Start
program:</p>
<pre>javaws http://www.horstmann.com/violet/violet.jnlp</pre>

<p>If you get an error message such as</p>
<pre>java.lang.UnsatisfiedLinkError: /usr/java/jre1.6.0_03/lib/i386/libdeploy.so: libstdc++.so.5: cannot open shared object file: No such file or directory</pre>

<p>then run</p>
<pre>yum install compat-libstdc++-33</pre>

<p>You should now be able run Java applications and have them show up on your
other computer. </p>

<p>Unfortunately, on the XO itself, the Matchbox window manager seriously
breaks Java applications. JEdit shows up, but the main window is too small
and the menus and dialogs are at the wrong places. Violet doesn't seem to
work at all. This will presumably get worked on in the future. </p>

<p>I then tried to get the Java Plug-in working in the usual way:</p>
<pre>cd /usr/lib/mozilla/plugins/</pre>
<pre>ln -s /usr/java/jre1.6.0_03/plugin/i386/ns7/libjavaplugin_oji.so</pre>

<p>Unfortunately, the plug-in didn't show up when visiting
<code>about:plugins</code></p>

<p>I got these errors in
<code>/home/olpc/.sugar/default/logs/org.laptop.WebActivity?-1.log</code></p>
<pre>LoadPlugin: failed to initialize shared library libXt.so [libXt.so: cannot open shared object file: No such file or directory]</pre>
<pre>LoadPlugin: failed to initialize shared library libXext.so [libXext.so: cannot open shared object file: No such file or directory]</pre>
<pre>LoadPlugin: failed to initialize shared library /usr/java/jre1.6.0_03/plugin/i386/ns7/libjavaplugin_oji.so [/usr/java/jre1.6.0_03/plugin/i386/ns7/libjavaplugin_oji.so: undefined symbol: _ZTVN10__cxxabiv121__vmi_class_type_infoE]</pre>

<p>I got rid of the first two error messages by making symlinks
<code>/usr/lib/libXt.so</code> -&gt; <code>libXt.so.6</code> and
<code>/usr/lib/libXext.so</code> -&gt; <code>libXext.so.6</code></p>

<p>But the third message persisted. Apparently, I am <a
href="http://www.google.com/search?q=libjavaplugin_oji.so+undefined+symbol+_ZTVN10__cxxabiv121__vmi_class_type_infoE">not
the only one</a>with this problem, but I could not find a solution. (Setting
<code>JAVA_HOME</code> in <code>/etc/profile</code> didn't help.) </p>

<p>Just to make it very clear&mdash;do <em>not</em> buy an OLPC today to run
Java applications. My experiment demonstrates that the machine has sufficient
power to do so, but the software needs work. </p>]]>

</content>
</entry>
<entry>
<title>Properties Get No Respect</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2007/12/properties_get_1.html" />
<modified>2007-12-21T00:02:08Z</modified>
<issued>2007-12-21T00:01:59Z</issued>
<id>tag:weblogs.java.net,2007:/blog/cayhorstmann/334.8875</id>
<created>2007-12-21T00:01:59Z</created>
<summary type="text/plain">Last week, there has been another flurry of discussions about closures in Java and minor language enhancements. Conspicuously absent from this discussion was my pet unappreciated language feature, native properties. Most of the effort about properties has been scattered about in the blogosphere. Nikolay Botev, a CS student at SJSU, did something about that and put together a nifty Wiki, complete with voting buttons. Check it out!</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/no-respect.jpeg" style="float: left; margin-right: 1em;" width="97"
height="130" />There has been another flurry of discussions about <a
href="http://www.jroller.com/scolebourne/entry/closures_comparing_the_core_of">closures
in Java</a> and <a href="http://www.bejug.org/newsletter/05/index.html">minor
language enhancements</a>, together with the usual flurry of &ldquo;<a
href="http://weblogs.java.net/blog/robogeek/archive/2007/12/should_java_sta.html">leave
the language alone</a>&rdquo; lamentations. </p>

<p>Conspicuously absent from this discussion was <a
href="http://weblogs.java.net/blog/cayhorstmann/archive/2006/06/say_no_to_prope.html">my
pet unappreciated language feature</a>, native properties. Properties get no
respect. Every few weeks, <a
href="http://blogs.sun.com/joe/entry/java_properties_and_events">another
blogger comes along</a> and says &ldquo;we need a property syntax&rdquo;,
proposes something, and moves on to greener pastures. </p>
<p>At best, properties are dull. Programmers who work with Swing, JPA, JSF components,  XMLEncoder/Decoder, and other "beanish" technology cringe every time they have another class with a bunch of annoying trivial getters and setters. But it isn't the end of the world. They can cringe and keep on coding. How much gratification is there in making people cringe less? Apparently not enough to put together a proposal that deals with all the pesky details.</p>
<p style="clear: left;" ><img alt="devil" src="http://weblogs.java.net/blog/cayhorstmann/archive/devil.jpg" style="float: left; margin-right: 1em;" width="68"
height="75" />But it gets worse. While worrying about pesky details, the hapless property syntax designer needs to fend off a barrage of attacks from the 
inevitable naysayers (&ldquo;What's the big deal...Eclipse writes the getters
and setters for me&rdquo;) and the OO purists (&ldquo;Properties are the tool
of the devil...they break encapsulation&rdquo;).</p>

<p>As a result, most of the effort about properties has been half-hearted and scattered about
in the blogosphere. There was never enough momentum to arrive at a
consensus. Nikolay Botev, a computer science student at SJSU, has done
something about that. In his independent study project, he collected every
reference about properties he could find, in Java and other languages, and
put all the information into a Wiki. He also added nifty voting buttons to
the Wiki. </p>

<p><img alt="" src="http://weblogs.java.net/blog/cayhorstmann/archive/mall.jpeg" style="float: left; margin-right: 1em;" width="143" height="102"
/>While everyone else is madly milling about at the mall, please take a few
minutes to see check it out: <a
href="http://oslo.cs.sjsu.edu:8080/xwiki/bin/view/JavaProperties/">http://oslo.cs.sjsu.edu:8080/xwiki/bin/view/JavaProperties</a>.
If you are a properties enthusiast (you know who you are), please make an
account and add to the Wiki. </p>

<p>Happy holidays!</p>]]>

</content>
</entry>
<entry>
<title>DSLs--Standalone or Embedded?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2007/12/dslsstandalone_1.html" />
<modified>2007-12-20T05:37:46Z</modified>
<issued>2007-12-20T05:37:38Z</issued>
<id>tag:weblogs.java.net,2007:/blog/cayhorstmann/334.8869</id>
<created>2007-12-20T05:37:38Z</created>
<summary type="text/plain">I have the unenviable job of reviewing several hundred submissions to the Java One &quot;Tools and Languages&quot; track. Today I found this in my inbox: &quot;I&apos;m a reviewer on another track for JavaOne &apos;08, and couldn&apos;t help but notice your rather dismissive review of my proposed technical session.&quot; The topic is DSLs, and I feel rather strongly that a DSL is best embedded in a host language. If you disagree, let me know and I&apos;ll reconsider my review.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>Community: Java Tools</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<p>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. 
</p>
<p>One submitter proposed a talk on "Doing your own language". The outline talked about parsing, abstract syntax trees, and generating code.  I flippantly commented "A DSL is not a DYOL. You use a DSL precisely because you DON'T want to write another parser."</p>
<p>Of course, what I had in mind was the recent trend of embedding DSLs in programming languages such as Groovy and Scala. (See <a href="http://docs.codehaus.org/display/GROOVY/Writing+Domain-Specific+Languages">this blog for Groovy</a>.) 
</p>
<p>The submitter happened to be a reviewer in another Java One track, so he was able to see my comment, and he was not happy. He emailed me: "I feel strongly that this is mistaken. Most DSL's originate with domain experts, who become weary of using general-purpose languages to work within their domain concepts and patterns. Many of us are the beneficiaries of such efforts, but DSL's don't spring forth from nothingness."</p>
<p>Now here is my thinking. Technically speaking, the submitter is right. A DSL is simply a domain-specific language, and the term does not imply an implementation strategy. You can use a parser and code generator, as was customary in the past, or you can embed the language in a larger host language, by rigging the metaobject protocol, doing tricks with closures and operator overloading, or whatever. </p>
<p>I just think that the embedded approach should be the approach of choice when it is at all feasible. After all, the toolbuilders are busy giving us tools for JRuby, Groovy, and Scala. If your DSL is contained in one of these languages, you get to leverage those tools. If, on the other hand, you start a new language from scratch, you might get a marginally prettier syntax, but you now have to build up a whole tool chain. 
</p>
<p>Consider <a href="http://www.sun.com/software/javafx/script/index.jsp">JavaFX Script</a>. (Doesn't that just roll off your tongue?) It has a bunch of nice features for building GUIs, such as the <code>bind</code> and <code>dur</code> operators. But it is yet another programming language. People need to learn it, they need to build tools for it, they need to learn how to use those tools. Sadiya Hameed, one of my graduate students, is implementing the key features of JavaFX Script in Scala and Groovy. The syntax is a bit clunkier, but not by much. Either of them would have made a fine host for a FX DSL.  
</p>
<p>What do you think? Am I being naive? Is it just too awkward to shoehorn DSL syntax into the Procrustean bed of a host language? Is it crazy to have a program with ten mutually incomprehensible DSLs in Scala or Groovy? Or has the time come to say "no" to building more parsers? 
</p>]]>

</content>
</entry>
<entry>
<title>Flying Saucer Comes Through with Flying Colors, or the Triumph of Infrastructure</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2007/08/flying_saucer_c.html" />
<modified>2007-08-18T22:30:53Z</modified>
<issued>2007-08-18T22:30:42Z</issued>
<id>tag:weblogs.java.net,2007:/blog/cayhorstmann/334.8054</id>
<created>2007-08-18T22:30:42Z</created>
<summary type="text/plain">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.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<h2>Say No To Powerpoint</h2>

    <p>I loathe authoring with Powerpoint (or its OpenOffice equivalent).
    Putting together a presentation requires a horrid amount of mouse clicking
    and fussing with fonts and formatting. Instead, I use the amazing <a
    href="http://www.w3.org/Talks/Tools/Slidy/">HTML Slidy</a>. You write your
    slides in XHTML (I use <a
    href="http://www.xmlmind.com/xmleditor/">XMLMind</a>, but any web editor
    that produces XHTML will do.) Then you add links to the Slidy style sheet
    and JavaScript magic, and you have a great slide show.</p>

    <p>This isn't something that Aunt Tilly would do, but I already know XHTML
    and a bit of CSS, so authoring becomes very, very fast. I dash off a few
    <tt>h1</tt>, <tt>ul</tt>, and <tt>img</tt>, and I am done.</p>

    <h2>Your Mission, Should You Choose to Accept It</h2>

    <p><img alt="???" src="http://weblogs.java.net/blog/cayhorstmann/archive/mission-impossible.jpeg"
    style="float: left; margin-right: 1em;" />Next semester, I will use <a
    href="http://up.ucsd.edu/about/WhatIsUP.html">Ubiquitous Presenter</a> for
    &ldquo;active learning&rdquo; in the classroom. It is a nifty system where
    both the professor and the students can annotate slides. However, the
    slides must be in Powerpoint format (and, I am told, it is best if the
    Powerpoint is not too old or too new or &ldquo;too complex&rdquo;). As an
    alternative, the system will grudgingly accept a set of 576x432 pixel
    image files. (It took me a long time to realize that this means 8x6 inches
    at 72 dots per inch.)</p>

    <p>I forged ahead with this recipe:</p>

    <ol>
      <li>Use <a href="http://www.princexml.com/">PrinceXML</a> to convert
      XHTML to PDF</li>

      <li>Use <a href="http://www.accesspdf.com/pdftk/">Pdftk</a> to burst the
      PDF into a sequence of single-page PDFs</li>

      <li>Use <a href="http://www.imagemagick.org/">ImageMagick</a> to convert
      the pages to PNG</li>
    </ol>

    <p>It worked, but the image quality was rather poor.</p>

    <p><img alt="???" src="http://weblogs.java.net/blog/cayhorstmann/archive/badslide.png" /></p>

    <p>There had to be a better way. My mission was to find one.</p>

    <p>I considered using <tt>JEditorPane</tt>, but I had not been happy with
    it in the past. It has a lot of quirks and doesn't seem very actively
    maintained. Then I happened to spot <a
    href="https://xhtmlrenderer.dev.java.net/">Flying Saucer</a>.</p>

    <h2>Flying Saucer</h2>

    <p><img alt="???" src="http://weblogs.java.net/blog/cayhorstmann/archive/flying-saucer.png"
    style="float: left; margin-right: 1em;" />Flying Saucer is &ldquo;an
    XML/XHTML/CSS 2.1 renderer in 100% Java&rdquo;. It renders to Java2D
    images, and, together with the <a
    href="http://www.lowagie.com/iText/">iText</a> library, to PDF. (It does
    not try to process arbitrary HTML, so you won't want to build a web
    browser with it.) Some people use it to produce PDF or images on the fly,
    for example in web applications. Generate XML or XHTML, use CSS for
    styling, and you can produce quite a variety of output with very little
    work.</p>

    <p>I loaded a slide sample into the Flying Saucer viewer application.
    Impressively enough, all of the CSS was correctly interpreted. Make that
    &ldquo;almost all of the CSS&rdquo;. A bug with image scaling was a
    showstopper, but I sent a message to the mailing list, and <a
    href="https://xhtmlrenderer.dev.java.net/servlets/ReadMsg?list=users&amp;msgNo=817">a
    patch</a> materialized within hours.</p>

    <p>Flying Saucer comes with command-line utilities to generate PDF or
    images, but there was nothing to produce an image per page. In a day, I
    hacked together a <a href="http://weblogs.java.net/blog/cayhorstmann/archive/MultiPageRenderer.java">simple program</a> for
    this purpose, by copying the pagination code from the PDF generator and
    the image rendering code from the image generator. I don't understand all
    the mumbo-jumbo with devices and contexts, but it works perfectly. Here is
    a slide sample:</p>

    <p><img alt="???" src="http://weblogs.java.net/blog/cayhorstmann/archive/goodslide.png" /></p>

    <p>If you ever need to render images or PDF with lots of text and a fairly
    rigid structure, give Flying Saucer a try.</p>

    <h2>Infrastructure</h2>

    <p><img alt="???" src="http://weblogs.java.net/blog/cayhorstmann/archive/infrastructure.jpg"
    style="float: left; margin-right: 1em;" />What does this all mean in a
    bigger way? It is an issue of infrastructure. The Ubiquitous Presenter tools are
    tethered to Powerpoint. It is a fragile infrastructure. There is no
    reliable mechanism to process Powerpoint other than Powerpoint, and even
    that comes with the proviso that the files are neither too old nor too
    new.</p>

    <p>In contrast, open standards and open source enabled me to leverage a
    huge infrastructure. When I submit a bug report about CSS, there was no
    arguing about the expected behavior, but the bug simply got fixed. (Try
    that with Powerpoint!) There are lots of tools that produce or consume
    XML+CSS. The Flying Saucer people integrate the iText stuff; I take the
    Flying Saucer stuff and solve my problem in a day. It's all open source
    and there is very little friction. It isn't something that I think about
    very much, just like I don't usually spend a lot of time thinking about
    the physical infrastructure that surrounds us. As long as it works, it is
    invisible.</p>

    <p>For this reason, I am somewhat reluctant to embrace the Ianguage du
    jour. If I switch to Ruby or Python, I have a different infrastructure.
    How good is it? For example, how do I render XHTML into PDF? Is it like
    moving from the United States to Mexico? Fun at first, but then the bad
    plumbing gets to you? Maybe the JVM will become a part of the
    infrastructure, and in ten years, I'll call Flying Saucer from JRuby or,
    more likely, Scala.</p>]]>

</content>
</entry>
<entry>
<title>A Bundle of Joy - NOT.</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/cayhorstmann/archive/2007/08/a_bundle_of_joy.html" />
<modified>2007-08-02T18:50:53Z</modified>
<issued>2007-08-02T18:48:09Z</issued>
<id>tag:weblogs.java.net,2007:/blog/cayhorstmann/334.7965</id>
<created>2007-08-02T18:48:09Z</created>
<summary type="text/plain">Today, I rant about Sun&apos;s blunder in their bundling of JavaDB in JDK 6. Executive summary: 1. Don&apos;t rely on JavaDB being present in the JDK. 2. A bungled bundle is worse than no bundle at all.</summary>
<author>
<name>cayhorstmann</name>

<email>cay@horstmann.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/cayhorstmann/">
<![CDATA[<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title></title>
  </head>

  <body>
    <p>    
    <img alt="bundle of joy movie" src="http://weblogs.java.net/blog/cayhorstmann/archive/bundle2.jpg"
    style="float:left; margin-right: 1em;" /> When JDK 6 was released, there
    was a lot of buzz about the bundling of Derby, erm, JavaDB: <a
    href="http://coffeecode.net/archives/107-Java-6-is-out;-now-including-JavaDB-aka-Apache-Derby.html">buzz</a>,
    <a
    href="http://weblogs.java.net/blog/forsini/archive/2006/06/java_db_is_now.html">buzz</a>,
    <a
    href="http://weblogs.java.net/blog/davidvc/archive/2006/06/java_db_is_bund.html">buzz</a>.
    Of course, there also was some <a
    href="http://www.bileblog.org/?p=25">bile</a>. Programmer opinion was <a
    href="http://today.java.net/pub/pq/109?page=last&amp;x-maxdepth=0">mixed</a>.
    My personal feeling (recorded <a
    href="http://today.java.net/cs/user/view/cs_msg/20360">here</a> for
    posterity) was &ldquo;Doesn't the Java team have better things to
    do?&rdquo; </p>

    <p>But so what&mdash;once the deed was done, I felt that I might as well
    take advantage of the bundled database. In a couple of books, I suggested
    that readers download JDK 6 and put <i>jdk</i><tt>/lib/db/derby.jar</tt>
    onto the classpath. The publisher of my <a
    href="http://horstmann.com/bigjava">college text</a> developed a nifty
    tool for homework checking that is deployed with Java Web Start. It allows
    students to run sanity checks on their homework assignments, and it
    uploads the solutions and the results of the checks to the professor's
    gradebook. For database problems, it simply uses
    <i>jdk</i><tt>/lib/db/derby.jar</tt>.</p>

    <p>All was peachy until Java SE 6u2. (<a
    href="http://weblogs.java.net/blog/cayhorstmann/archive/2007/07/number_melancho.html#comments">Don't
    get me going</a> on the numbering...) </p>

    <p>Now, out of a sudden, the <a
    href="http://java.sun.com/javase/6/webnotes/README.html#javadb">rules have
    changed</a>. According to Sun, </p>

    <p>&ldquo;This distribution bundles Java DB, Sun Microsystems'
    distribution of the Apache Derby pure Java database technology. Default
    installation locations are: </p>

    <ul>
      <li>Solaris: <tt>/opt/SUNWjavadb</tt></li>

      <li>Linux : <tt>/opt/sun/javadb</tt></li>

      <li>Windows: <tt>C:\Program Files\Sun\JavaDB</tt>&rdquo;</li>
    </ul>

    <p>The reality is a bit more complex. </p>

    <p>On Linux, JavaDB is no longer included in the Sun JDK download. It may
    be that they hope that Ubuntu and others add it to their package, but
    Ubuntu doesn't even use the <tt>/opt</tt> directory. </p>

    <p>On Windows, the installer charmingly continues making the
    <i>jdk</i><tt>/lib/db</tt> directory, but it leaves it empty. Users can
    select where they want JavaDB installed (with <tt>C:\Program
    Files\Sun\JavaDB</tt> as the default). You can find their decision in the
    registry (<tt>HKLM\Sun Microsystems\JavaDB</tt>). Except that the
    uninstaller doesn't remove the registry entry, so you don't want to rely
    on it.</p>

    <p>I have no idea what Apple does with their JDK for the Mac, but I would
    love to know.</p>

    <p>The takeaway from this sorry episode is: </p>

    <ul>
      <li>Don't rely on JDK users having JavaDB. They may or may not have it,
      and if they do, it is a nightmare to locate it.</li>

      <li>If you write an article or book, just tell your readers to download
      <a href="http://db.apache.org/derby/">Apache Derby</a>. </li>

      <li>The lesson from Sun's blunder is: Don't bundle unless (a) there is a
      truly pressing need and (b) you have the resources to do it right. A
      bungled bundle is worse than not bundling in the first place. </li>
    </ul>
  </body>
</html>]]>

</content>
</entry>

</feed>