Platinum Partner
java

Judicious Java IDE Usage and the Road to Enlightenment

An often heard complaint in relation to the Java IDE's goes like this: "I want to do my own coding. I don't want stuff being generated for me. Firstly because I don't learn anything that way, except how to use the tool, which locks me in to that tool, and secondly because I don't trust that the code being generated is always optimal." In this article, I provide an alternative approach to using an IDE, an approach for sceptical programmers.

Often, trainings and tutorials that lean heavily on IDEs are very point-and-clicky. Let's take JSR-295 as our example, i.e., the JSR for beans binding. Using NetBeans IDE, our beans binding tutorial could easily be as follows:

  1. Use the New Project wizard to create a new Java application.
  2. Use the New File wizard to create a JFrame.
  3. Use the Palette to add a JTextArea.
  4. Use the Palatte to add a JTextField.
  5. Right-click the JTextField, choose Bind and then "text". The Bind dialog opens.
  6. Under "Binding Source", choose jTextArea1 and under "Binding Expression", choose ${text}. Click OK.
  7. Now deploy the application and notice that when you type something in the JTextField, the JTextArea is automatically updated.

Hmmm. What have I learned about JSR-295? Nothing at all. But, possibly that's not the intention of the tutorial in the first place. However, if this were to be an introduction to JSR-295 for me, I, as a sceptical programmer, would throw the IDE out the window. (A virtual window, I guess.) Not only have I learned nothing about beans binding, but if I want to achieve the above connection between components at any point in the future, I will ALWAYS have to use NetBeans IDE, because I have learned no general principles at all.

However, let's now leverage the IDE to its full potential and REALLY learn something significant about beans binding. We'll continue with the same tutorial, so we assume that the user has taken the steps above already. So, the steps that follow below would come after those above.

  1. Create a new JFrame in your application and again add a JTextArea and a JTextField to it.
  2. Open the Source view of the JFrame you created in the first section above.
  3. Copy the org.jdesktop.beansbinding.BindingGroup declaration to your new JFrame and instantiate it in the JFrame's constructor.
  4. Copy the definition of org.jdesktop.beansbinding.Binding into your constructor as well.
  5. Copy the method that adds the binding to the group and the method that binds it.
  6. Finally, you should now see the following, all copied from your original JFrame into your new one:

    ...
    ...
    ...
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;

    public NewJFrame2() {
    initComponents();
    bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
    org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.
    createAutoBinding(
    org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
    jTextArea1, org.jdesktop.beansbinding.ELProperty.create("${text}"),
    jTextField1, org.jdesktop.beansbinding.BeanProperty.create("text"));
    bindingGroup.addBinding(binding);
    bindingGroup.bind();
    }
    ....
    ....
    ....

Now, we've made some real progress in terms of learning about beans binding. When I run the JFrame above, I have the same result as before. The difference is that I, as the user of the IDE, constructed the code myself, based on the code that had previously been generated for me. At this point, I am using the IDE as an advanced code snippet generator. I'm not going straight into production with code that I don't understand at all. I have had some code generated for me, then I have looked at it carefully, and extracted those parts that are relevant for my scenario. I recreated the original scenario, minus the generated beans binding stuff, and then rebuilt those parts into it.

I am still no expert at beans binding, based on where I am above. However, right now I do know that I need a BindingGroup and a Binding. I also know that the binding is added to the binding group and that the binding group is bound. I can also see from the definition of the binding that there's something referred to as an update strategy, which here is marked as READ_WRITE. I can imagine what that might mean. I also see my JTextArea and JTextField represented in the binding. I am now a lot further. Still not there, but a lot further than I would have been had I simply been using the point-and-click approach to learning.

Hence, judicious use of an IDE can clearly be a help, rather than a hindrance, when introducing yourself to new techniques, such as beans binding. By the way, if you're interested in beans binding, I highly recommend this recent interview with Shannon Hickey.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}