Skip to main content

Help Educate Java Beginners: Static Import?

Posted by editor on August 10, 2009 at 7:27 AM PDT

Java Champion Cay Horstmann is asking developers for a bit of assistance as he rewrites a Java book for beginners. His question is simple: "Are you using static import?":

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


import static java.lang.System.out;

public class Greeting
{
   public static void main(String[] args)
   {
      out.println("Hello, World!");
   }
}

I would no longer have to dissect the awful System.out.println("Hello, World!") expression.

Cay notes that, for example, sin(angle * PI / 180) "looks so much nicer than" Math.sin(angle * Math.PI / 180). However, his objective in asking the question is to:

get the reaction of the average Java coder here. Have you switched from System.out to out with a static import? Would you think it weird to look at other people's code that did that? Or would you welcome it?

Since the book is for Java beginners, it would not make sense to teach something that simply isn't done by the vast majority of Java developers. The beginner, in their first job, might look at inherited code they have to work on, and think something's wrong.

So far, 19 comments have been posted in response to Cay's question. It turns out that "Are you using static import?" is indeed a stimulating question!


In Java Today, we're featuring Mario Fusco on the Lambdaj Project: Jim Wright interviews Mario Fusco, creator of the Lambdaj Project, in this java.net Community Corner 2009 podcast, recorded at JavaOne. "Lambdaj is a library that makes easier to manipulate collections in a pseudo-functional and statically typed way. In our experience to iterate over collection, especially in nested loops, is often error prone and makes the code less readable. The purpose of this library is to alleviate these problems employing some functional programming techniques but without losing the static typing of java..."

Java Champion Adam Bien talks about his Five Days with NetBeans68M1, JSF20, EJB31, Maven, and GlassFish V2/V3... And the Result: "NetBeans 6.7.1 worked well for me, even the new Java EE 6 stuff can be used after some tweaks. Netbeans 6.8m1 supports Java EE 6 out-of-the-box, so I switched some projects and worked intensively with it. Conclusion..."

Angela Caicedo has an interesting article on the Sun Developer Network, Developing Content with JavaFX Mobile, Java ME, and the Messaging API (JSR 205) - Background: "One of the questions every time a new technology appears is "How can I integrate this technology with my existing applications?" This article shows you how to use the JavaFX mobile user interface with existing Java ME APIs and, in particular, the Messaging API (JSR 205). You will build two applications: one will create and send the message, and the second application will receive the message..."


In today's Weblogs, Sebastien Dionne writes about GWS Deployer 1.9.17 : Reloaded : New Features Part 1: "Since the Grizzly release 1.9.17. There were few new features for Deployer. Let's take a look of theses "must have" features."

Cay Horstmann asks developers Are you using static import?: "I would love to replace System.out.println with a static import and out.println in an introductory textbook, so that I could focus on objects and methods rather than what System.out means, but I am worried that it is considered too weird. What do you think?"

And John Ferguson Smart has written A silly song for Agile2009: "To the tune of 'Blowing in the wind', by Bob Dylan. This (rather silly) text was inspired by a tweet from Andres Almiray How many sprints must a girl conduct, Before scrum-master she becomes? Yes, 'n' how many stories must we implement, Before..."


In the Forums, Felipe Gaucho has a question about @Local access in EAR file: "I have this EAR file, web.war, ejb.jar, lib/ejb.client.jar. In my EJB I have beans I want to annotate as @Local ... problem is: if I use @Local, the classes od web.war cannot find the reference to the EJBs.. but if I keep the same code and packaging structure and just chance the annotation to @Remote, it works..."

mcapelati asks WHY my j2me app stops sending http data...: "Hi folks, Hi have an J2ME application that should get some data and send them to an external php application. Everything was working fine. But now, misteriously, it just stops to send data (!). There was a change on the server - but I've never heard that there was some incompatibility with j2me and linux+apache+php... Another thing was I upgrade to Netbeans 6.5.1. I've lost 2 whole days looking for the problem, and nothing... Watching by Netbeans debugger, all data are fine, and variables are with right values - but it simply does not POST the data to php..."

And skolson asks about User certificate authentication with jax-ws 2.1.7 client and IIS .Net srvr: "I'm attempting to use basic jax-ws as a web service client to a .Net web service that requires a client certificate to authenticate. No WS-* specifications are involved, this is just straight client certificate authentication. So far my attempts all result in 403.7 errors returned from IIS, and the java SSL debug output shows no attempt by jax-ws to submit the client cert in the configured keyStore (see below). I figure I must be missing something, and am hoping someone can point me in the right direction. I've made a modified cacerts keystore that has the correct CA certs involved for both the SSL negotiation and the issuer of the client cert..."


The current Spotlight is Mario Fusco on the Lambdaj Project: "Jim Wright interviews Mario Fusco, creator of the Lambdaj Project, in this java.net Community Corner 2009 podcast, recorded at JavaOne: "Lambdaj is a library that makes easier to manipulate collections in a pseudo-functional and statically typed way. In our experience to iterate over collection, especially in nested loops, is often error prone and makes the code less readable. The purpose of this library is to alleviate these problems..."


This week's java.net Poll asks "Which feature phone platform offers developers the greatest capability?". Voting will be open through next Thursday.


Our Feature Articles include Jeff Friesen's new article Introducing Custom Paints to JavaFX, which shows how you can leverage undocumented JavaFX capabilities to support custom paints in JavaFX Version 1.2. We're also featuring Biswajit Sarkar's Using the Payment API for Microcredit and Other Applications, which describes how to apply the Payment API (JSR 229) in JavaME applications.


The latest Java Mobility Podcast is Java Mobility Podcast 84: Valderi Leithardt on using SunSpots for gesture recognition.: "An interview with Ph.D. candidate Valderi Leithardt in Brazil on using SunSpots for gesture recognition."

The latest OpenJDK Podcast is

The latest JavaOne Community Corner Podcast is


-->


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.

Java Champion Cay Horstmann is asking developers for a bit of assistance as he rewrites a Java book for beginners...

Related Topics >>