Skip to main content

Have A Heart

Posted by editor on November 27, 2007 at 7:50 AM PST


Help the beginners figure out autoboxing

Sometimes the "Not-So-Stupid" question is a discussion-starter, with lots of ways the question can be answered. But other times, there really is something of a "correct" answer, and the existence of the question gets at the idea of why this answer isn't easier to find.

Consider today's not-so-stupid question, presented as
our Feature Article,
(Not So) Stupid Questions 20: Primitives and Collections. It cites a Sun Java SE 5.0 page that says:

As any Java programmer knows, you can't put an int (or other primitive value) into a collection. Collections can only hold object references, so you have to box primitive values into the appropriate wrapper class (which is Integer in the case of int).

Yet, a simple 10-line program shows it's trivially easy to add ints directly to an ArrayList. So what's the deal?

The seasoned developer knows that what's up is autoboxing, the automatic conversion by the compiler of integers to their primitive-wrapping object equivalents: ints become Integers, floats become Floats, etc. In fact, that's even the title of the documentation page that the above quote comes from. Problem is, the doc page kind of buries the idea of autoboxing in some too-clever code, and a discussion of performance considerations. It might have been better to take a paragraph and explicitly say something like "myArrayList.add(1) throws a compile-time exception before Java 5, and does what you expect it to in Java 5 and later."

And maybe that's something to talk about, that this is a feature that directly addresses problems developers have had with previous versions of Java, without considering what it looks like to the new developer who comes to the language without that experience, without presumptions or biases. Maybe it doesn't make sense to fresh eyes like it does to anyone who's done it the hard way. The conservative "no more language changes" crowd may see this as a problem, but then again, is autoboxing really unintuitive? Isn't the point to do what you would expect myArrayList.add(1) to do?

Hmmm... maybe not a stupid question at all...


In today's Weblogs,
David Herron asks
What is Needed for the Next Level of Internet Applications?
"My point is that one can only go so far in application features using an application development framework hosted inside a web browser. Stagnation in browsers, as Ian put it, means application developers have had stagnancy in the capabilities they could code into their applications."

Scott Oaks crunches the story behind the numbers in
A scalable SPECjAppServer 2004 submission.
"Sun has submitted a SPECjAppServer 2004 submission that scales across a lot of hardware. Is it just a question of throwing hardware at the problem?"

Finally, Sahoo offers
A javac plugin to manage your persistence.xml.
"In this article, I talk about a Java compiler plugin that can create the persistence.xml file for you automatically during normal course of Java code compilation and show how easy it is to use in your existing build scripts - be it maven or ant or shell script."


In Java Today,

The Aquarium notes, "the most recent episode of the GlassFish Podcast is an interview about Hudson with Kohsuke. Listen to find out how Kohsuke's laziness is what made the project happen..." Also if you're using or simply interested in Hudson, the next GlassFish v3 Brown Bag is focusing on Hudson (Tues, Dec 4th : 9am - 10:30am PST). These are conference calls open to the entire GlassFish community. Previous topics covered (Subversion & Maven2) have slides and audio available.

Last week, Neal Gafter discussed the possibility of adding "extension methods" in Java 7, which allow a user to add a method to an interface or class that you don't control. In his blog Extension methods, Stephen Colebourne offers some ideas on alternative syntax for the feature. "My proposal is that the freedom given to the user by the use-site approach is far more desirable, but the possible side-effects are nasty. My preference would be to add a visible marker to show that this isn't a regular method."

A new Artima article covers a JavaZone presentation in which Matt Raible Compares Six Java Web Frameworks. "Matt Raible's presentation comparing six Java Web frameworks is now available online in a video format. The talk, given at the JavaZone conference in Oslo earlier this fall, compares JSF, Spring/MVC, Stripes, Struts 2, Tapestry, and Wicket. Raible also has updated presentation slides that include GWT, Seam, and Flex in the comparison as well." The video of the presentation is available from the Belgian JUG's PARLEYS.com site.


In today's Forums,
cerveny_richard wonders about
Securing JDBC password.
"How can I protect password for JDBC connection pool? Our security policy requires database administrators to generate new password every few weeks and this password is encrypted into a file on filesystem. I can read this password and change resource pool password programatically but password is written into domain.xml in plain format which is forbiden. Is there some (preferably easy) solution for this? I know about aliases but how can I use them programatically?"

franco_dalmolin seeks to share
Deployment experiences with JXTA 2.5.
"We have deployed our production system on JXTA 2.5 in a multi-rdv multi-relay configuration. We have been struggling for many weeks with it and have still not solved our deployment issues with the new 2.5 super peers. The core problem seems to relate to the new NIO based TCP transport implementation (a.k.a. "epoll bug") and its behavior on certain OS's, Linux kernels, and Java versions. Currently we run on CentOS kernel 2.6.18 with Java 6 update 3. We ran also tests on Fedora kernel 2.6.23 and it seemed fine in a test simulating 100 concurrent edge peers running all weekend. Are there any other experiences out there?"

lcmeng provides an answer to his or her own question in
Re: Where to find an up-to-date tutorial of JAI programming.
"Alright then. I'll serve as my own savior. 1. Go to: https://jai-demos.dev.java.net/servlets/ProjectSource and check out the source files. The jai-samples will be good live tutorial for basic JAI concepts; the jai-app will be a good guide for more complicated implementations. 2. A PDF tutorial is available. Just google "Java Advanced Imaging API: A Tutorial" and "Rafael Santos" with filetype:pdf. It's relatively new (finished in 2K4). It provides codes for specific CG algorithms. 3. An interactive tutorial provided by Sun can be found.It's outdated, but looks kool. 4. BOF-Tutorial at JavaOne 2K5 and 2K6 available in pdf, just google them. BTW, BOF means Birds Of a Feather. There are what I've found so far. Hope it will help those new kids to JAI just like me."


Current and upcoming Java
Events
:

Registered users can submit event listings for the href="http://www.java.net/events">java.net Events Page using our href="http://today.java.net/cs/user/create/e">events submission form.
All submissions go through an editorial review before being posted to the
site.


Archives and Subscriptions: This blog is delivered weekdays as
the Java
Today RSS feed
. Also, once this page is no longer featured as the
front page of java.net it will be
archived along with other past issues in the href="http://today.java.net/today/archive/">java.net Archive.

Help the beginners figure out autoboxing