Java Verbosity

I’ve been doing quite a bit of Java over the last fortnight. It’s much easier with eclipse of course, but it’s still pretty verbose. But I dunno, maybe it’s just me, a whingy old Perl coder. But then again, look what I’ve just found in the Java Cookbook:

  public class Ls {
    public static void main(String argh_my_aching_fingers[]) {
      // ...
    }
  }

Glad to know I’m not the only one. :-)

Comments 6

  1. Marc wrote:

    I hear you! I’m so glad there’s a macro for such things in NetBeans, it expands it for you so you only have to type “pvsm”. I wonder if you’ve tried that one instead of Eclipse, bearing in mind it’s 2009 now and not 2006… It’s the first Java IDE I’m really trying to learn with, and it’s a bit confusing to separate all the IDE fluff that comes with it.

    This next one might make you laugh too. I don’t even own an Apple device of any sort, but I stumbled across this example of how to add a shortcut key to a menu item in Swing:

        JMenuItem saveAsItem = new JMenuItem("Save As...");
        saveAsItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, (java.awt.event.InputEvent.SHIFT_MASK | (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()))));
        saveAsItem.addActionListener(new ActionListener(  ) {
          public void actionPerformed(ActionEvent e) { System.out.println("Save As...") ; }
        });
        fileMenu.add(saveAsItem);

    Looks like Swing takes the biscuit!

    Posted 04 Jun 2009 at 16:19
  2. Marc wrote:

    Sorry I meant “psvm” of course…

    Posted 04 Jun 2009 at 16:20
  3. Marc wrote:

    And the code’s from here.

    @Marc

    Posted 04 Jun 2009 at 16:21
  4. Marc wrote:

    Of course, this layout messed up any formatting it might’ve had, how much clearer can you make a method call that contains another method call that eventually drills down even further to return a value from an instance of the Toolkit class… It’s making me dizzy; just count the parentheses!

    Posted 04 Jun 2009 at 16:26
  5. Marc wrote:

    My last post now, I apologise for the spiel! But you see, it got to the point where I couldn’t even figure out that the setAccelerator method is called with an instance of the KeyStroke class (I think), supplied with the constant KeyEvent.VK_S representing the ‘S’ key… Ad nauseum! There must be an easier, cleaner way to do it whilst still maintaining accessibility, portability and design standards… From my brief looks at the GTK, Qt/KDE and Tk libraries, it seems that it is possible to some degree – although I couldn’t be sure about that!

    Posted 04 Jun 2009 at 16:35
  6. dom wrote:

    @Marc: I’ve just added the formatting back in for you.

    I have to be honest, when it comes to GUI programming I’ve only seen two systems that look at all “clean” (bear in mind I’m emphatically not a GUI programmer).

    1. Interface Builder for the mac. This totally avoids code, but it’s super-easy to throw together a nice looking UI.
    2. The declarative code in JavaFX Script looks like a really nice way of doing things. Of course they had to design a language around the domain, but frankly that strikes me as a good idea.

    In general, I’ve become quite immune to the verbosity of Java since I first wrote this post. Heck, if I can learn to like maven

    Posted 04 Jun 2009 at 16:49