<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Dustin Marx's blog</title>
  <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/blog/185"/>
  <link rel="self" type="application/atom+xml" href="http://www.javaworld.com/community/blog/185/atom/feed"/>
  <id>http://www.javaworld.com/community/blog/185/atom/feed</id>
  <updated>2012-01-04T10:00:22-05:00</updated>
  <entry>
    <title>JavaFX 2 Animation: Path Transitions</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8311" />
    <id>http://www.javaworld.com/community/node/8311</id>
    <published>2012-02-06T23:41:00-05:00</published>
    <updated>2012-02-07T00:01:30-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p>One of the flashiest aspects of <a href="http://javafx.com/">JavaFX</a> 2 is its <a href="http://www.asgteach.com/blog/?p=372">animation</a> support. The insightful <a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm">Creating Transitions and Timeline Animation in JavaFX</a> covers using both <a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm#CJAJJAGI">Transitions</a> and <a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm#CJAFADFJ">Timelines</a> in JavaFX 2.    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>One of the flashiest aspects of <a href="http://javafx.com/">JavaFX</a> 2 is its <a href="http://www.asgteach.com/blog/?p=372">animation</a> support. The insightful <a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm">Creating Transitions and Timeline Animation in JavaFX</a> covers using both <a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm#CJAJJAGI">Transitions</a> and <a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm#CJAFADFJ">Timelines</a> in JavaFX 2. In this blog post, I adapt an example provided in that tutorial to specifically demonstrate Path Transitions.</p>

<p>Example 2 ("Path Transition") shown in <a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm">Creating Transitions and Timeline Animation in JavaFX</a> demonstrates creating a Path with classes from the JavaFX 2 "shapes" package: <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/shape/Path.html">javafx.scene.shape.Path</a>, <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/shape/MoveTo.html">javafx.scene.shape.MoveTo</a>, and <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/shape/CubicCurve.html">javafx.scene.shape.CubicCurve</a>. That example then demonstrates instantiation of a <a href="http://docs.oracle.com/javafx/2.0/api/javafx/animation/PathTransition.html">javafx.animation.PathTransition</a> and applying an instantiated <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/shape/Rectangle.html">javafx.scene.shape.Rectangle</a> to move along the created Path.</p>

<p>In my code listing below, I've made some slight changes to Example 2 in <a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm">Creating Transitions and Timeline Animation in JavaFX</a>. I have specifically changed the moving shape from a rectangle to a <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/shape/Circle.html">Circle</a>, added two "end knobs" to the path as two separate circles, and added the ability to change the opacity of the path along with the animated circle moves. The nice side effect of using a zero opacity is that the path itself does not appear and it instead looks like the circle is moving along freely. I tried to break each major piece of this up into its own private method to make it easier to see the "chunks" of functionality.</p>

<strong>JavaFxAnimations.java</strong>
<pre name="code" class="java" style="font-size: 9pt; overflow: auto;">
package dustin.examples;

import java.util.List;
import javafx.animation.PathTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * Simple example demonstrating JavaFX animations.
 * 
 * Slightly adapted from Example 2 ("Path Transition") which is provided in
 * "Creating Transitions and Timeline Animation in JavaFX"
 * (<a href="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm" title="http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm">http://docs.oracle.com/javafx/2.0/animations/jfxpub-animations.htm</a>).
 * 
 * @author Dustin
 */
public class JavaFxAnimations extends Application
{
   /**
    * Generate Path upon which animation will occur.
    * 
    * @param pathOpacity The opacity of the path representation.
    * @return Generated path.
    */
   private Path generateCurvyPath(final double pathOpacity)
   {
      final Path path = new Path();
      path.getElements().add(new MoveTo(20,20));
      path.getElements().add(new CubicCurveTo(380, 0, 380, 120, 200, 120));
      path.getElements().add(new CubicCurveTo(0, 120, 0, 240, 380, 240));
      path.setOpacity(pathOpacity);
      return path;
   }

   /**
    * Generate the path transition.
    * 
    * @param shape Shape to travel along path.
    * @param path Path to be traveled upon.
    * @return PathTransition.
    */
   private PathTransition generatePathTransition(final Shape shape, final Path path)
   {
      final PathTransition pathTransition = new PathTransition();
      pathTransition.setDuration(Duration.seconds(8.0));
      pathTransition.setDelay(Duration.seconds(2.0));
      pathTransition.setPath(path);
      pathTransition.setNode(shape);
      pathTransition.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
      pathTransition.setCycleCount(Timeline.INDEFINITE);
      pathTransition.setAutoReverse(true);
      return pathTransition;
   }

   /**
    * Determine the path's opacity based on command-line argument if supplied
    * or zero by default if no numeric value provided.
    * 
    * @return Opacity to use for path.
    */
   private double determinePathOpacity()
   {
      final Parameters params = getParameters();
      final List&lt;String&gt; parameters = params.getRaw();
      double pathOpacity = 0.0;
      if (!parameters.isEmpty())
      {
         try
         {
            pathOpacity = Double.valueOf(parameters.get(0));
         }
         catch (NumberFormatException nfe)
         {
            pathOpacity = 0.0;
         }
      }
      return pathOpacity;
   }

   /**
    * Apply animation, the subject of this class.
    * 
    * @param group Group to which animation is applied.
    */
   private void applyAnimation(final Group group)
   {
      final Circle circle = new Circle(20, 20, 15);
      circle.setFill(Color.DARKRED);
      final Path path = generateCurvyPath(determinePathOpacity());
      group.getChildren().add(path);
      group.getChildren().add(circle);
      group.getChildren().add(new Circle(20, 20, 5));
      group.getChildren().add(new Circle(380, 240, 5));
      final PathTransition transition = generatePathTransition(circle, path);
      transition.play(); 
   }

   /**
    * Start the JavaFX application
    * 
    * @param stage Primary stage.
    * @throws Exception Exception thrown during application.
    */
   @Override
   public void start(final Stage stage) throws Exception
   {
      final Group rootGroup = new Group();
      final Scene scene = new Scene(rootGroup, 600, 400, Color.GHOSTWHITE);
      stage.setScene(scene);
      stage.setTitle("JavaFX 2 Animations");
      stage.show();
      applyAnimation(rootGroup);
   }

   /**
    * Main function for running JavaFX application.
    * 
    * @param arguments Command-line arguments; optional first argument is the
    *    opacity of the path to be displayed (0 effectively renders path
    *    invisible).
    */
   public static void main(final String[] arguments)
   {
      Application.launch(arguments);
   }
}
</pre>

<p>The following series of screen snapshots show this simple JavaFX animation example in action. They are listed in order of descending opacity (from 1.0 to 0.0).</p>

<strong>Demonstration of Adapted PathTransition Example (Opacity 1.0)</strong>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-6cBHRPCjnqE/TzCmt7LUpPI/AAAAAAAAC_4/El7lUUlYuY4/s1600/pathTransitionOpacity1BallOnPath.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="226" width="320" src="http://2.bp.blogspot.com/-6cBHRPCjnqE/TzCmt7LUpPI/AAAAAAAAC_4/El7lUUlYuY4/s320/pathTransitionOpacity1BallOnPath.png" /></a></div>

<strong>Demonstration of Adapted PathTransition Example (Opacity 0.2)</strong>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-X3Vapb9DqdE/TzCmyrT8HbI/AAAAAAAADAE/Jlm7fH39wjw/s1600/pathTransitionOpacity02BallOnPath.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="226" width="320" src="http://1.bp.blogspot.com/-X3Vapb9DqdE/TzCmyrT8HbI/AAAAAAAADAE/Jlm7fH39wjw/s320/pathTransitionOpacity02BallOnPath.png" /></a></div>

<strong>Demonstration of Adapted PathTransition Example (Opacity 0.05)</strong>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-QG5Cd-tXAEU/TzCm2iWxTcI/AAAAAAAADAU/vMYI9CIEYLk/s1600/pathTransitionOpacity005BallOnPath.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="226" width="320" src="http://2.bp.blogspot.com/-QG5Cd-tXAEU/TzCm2iWxTcI/AAAAAAAADAU/vMYI9CIEYLk/s320/pathTransitionOpacity005BallOnPath.png" /></a></div>

<strong>Demonstration of Adapted PathTransition Example (Opacity 0.0)</strong>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-ysyVlBfL03A/TzCm7h3UqqI/AAAAAAAADAc/M_4k65Ij7OA/s1600/pathTransitionOpacity0BallOnPath.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="226" width="320" src="http://1.bp.blogspot.com/-ysyVlBfL03A/TzCm7h3UqqI/AAAAAAAADAc/M_4k65Ij7OA/s320/pathTransitionOpacity0BallOnPath.png" /></a></div>

<p>Each of the above screen snapshots was taken after running the application with the specified command-line argument (1, 0.2, 0.05, and 0).</p>

<p>This adapted example has demonstrated using <code>PathTransition</code> to animate a node's movement along the prescribed path (I have <a href="http://marxsoftware.blogspot.com/2011/12/javafx-20-christmas-tree-javafx-20.html">blogged on use of Path</a> and some of its <a href="http://marxsoftware.blogspot.com/2011/12/javafx-20-path-alternatives.html">alternatives</a> before). Developers can implement their own derivative of <a href="http://docs.oracle.com/javafx/2.0/api/javafx/animation/Transition.html">Transition</a> and there are other supplied transitions supported as well (such as <a href="http://docs.oracle.com/javafx/2.0/api/javafx/animation/FadeTransition.html">FadeTransition</a>, <a href="http://docs.oracle.com/javafx/2.0/api/javafx/animation/ParallelTransition.html">ParallelTransition</a>, and <a href="http://docs.oracle.com/javafx/2.0/api/javafx/animation/SequentialTransition.html">SequentialTransition</a>).</p>

<p>It is a straightforward process to quickly begin applying JavaFX 2 animation using the provided Transition classes.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-46725781961741473?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/UwG6fbsZBzA" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>Book Review: JBoss AS 7: Configuration, Deployment, and Administration</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8308" />
    <id>http://www.javaworld.com/community/node/8308</id>
    <published>2012-01-31T22:04:00-05:00</published>
    <updated>2012-02-01T11:00:16-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><p>I eagerly accepted <a href="http://www.packtpub.com/" rel="nofollow" rel="nofollow">Packt Publishing</a>'s invitation to review <a href="https://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book" rel="nofollow" rel="nofollow">JBoss AS 7: Configuration, Deployment, and Administration</a> because it has been several years since I last used JBoss and I was curious to learn more about <a href="http://www.jboss.org/as7" rel="nofollow" rel="nofollow">JBoss AS 7</a>.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>I eagerly accepted <a href="http://www.packtpub.com/" rel="nofollow">Packt Publishing</a>'s invitation to review <a href="https://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book" rel="nofollow">JBoss AS 7: Configuration, Deployment, and Administration</a> because it has been several years since I last used JBoss and I was curious to learn more about <a href="http://www.jboss.org/as7" rel="nofollow">JBoss AS 7</a>. I have already written about my <a href="http://marxsoftware.blogspot.com/2012/01/first-impressions-of-book-jboss-as-7.html" rel="nofollow">First Impressions of Book 'JBoss AS 7 Configuration, Deployment and Administration'</a> and in this post I review the book in greater detail while attempting to minimize how much I repeat from that post. My review is based on an electronic (PDF) copy of <em>JBoss AS 7: Configuration, Deployment, and Administration</em>.</p>
<p><strong>General Features</strong></p>
<p><em>JBoss AS 7: Configuration, Deployment, and Administration</em> highlights particularly important notes and warnings within boxing that makes them obvious and with an icon representing a pencil and paper. Similarly, tips and tricks also attract special attention with similar boxing and with a light bulb icon. It is helpful to have the most important notes and tips and tricks highlighted like this.</p>
<p>It didn't take much reading of this book to realize how significantly new JBoss AS 7's architecture is. One of the strengths of <em>JBoss AS 7: Configuration, Deployment, and Administration</em> is its comparisons of previous versions of JBoss AS to JBoss AS 7. These comparisons help to understand how changed JBoss AS 7 is and should be especially helpful to anyone migrating to JBoss AS 7 from a previous version.</p>
<p>This book provides several tables of various configuration options and their descriptions. These tables provide easy reference for various configuration options. Although I mostly just skimmed these as I read this book, I noted their existence for future reference when configuring various parts of JBoss AS 7.</p>
<p>Command line interfaces and script-based configuration and administration are emphasized throughout the book. I appreciate this because I tend to use command line approaches far more frequently than I use graphical tools, but some books focus almost exclusively on the graphical tools.</p>
<p>Perhaps the greatest strength of <em>JBoss AS 7: Configuration, Deployment, and Administration</em> is its focus on what its title promises: configuration, deployment, and administration. Although this book does provide brief introductory details about Java EE, the book assumes that the reader will look to focused books or tutorials for detailed information on Java EE. This allows the book to focus on administration and configuration of and deployment to JBoss AS 7.</p>
<p>Although examples in the book specifically use Eclipse, MySQL, and Windows, the descriptions and explanations are broad enough to cover other choices of IDE, database, and operating system respectively. The illustrations assuming one of these are relatively rare and most of the discussion is more general to JBoss AS 7 rather than to any of these supporting products. In many of these cases, alternatives (and how to use those alternatives) are mentioned. The final chapter (cloud computing with OpenShift) and the Appendix (common commands and operations) provide Linux-based examples.</p>
<p>There is a small number of typos and a few instances of questionable sentence structure, but the author's writing style generally flows easily and is easy to follow. There are numerous drawings, tables, and screen snapshots to illustrate points and highlight the more important details. I like the significant white space and the call outs for special notes and observations.</p>
<p><strong>Chapter 1: Installing JBoss AS 7</strong></p>
<p>Because I have not used JBoss for several years, I needed to install JBoss AS 7 and <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_1" rel="nofollow">this chapter</a> provides an easy guide to doing that. The chapter begins with brief coverage of the usefulness of Java EE application servers and of JBoss AS 7's high-level design. It then moves into the practical steps necessary for installing JBoss AS 7. The author recommends in one of the "important notes" that readers download and use the Java 6 SDK, but does acknowledge that Java SE 7 SDK is available and should work fine with JBoss AS 7. The chapter discusses installation on Windows and Linux/Unix and even includes a "tip/trick" highlighting of installation on Windows Vista. The chapter goes beyond basic installation (which amounts to uncompressing archive files) to discuss starting and stopping JBoss AS 7 and using <a href="https://community.jboss.org/wiki/CommandLineInterface" rel="nofollow">Command Line Interface</a> (CLI) to connect to it locally and remotely.</p>
<p>The initial chapter also discusses installation of <a href="http://www.eclipse.org/" rel="nofollow">Eclipse</a> ("the development environment used in this book"). Besides downloading and installing Eclipse (<a href="http://eclipse.org/indigo/" rel="nofollow">Indigo</a>), the chapter also discusses installation of the JBoss AS plugins (part of <a href="http://download.jboss.org/jbosstools/updates/development/indigo/" rel="nofollow">JBoss Tools</a>) for Eclipse.</p>
<p>One of my favorite parts of this initial chapter is its coverage of the application server's <a href="https://docs.jboss.org/author/display/AS7/Getting+Started+Guide#GettingStartedGuide-AS7DirectoryStructure" rel="nofollow">directory structure</a> and differentiation of JBoss AS 7's "standalone servers and domain servers." This was an important distinction for me coming back to JBoss after such a long period of time, but was an easy one to grasp because of my familiarity with <a href="http://glassfish.java.net/" rel="nofollow">GlassFish</a>. After differentiating between the types of servers supported in JBoss AS 7, the section concludes with coverage of several significant directories/folders in the JBoss AS 7 installation.</p>
<p><strong>Chapter 2: Configuring the Application Server</strong></p>
<p>With JBoss AS 7 and tools (Eclipse) installed, it is natural to move onto configuring the JBoss AS 7 instance. <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_2" rel="nofollow">This chapter</a> had some surprises for me, including starting with this: "The application configuration has also been renewed, moving from a large set of XML files to a single monolithic file." The chapter discusses this single file and covers its default names (depending on server configuration). It goes through the configuration file one major section at a time, detailing how to configure the server in each area. There is quite a bit in this chapter on configuring logging. Another thing I learned here that has changed in JBoss in recent years is default use of its <a href="https://community.jboss.org/thread/154993#555972" rel="nofollow">own logging framework</a>.</p>
<p><strong>Chapter 3: Configuring Enterprise Services</strong></p>
<p>The <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_3" rel="nofollow">third chapter</a> is on configuring enterprise services. This chapter specifically focuses on configuring database connectivity, EJB container, messaging service, and transaction service.</p>
<p>The section of Chapter 3 on configuring database connectivity mentions that JBoss AS 7 comes with the <a href="http://www.h2database.com/html/main.html" rel="nofollow">H2</a> open source database server built in, but then uses <a href="http://www.mysql.com/" rel="nofollow">MySQL</a> for its examples. I liked how this chapter compared and contrasted how database configuration was performed in previous versions of JBoss AS to how it is now done in JBoss AS 7. The chapter demonstrates XML-based configuration of a data source (and how it was similar to that used in previous versions of the JBoss application server), but then also shows <a href="http://blogs.oracle.com/Lance/entry/introducing_the_datasourcedefinition_annotation" rel="nofollow">how to use</a> the <a href="http://docs.oracle.com/javaee/6/tutorial/doc/" rel="nofollow">Java EE 6</a> annotation <a href="http://docs.oracle.com/javaee/6/api/javax/annotation/sql/DataSourceDefinition.html" rel="nofollow">@DataSourceDefinition</a> to programmatically configure the data source in conjunction with an <a href="http://www.theserverside.com/news/1321151/New-Features-in-EJB-31" rel="nofollow">EJB 3.1</a> Singleton EJB.</p>
<p>Chapter 3's section on configuring the EJB container starts by introducing the basics of EJBs with specific introductory focus on the "new EJB 3.1 variants introduced by Java EE 6": <a href="http://docs.oracle.com/javaee/6/tutorial/doc/gipvi.html" rel="nofollow">Singleton EJB</a>, <a href="http://blogs.oracle.com/kensaks/entry/optional_local_business_interfaces" rel="nofollow">No-Interface EJB</a>, and <a href="http://blogs.oracle.com/arungupta/entry/totd_137_asynchronous_ejb_a" rel="nofollow">Asynchronous EJB</a>. The chapter discusses in detail how to configure the different types of EJBs. It also points out the built-in JMS support in JBoss AS 7 provided by <a href="http://www.jboss.org/hornetq" rel="nofollow">HornetQ</a>. It also covers configuration related to JBoss AS 7's/HornetQ's use of <a href="http://www.jboss.org/netty" rel="nofollow">Netty</a>.</p>
<p>The section of Chapter 3 on configuring transactions introduces the <a href="http://www.oracle.com/technetwork/java/javaee/jta/index.html" rel="nofollow">Java Transaction API</a>. It then explains how to configure the JTA support for timeouts and statistics gathering.</p>
<p><strong>Chapter 4: JBoss Web Server Configuration</strong></p>
<p>The focus of the <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_4" rel="nofollow">fourth chapter</a> of <em>JBoss AS 7: Configuration, Deployment, and Administration</em> is on configuration of the JBoss web server (<a href="http://www.jboss.org/jbossweb" rel="nofollow">JBoss Web</a>), which is based on a fork of <a href="http://tomcat.apache.org/" rel="nofollow">Tomcat 7</a>. The chapter discusses HTTP connectors, including JBoss Web's built-in <a href="http://en.wikipedia.org/wiki/Apache_Tomcat#Coyote" rel="nofollow">Coyote</a> HTTP 1.1 connector and the <a href="http://apr.apache.org/" rel="nofollow">Apache Portable Runtime</a> (<a href="http://docs.jboss.org/jbossweb/3.0.x/apr.html" rel="nofollow">APR</a>) connector. The chapter shows how to separately download and use the ARP connector with JBoss AS 7.</p>
<p>The chapter of JBoss Web server covers configuration of static (HTML/images) and dynamic (JSP) resources and then moves onto discussion of deploying <a href="http://www.oracle.com/technetwork/java/javaee/javaserverfaces-139869.html" rel="nofollow">JavaServer Faces</a> (<a href="http://www.jboss.org/richfaces" rel="nofollow">JSF</a>)-based applications on JBoss AS 7. The author points out: "Currently, JBoss AS 7 supports the JSF release 2.1 using the <a href="http://java.net/projects/mojarra/" rel="nofollow">Mojarra</a> implementation,<br />
although there are plans for supporting <a href="http://myfaces.apache.org/" rel="nofollow">MyFaces</a> implementation too." The chapter then demonstrates using Eclipse to create a JSF project and adding an EJB layer to that application. The chapter also demonstrates adding <a href="http://www.oracle.com/technetwork/articles/marx-jpa-087268.html" rel="nofollow">JPA</a>-based persistence (including how to switch the JPA provider from default <a href="http://www.hibernate.org/" rel="nofollow">Hibernate 4</a>), setting a custom web context, and deploying the web application.</p>
<p><strong>Chapter 5: Configuring a JBoss AS Domain</strong></p>
<p>The <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_5" rel="nofollow">fifth chapter</a> concludes the chapters on configuration by providing a more detailed look at configuring JBoss AS 7 domains. Of particular interest to me is the sections on configuring the JVM and providing JVM options. I also found the author's use of <a href="http://marxsoftware.blogspot.com/2008/08/from-jconsole-to-visualvm.html" rel="nofollow">VisualVM</a> to be helpful. This detailed chapter introduces domain terminology, explains what a domain is, and explains why a domain does not provide the same functionality or purpose as node clustering. It provides thorough detail on configuring domains.</p>
<p><strong>Chapter 6: Deploying Applications on JBoss AS 7</strong></p>
<p>Deployment to JBoss AS 7 is the focus of <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_6" rel="nofollow">Chapter 6</a>. The chapter begins with an introduction to <a href="http://docs.oracle.com/javase/tutorial/deployment/jar/" rel="nofollow">JAR</a>, <a href="http://docs.jboss.org/jbossweb/3.0.x/deployer-howto.html" rel="nofollow">WAR</a>, <a href="http://docs.oracle.com/javaee/5/tutorial/doc/bnaby.html" rel="nofollow">EAR</a>, <a href="http://www.jboss.org/ironjacamar" rel="nofollow">RAR</a>, and <a href="http://www.javabeat.net/tips/117-sar-service-archive-file-in-jboss.html" rel="nofollow">SAR</a> files and then goes onto more detailed (but still thankfully brief) coverage of the first three types of archive files.</p>
<p>After covering JAR, WAR, and EAR, the chapter moves onto coverage of manual and automatic deployments to JBoss AS 7. I was happy to see coverage of using CLI to deploy from the command line, but fans of deploying via web page will be happy to know that there is also coverage of deploying from the web administration console. The chapter also demonstrates deploying from the Eclipse IDE.</p>
<p>The most significant bane of my Java development experience has probably been <a href="https://community.jboss.org/wiki/JBossClassLoaderHistory" rel="nofollow">classloaders</a>, which become tricky when application servers, IDEs, and frameworks like Spring are involved. With this in mind, I was happy to see a section in the sixth chapter called "JBoss AS 7 classloading explained." Several pages are devoted to using JBoss's provided mechanism for appropriately dealing with classes used by the application server as well as the deployed applications. The chapter also talks about using Java EE's standard approach of specifying <code>Class-Path</code> in the <code>MANIFEST.MF</code> file.</p>
<p><strong>Chapter 7: Managing the Application Server</strong></p>
<p>The <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_7" rel="nofollow">seventh chapter</a> focuses on managing JBoss AS 7 via the command line-based CLI tool and the web-based Web admin console. Differentiation is made between CLI commands and CLI operations. I find the sections "Executing CLI scripts in batch" and "Executing scripts in a file" to be particularly interesting from a CLI perspective. The first section talks about CLI support for a group of commands as an atomic unit and the second section talks about writing file-based administration scripts. The book further peaks my interest in CLI by explaining how to take snapshots in CLI and how to display CLI history.</p>
<p>Although I find that I use command line-based tools for configuration, administration, and deployment of an application server in the long-run, web-based or other graphically-oriented tools are often nice when first using an application server or when trying to figure new things out. In other words, I prefer command line scripting for routine tasks and prefer graphically-oriented administrative tools for new or unusual tasks. The second half of Chapter 7 covers using "The new Web admin console."</p>
<p>Chapter 7's coverage of the history of JBoss's web administrative consoles is a good example of how the overall book does a nice job of comparing and contrasting different versions of JBoss tools. The chapter points out the advantages and limitations of the <a href="https://community.jboss.org/wiki/JMXConsole" rel="nofollow">jmx-console</a> approach (versions of JBoss up to JBoss 4.x) and the <a href="http://seamframework.org/" rel="nofollow">Seam</a>-based Web admin console (JBoss 5.x and 6.x) before covering JBoss AS 7's <a href="http://code.google.com/webtoolkit/" rel="nofollow">GWT</a>-based Web admin console. As one would expect, the section on Web admin console is filled with screen snapshots demonstrating the Web admin console in action.</p>
<p><strong>Chapter 8: Clustering</strong></p>
<p>One of the things many of us want from our application server is <a href="https://www.jboss.org/dms/AS7/as7webinar/AS7-clustering-webinar.pdf" rel="nofollow">clustering</a> functionality, which is the theme of <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_8" rel="nofollow">Chapter 8</a> (load balancing of web applications is covered in the next chapter). The chapter points out several facets of clustering that have changed in JBoss AS 7. It also covers how <a href="http://www.jgroups.org/" rel="nofollow">JGroups</a> and <a href="http://www.jboss.org/infinispan" rel="nofollow">Infinispan</a> are used to implement JBoss clustering. This is an information--packed chapter that I will be sure to read again before using JBoss AS 7 clustering.</p>
<p><strong>Chapter 9: Load-balancing Web Applications</strong></p>
<p><a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_9" rel="nofollow">Chapter 9</a> covers load-balancing of web applications. The chapter only briefly covers installation of Tomcat's <a href="http://tomcat.apache.org/connectors-doc/" rel="nofollow">mod_jk</a> and Apache's <a href="http://httpd.apache.org/docs/2.0/mod/mod_proxy.html" rel="nofollow">mod_proxy</a> to connect the Apache web server to JBoss AS 7 because "the installation of either mod_jk or mod_proxy does not differ from earlier AS releases." The remainder of the chapter focused on load balancing covers <a href="http://www.jboss.org/mod_cluster" rel="nofollow">mod_cluster</a> (new to JBoss AS 7). The chapter concludes by returning to discussion of clustering. The author references the <a href="https://docs.jboss.org/author/display/AS71/High+Availability+Guide" rel="nofollow">JBoss AS 7.1 High Availability Guide</a> for continuing developments related to JBoss AS 7's clustering support.</p>
<p><strong>Chapter 10: Securing JBoss AS 7</strong></p>
<p><a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_10" rel="nofollow">Chapter 10</a> of <em>JBoss AS 7: Configuration, Deployment, and Administration</em> is focused on security, an increasingly popular topic. Reading about security is often my best cure for insomnia, but there were some interesting nuggets in this chapter that kept my attention.</p>
<p>The chapter introduces <a href="http://www.jboss.org/picketbox" rel="nofollow">PicketBox</a> (formerly known as <a href="https://community.jboss.org/wiki/PicketBoxOverview#What_is_PicketBox" rel="nofollow">JBoss Security</a>), the security framework upon which JBoss AS 7's security is built. It then provides a basic overview of Java's security API and provide definitions of key security terms in a Java EE context. This thorough chapter covers a wide range of security-related topics as they pertain to JBoss AS 7.</p>
<p><strong>Chapter 11: Taking JBoss AS 7 in the Cloud</strong></p>
<p>The <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#chapter_11" rel="nofollow">final chapter</a> is devoted to the <a href="http://marxsoftware.blogspot.com/2011/12/significant-software-development.html" rel="nofollow">trendiest topic</a> of them all: cloud computing. The central focus of this chapter is <a href="http://www.redhat.com/" rel="nofollow">Red Hat</a>'s <a href="https://openshift.redhat.com/app/" rel="nofollow">OpenShift</a> (<a href="http://en.wikipedia.org/wiki/Platform_as_a_service" rel="nofollow">PaaS</a>). The author does as good a job as I have seen of describing cloud computing and I particularly liked the contrasting of cloud computing to grid computing. The majority of the chapter discusses starting with <a href="https://openshift.redhat.com/app/express" rel="nofollow">OpenShift Express</a> and then transitioning to <a href="https://openshift.redhat.com/app/flex" rel="nofollow">OpenShift Flex</a>.</p>
<p><strong>Appendix</strong></p>
<p>The Appendix is six pages of "common commands and operations" that provides an easy access reference. Although the shown commands use Linux script <code>jboss-admin.sh</code>, the alternative for Windows (<code>jboss-admin.bat</code>) is shown at the beginning of the appendix. The subsections of the appendix are Startup Options, General Commands, Domain Mode, JMS, Data sources, mod_cluster, Batch, and Snapshots.</p>
<p><strong>Conclusion</strong></p>
<p><a href="https://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book" rel="nofollow">JBoss AS 7: Configuration, Deployment, and Administration</a> delivers what it's title promises: an introduction and in-depth coverage of configuring and administrating and deploying to JBoss AS 7. Along the way, the book manages to provide differences in JBoss AS 7 from previous versions and to provide introductory details about aspects of Java EE supported in JBoss AS 7. This is not the book one would learn how to write JavaServer Pages, JavaServer Faces applications, EJBs, or other Java EE code from. However, it is the book one would learn how to deploy a Java EE application to JBoss AS 7 and how to maintain and configure JBoss AS 7 to most efficiently support Java EE applications.</p>
<p><strong>Other Reviews</strong></p>
<p>Other reviews of <a href="https://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book" rel="nofollow">JBoss AS 7: Configuration, Deployment, and Administration</a> are available. These include <a href="https://plus.google.com/100362024804331957185/about" rel="nofollow">Markus Eisele</a>'s <a href="http://blog.eisele.net/2012/01/review-jboss-as7-configuration.html" rel="nofollow">Review: "JBoss AS7 Configuration, Deployment and Administration" by Francesco Marchioni</a>, <a href="http://rickwagner.blogspot.com/" rel="nofollow">Rick Wagner</a>'s <a href="http://rickwagner.blogspot.com/2011/11/book-review-for-jboss-as-7.html" rel="nofollow">Book Review for "JBoss AS 7 Configuration Deployment and Administration"</a> (unfinished version of the book), <a href="http://maksim.sorokin.dk/it/about/" rel="nofollow">Maksim Sorokin</a>'s <a href="http://maksim.sorokin.dk/it/2012/01/06/packt-jboss-as-7-configuration-deployment-and-administration/" rel="nofollow">[PACKT] JBoss AS 7 Configuration, Deployment and Administration</a> (announcing review coming), and <a href="http://www.blogger.com/profile/02280824131541047038" rel="nofollow">David Salter</a>'s <a href="http://www.davidsalter.com/2012/01/forthcoming-book-review.html" rel="nofollow">Forthcoming Book Review</a> (announcing review coming).</p>
<p>Original posting available at <a href="http://marxsoftware.blogspot.com/" rel="nofollow">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p>
    ]]></content>
  </entry>
  <entry>
    <title>JavaFX 2 Presents the Quadratic Formula</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8304" />
    <id>http://www.javaworld.com/community/node/8304</id>
    <published>2012-01-30T09:58:00-05:00</published>
    <updated>2012-01-30T11:00:31-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><p>I recently needed to check some homework answers related to use of the <a href="http://www.purplemath.com/modules/quadform.htm" rel="nofollow" rel="nofollow">quadratic formula</a>. After realizing that it was getting tedious to do these by hand, I thought of using my <a href="http://en.wikipedia.org/wiki/HP-48_series" rel="nofollow" rel="nofollow">calculator</a> to solve them. However, I realized that I could write a simple application using <a href="http://javafx.com/" rel="nofollow" rel="nofollow">JavaFX</a> to calculate the results and that approach seemed more interesting than using the calculator.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>I recently needed to check some homework answers related to use of the <a href="http://www.purplemath.com/modules/quadform.htm" rel="nofollow">quadratic formula</a>. After realizing that it was getting tedious to do these by hand, I thought of using my <a href="http://en.wikipedia.org/wiki/HP-48_series" rel="nofollow">calculator</a> to solve them. However, I realized that I could write a simple application using <a href="http://javafx.com/" rel="nofollow">JavaFX</a> to calculate the results and that approach seemed more interesting than using the calculator. This post demonstrates that simple application and provides the relatively straightforward code required to make it happen.</p>
<p>The next couple of screen snapshots demonstrate the simple application in example. They include the initial appearance of the application followed by a couple images showing different values calculated by the application.</p>
<p><a href="http://3.bp.blogspot.com/-W5tOqQ1Rfho/TyTJh7IJPmI/AAAAAAAAC-k/3MvnFG3Imgg/s1600/javaFxQuadraticFormulaInitialStartup.png" imageanchor="1" rel="nofollow"></a></p>
<p><a href="http://1.bp.blogspot.com/-AvalxUb6YUU/TyTKT1wXcHI/AAAAAAAAC-w/5tYjhpYKXvo/s1600/javaFxQuadraticFormula5and5.png" imageanchor="1" rel="nofollow"></a></p>
<p><a href="http://1.bp.blogspot.com/-CTvg0vr-B80/TyTKYwSHpQI/AAAAAAAAC-8/xDkImgBMIZE/s1600/javaFxQuadraticFormula5and10.png" imageanchor="1" rel="nofollow"></a></p>
<p><a href="http://3.bp.blogspot.com/-YPWRu-xSSM0/TyTKbgzyHYI/AAAAAAAAC_I/YOn_cE9tk3s/s1600/javaFxQuadraticFormulaInvalid.png" imageanchor="1" rel="nofollow"></a></p>
<p>The last screen snapshot shows the output when one of the coefficients provided does not allow the quadratic formula to be applied. To provide this application slightly broader application than solely quadratic equation solving, I have added code to detect when the 'a' coefficient is zero and the 'b' coefficient is non-zero. This is a linear equation and the simple application solves it as well as the quadratic equations provided. The next screen snapshot demonstrates the output when coefficients for a linear equation are provided.</p>
<p><a href="http://2.bp.blogspot.com/-SEaAv0CxyZA/TyW25mysPWI/AAAAAAAAC_U/UD_vXjaLC3w/s1600/javaFxQuadraticFormulaLinearEquationExample.png" imageanchor="1" rel="nofollow"></a></p>
<p>The first code listing has nothing to do with the JavaFX presentation layer, but is instead a simple call that provides the basic back-end quadratic formula calculations. I include it here because it is use by the JavaFX example application. It is somewhat interesting in its own right because there are so many ways to calculate a square root in Java. The best-known approach is to use <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#sqrt(double)" rel="nofollow">Math.sqrt(double)</a>, but the <a href="http://stackoverflow.com/questions/1384919/are-there-libraries-for-square-root-over-bigdecimal" rel="nofollow">choices are often more varied</a> when using <a href="http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html" rel="nofollow">BigDecimal</a> instead of <code>double</code>. Because the purpose of my post is to focus on the JavaFX aspect of this and because my chosen approach is accurate enough for its purposes, I've taken the "easy way" out here and simply use <code>Math.sqrt(double)</code>.</p>
<p><strong>SimplisticQuadraticFormula.java</strong></p>
<p>package dustin.examples;</p>
<p>import java.math.BigDecimal;<br />
import java.math.MathContext;<br />
import java.math.RoundingMode;<br />
import java.util.ArrayList;<br />
import java.util.List;</p>
<p>/**<br />
 * Class encapsulating quadratic formula implementation.<br />
 *<br />
 * @author Dustin<br />
 */<br />
public class SimplisticQuadraticFormula<br />
{<br />
   /** Default precision used for specifying scale. */<br />
   private static final int DEFAULT_PRECISION = MathContext.DECIMAL64.getPrecision();</p>
<p>   /** Convenient representation of zero as BigDecimal. */<br />
   private static final BigDecimal ZERO = new BigDecimal("0");</p>
<p>   /** Convenient representation of two as BigDecimal. */<br />
   private static final BigDecimal TWO = new BigDecimal("2");</p>
<p>   /** Convenient representation of four as BigDecimal. */<br />
   private static final BigDecimal FOUR = new BigDecimal("4");</p>
<p>   /**<br />
    * Calculate intercepts with x-axis.<br />
    *<br />
    * @param a Coefficient 'a' from a quadratic equation to be solved.<br />
    * @param b Coefficient 'b' from a quadratic equation to be solved.<br />
    * @param c Coefficient 'c' from a quadratic equation to be solved.<br />
    * @return The x-intercepts or solutions to the quadratic equation (two values)<br />
    *     or a single value if solution to a linear equation. Note that two<br />
    *     solutions are always provided for quadratic equations even if they are<br />
    *     the same.<br />
    * @throws NumberFormatException Thrown when x-intercepts cannot be calculated.<br />
    */<br />
   public static List&lt;BigDecimal&gt; calculateXIntercepts(<br />
      final BigDecimal a, final BigDecimal b, final BigDecimal c)<br />
   {<br />
      final List&lt;BigDecimal&gt; intercepts = new ArrayList&lt;BigDecimal&gt;();<br />
      if (a.compareTo(ZERO) == 0 &amp;&amp; b.compareTo(ZERO) == 0)<br />
      {<br />
         // neither quadratic nor linear<br />
         throw new NumberFormatException("Must have coefficient for one of x terms.");<br />
      }<br />
      else if (a.compareTo(ZERO) == 0)  // linear equation<br />
      {<br />
         intercepts.add(c.setScale(DEFAULT_PRECISION).negate().divide(b, RoundingMode.HALF_UP));<br />
      }<br />
      else<br />
      {<br />
         final BigDecimal intercept1 =<br />
            calculateNumeratorWithAddition(a, b, c)<br />
               .divide(calculateDenominator(a), RoundingMode.HALF_UP);<br />
         intercepts.add(intercept1);<br />
         final BigDecimal intercept2 =<br />
            calculateNumeratorWithSubtraction(a, b, c)<br />
               .divide(calculateDenominator(a), RoundingMode.HALF_DOWN);<br />
         intercepts.add(intercept2);<br />
      }<br />
      return intercepts;<br />
   }</p>
<p>   /**<br />
    * Calculate axis of symmetry, if applicable.<br />
    *<br />
    * @param a Coefficient 'a' from a quadratic equation to be solved.<br />
    * @param b Coefficient 'b' from a quadratic equation to be solved.<br />
    * @return The "x" axis of symmetry.<br />
    * @throws NumberFormatException Thrown if the provided 'a' coefficient is<br />
    *    zero because cannot divide by zero.<br />
    */<br />
   public static BigDecimal calculateAxisOfSymmetry(final BigDecimal a, final BigDecimal b)<br />
   {<br />
      if (a.compareTo(ZERO) == 0)<br />
      {<br />
         throw new NumberFormatException(<br />
            "Cannot calculate axis of symmetry based on x-intercepts when a is zero.");<br />
      }<br />
      return b.setScale(DEFAULT_PRECISION).negate().divide(a.multiply(TWO), RoundingMode.HALF_UP);<br />
   }</p>
<p>   /**<br />
    * Calculate numerator of quadratic formula where the terms are added.<br />
    *<br />
    * @param a Coefficient 'a' from a quadratic equation to be solved.<br />
    * @param b Coefficient 'b' from a quadratic equation to be solved.<br />
    * @param c Coefficient 'c' from a quadratic equation to be solved.<br />
    * @return Value of numerator in quadratic formula where terms are added.<br />
    * @throws NumberFormatException Thrown if no real solution is available.<br />
    */<br />
   private static BigDecimal calculateNumeratorWithAddition(<br />
      final BigDecimal a, final BigDecimal b, final BigDecimal c)<br />
   {<br />
      return b.negate().add(calculateSquareRootPortion(a, b, c));<br />
   }</p>
<p>   /**<br />
    * Calculate numerator of quadratic formula where the terms are subtracted.<br />
    *<br />
    * @param a Coefficient 'a' from a quadratic equation to be solved.<br />
    * @param b Coefficient 'b' from a quadratic equation to be solved.<br />
    * @param c Coefficient 'c' from a quadratic equation to be solved.<br />
    * @return Value of numerator in quadratic formula where terms are subtracted.<br />
    * @throws NumberFormatException Thrown if no real solution is available.<br />
    */<br />
   private static BigDecimal calculateNumeratorWithSubtraction(<br />
      final BigDecimal a, final BigDecimal b, final BigDecimal c)<br />
   {<br />
      return b.negate().subtract(calculateSquareRootPortion(a, b, c));<br />
   }</p>
<p>   /**<br />
    * Calculate denominator of quadratic formula.<br />
    *<br />
    * @param a Coefficient of 'a' from a quadratic equation to be solved.<br />
    * @return Value of denominator in quadratic formula.<br />
    * @throws NumberFormatException Thrown in 0 is provided for coefficient 'a'<br />
    *    because denominator cannot be zero.<br />
    */<br />
   private static BigDecimal calculateDenominator(final BigDecimal a)<br />
   {<br />
      if (a.compareTo(ZERO) == 0)<br />
      {<br />
         throw new NumberFormatException("Denominator cannot be zero.");<br />
      }<br />
      return a.multiply(TWO);<br />
   }</p>
<p>   /**<br />
    * Calculates value of square root portion of quadratic formula.<br />
    *<br />
    * @param a Coefficient 'a' from a quadratic equation to be solved.<br />
    * @param b Coefficient 'b' from a quadratic equation to be solved.<br />
    * @param c Coefficient 'c' from a quadratic equation to be solved.<br />
    * @return The square root portion of the quadratic formula applied with<br />
    *    the three provided co-efficients.<br />
    * @throws NumberFormatException Thrown if there is no solution (no<br />
    *    intersection of the x-axis) or if a number is encountered that cannot<br />
    *    be handled with BigDecmal return type.<br />
    */<br />
   private static BigDecimal calculateSquareRootPortion(<br />
      final BigDecimal a, final BigDecimal b, final BigDecimal c)<br />
   {<br />
      BigDecimal sqrt;<br />
      final BigDecimal subtrahend = a.multiply(c).multiply(FOUR);<br />
      final BigDecimal insideSqrt = b.pow(2).subtract(subtrahend);<br />
      if (insideSqrt.compareTo(ZERO) &lt; 0)<br />
      {<br />
         throw new NumberFormatException("Cannot be solved: no x-intercepts.");<br />
      }<br />
      else<br />
      {<br />
         final double value = insideSqrt.doubleValue();<br />
         final double sqrtDouble = Math.sqrt(value);<br />
         sqrt = new BigDecimal(sqrtDouble);  // may throw NumberFormatException<br />
      }<br />
      return sqrt;<br />
   }<br />
}</p>
<p>With the calculations portion in place, it is time to move to the focus of this post (the presentation via JavaFX 2). The following code listing provides the JavaFX 2 class (written in pure Java) used for the application. Note that much of this presentation layer code could have been written using <a href="http://docs.oracle.com/javafx/2.0/fxml_get_started/jfxpub-fxml_get_started.htm" rel="nofollow">FXML</a>.</p>
<p><strong>QuadraticCalculator.java</strong></p>
<p>package dustin.examples;</p>
<p>import java.math.BigDecimal;<br />
import java.util.List;<br />
import javafx.application.Application;<br />
import javafx.event.ActionEvent;<br />
import javafx.event.EventHandler;<br />
import javafx.geometry.Pos;<br />
import javafx.scene.Group;<br />
import javafx.scene.Scene;<br />
import javafx.scene.control.Button;<br />
import javafx.scene.control.Label;<br />
import javafx.scene.control.TextField;<br />
import javafx.scene.control.TextFieldBuilder;<br />
import javafx.scene.image.Image;<br />
import javafx.scene.image.ImageView;<br />
import javafx.scene.layout.HBox;<br />
import javafx.scene.layout.VBox;<br />
import javafx.scene.paint.Color;<br />
import javafx.stage.Stage;</p>
<p>/**<br />
 * JavaFX-based application for solving quadratic equations.<br />
 *<br />
 * @author Dustin<br />
 */<br />
public class QuadraticCalculator extends Application<br />
{<br />
   /** Coefficient A used in quadratic formula. */<br />
   private TextField coefficientA =<br />
      TextFieldBuilder.create().promptText("Enter Coefficient A").build();</p>
<p>   /** Coeffecient B used in quadratic forumal. */<br />
   private TextField coefficientB =<br />
      TextFieldBuilder.create().promptText("Enter Coefficient B").build();</p>
<p>   /** Coeffecient C (constant) used in quadratic formula. */<br />
   private TextField coefficientC =<br />
      TextFieldBuilder.create().promptText("Enter Coefficient C").build();</p>
<p>   /** First x-intercept. */<br />
   private TextField xIntercept1 =<br />
      TextFieldBuilder.create().disable(true).editable(false).build();</p>
<p>   /** Second x-intercept. */<br />
   private TextField xIntercept2 =<br />
      TextFieldBuilder.create().disable(true).editable(false).build();</p>
<p>   /** Axis of symmetry. */<br />
   private TextField symmetryAxis =<br />
      TextFieldBuilder.create().disable(true).editable(false).build();</p>
<p>   /**<br />
    * Extract Image with provided name.<br />
    *<br />
    * @param imageName Name of image to be provided.<br />
    * @return Loaded image.<br />
    */<br />
   private Image getImage(final String imageName)<br />
   {<br />
      final String jarFileUrl =<br />
         this.getClass().getProtectionDomain().getCodeSource().getLocation().toString();<br />
      final String url = "jar:" + jarFileUrl + "!/" + imageName;<br />
      System.out.println(url);<br />
      return new Image(url, true);<br />
   }</p>
<p>   /**<br />
    * Provide a read-only horizontal box with quadratic equation and quadratic<br />
    * formula and with a button that can be clicked to calculate solution to<br />
    * quadration equation with provided coefficients.<br />
    *<br />
    * @return Horizontal box with quadratic equation and quadratic formula.<br />
    */<br />
   private HBox buildEquationsBox()<br />
   {<br />
      final HBox equationsBox = new HBox();<br />
      equationsBox.setAlignment(Pos.CENTER);<br />
      equationsBox.setSpacing(50);<br />
      final Image quadraticEquation = getImage("quadraticEquation-transparent.png");<br />
      final ImageView equationView = new ImageView(quadraticEquation);<br />
      equationsBox.getChildren().add(equationView);<br />
      final Image quadraticFormula = getImage("quadraticFormula-transparent.png");<br />
      final ImageView formulaView = new ImageView(quadraticFormula);<br />
      equationsBox.getChildren().add(formulaView);<br />
      final Button calculateButton = new Button("Calculate");<br />
      calculateButton.setOnAction(<br />
         new EventHandler&lt;ActionEvent&gt;()<br />
         {<br />
            public void handle(ActionEvent t)<br />
            {<br />
               final BigDecimal a = extractBigDecimal(coefficientA.getText());<br />
               final BigDecimal b = extractBigDecimal(coefficientB.getText());<br />
               final BigDecimal c = extractBigDecimal(coefficientC.getText());<br />
               try<br />
               {<br />
                  final List&lt;BigDecimal&gt; intercepts =<br />
                     SimplisticQuadraticFormula.calculateXIntercepts(a, b, c);<br />
                  xIntercept1.setText(intercepts.get(0).toPlainString());<br />
                  xIntercept1.setDisable(false);<br />
                  if (intercepts.size() &gt; 1)<br />
                  {<br />
                     xIntercept2.setText(intercepts.get(1).toEngineeringString());<br />
                     xIntercept2.setDisable(false);<br />
                  }<br />
                  else<br />
                  {<br />
                     xIntercept2.setText("-");<br />
                     xIntercept2.setDisable(true);<br />
                  }<br />
                  if (a.compareTo(new BigDecimal("0")) != 0)<br />
                  {<br />
                     final BigDecimal axis =<br />
                        SimplisticQuadraticFormula.calculateAxisOfSymmetry(a, b);<br />
                     symmetryAxis.setText(axis.toPlainString());<br />
                     symmetryAxis.setDisable(false);<br />
                  }<br />
                  else<br />
                  {<br />
                     symmetryAxis.setText("-");<br />
                     symmetryAxis.setDisable(true);<br />
                  }<br />
               }<br />
               catch (NumberFormatException nfe)<br />
               {<br />
                  xIntercept1.setText("-");<br />
                  xIntercept1.setDisable(true);<br />
                  xIntercept2.setText("-");<br />
                  xIntercept2.setDisable(true);<br />
                  symmetryAxis.setText("-");<br />
                  symmetryAxis.setDisable(true);<br />
               }<br />
            }<br />
         });<br />
      equationsBox.getChildren().add(calculateButton);<br />
      return equationsBox;<br />
   }</p>
<p>   /**<br />
    * Converts provided String to BigDecimal.<br />
    *<br />
    * @param possibleNumber String to be converted to an instance of BigDecimal.<br />
    * @return The BigDecimal corresponding to the provided String or Double.NaN<br />
    *     if the conversion cannot be performed.<br />
    */<br />
   private BigDecimal extractBigDecimal(final String possibleNumber)<br />
   {<br />
      BigDecimal extractedNumber;<br />
      try<br />
      {<br />
         extractedNumber = new BigDecimal(possibleNumber);<br />
      }<br />
      catch (NumberFormatException nfe)<br />
      {<br />
         extractedNumber = null;<br />
      }<br />
      return extractedNumber;<br />
   }</p>
<p>   /**<br />
    * Provide horizontal box with labels of coefficients and fields to enter<br />
    * coefficient values.<br />
    *<br />
    * @return Horizontal box for entering coefficients.<br />
    */<br />
   private HBox buildEntryBox()<br />
   {<br />
      final HBox entryBox = new HBox();<br />
      entryBox.setSpacing(10);<br />
      final Label aCoeff = new Label("a = ");<br />
      entryBox.getChildren().add(aCoeff);<br />
      entryBox.getChildren().add(this.coefficientA);<br />
      final Label bCoeff = new Label("b = ");<br />
      entryBox.getChildren().add(bCoeff);<br />
      entryBox.getChildren().add(this.coefficientB);<br />
      final Label cCoeff = new Label("c = ");<br />
      entryBox.getChildren().add(cCoeff);<br />
      entryBox.getChildren().add(this.coefficientC);<br />
      return entryBox;<br />
   }</p>
<p>   /**<br />
    * Construct the output box with solutions based on quadratic formula.<br />
    *<br />
    * @return Output box with solutions of applying quadratic formula given<br />
    *    provided input coefficients.<br />
    */<br />
   private HBox buildOutputBox()<br />
   {<br />
      final HBox outputBox = new HBox();<br />
      outputBox.setSpacing(10);<br />
      final Label x1 = new Label("x1 = ");<br />
      outputBox.getChildren().add(x1);<br />
      outputBox.getChildren().add(this.xIntercept1);<br />
      final Label x2 = new Label("x2 = ");<br />
      outputBox.getChildren().add(x2);<br />
      outputBox.getChildren().add(this.xIntercept2);<br />
      final Label axis = new Label("axis = ");<br />
      outputBox.getChildren().add(axis);<br />
      outputBox.getChildren().add(this.symmetryAxis);<br />
      return outputBox;<br />
   }</p>
<p>   /**<br />
    * Build overall presentation of application.<br />
    *<br />
    * @return Vertical box representing input and output of application.<br />
    */<br />
   private VBox buildOverallVerticalLayout()<br />
   {<br />
      final VBox vbox = new VBox();<br />
      vbox.setSpacing(25);<br />
      vbox.getChildren().add(buildEquationsBox());<br />
      vbox.getChildren().add(buildEntryBox());<br />
      vbox.getChildren().add(buildOutputBox());<br />
      vbox.setAlignment(Pos.CENTER);<br />
      return vbox;<br />
   }</p>
<p>   /**<br />
    * Start the JavaFX application for solving quadratic equations.<br />
    *<br />
    * @param stage Primary stage.<br />
    * @throws Exception JavaFX-related exception.<br />
    */<br />
   @Override<br />
   public void start(final Stage stage) throws Exception<br />
   {<br />
      final Group groupRoot = new Group();<br />
      groupRoot.getChildren().add(buildOverallVerticalLayout());<br />
      final Scene scene = new Scene(groupRoot, 600, 150, Color.LIGHTGRAY);<br />
      stage.setTitle("Quadratic Formula: JavaFX Style");<br />
      stage.setScene(scene);<br />
      stage.show();<br />
   }</p>
<p>   /**<br />
    * Main function for running the JavaFX-based quadratic equation solver.<br />
    *<br />
    * @param arguments<br />
    */<br />
   public static void main(final String[] arguments)<br />
   {<br />
      Application.launch(arguments);<br />
   }<br />
}</p>
<p>The JavaFX 2 code above loads two images with <a href="http://marxsoftware.blogspot.com/2011/04/making-white-image-backgrounds.html" rel="nofollow">transparent backgrounds</a> to display the standard form of a quadratic equation and to display the quadratic formula. In a previous post, I loaded these images from an external URL, but I loaded them from the application's JAR in this example. These images are shown next independent of the application.</p>
<p><strong>quadraticEquation-transparent.png</strong></p>
<p><a href="http://4.bp.blogspot.com/-WRHK8oEkTrs/TyW9oW0zZ7I/AAAAAAAAC_g/IkkUpnjGM6U/s1600/quadraticEquation-transparent.png" imageanchor="1" rel="nofollow"></a></p>
<p><strong>quadraticFormula-transparent.png</strong></p>
<p><a href="http://1.bp.blogspot.com/-bLGYh7p_yUc/TyW99YfcESI/AAAAAAAAC_s/Ld0oGuY2Znc/s1600/quadraticFormula-transparent.png" imageanchor="1" rel="nofollow"></a></p>
<p>There are several ways this simplistic application could be improved. One improvement would be to make sizes adjustable and bound to one another so the window could be dragged larger or smaller and still look good. Another improvement would be to provide some type of status message on the interface, especially for situations where solutions could not be calculated. A third improvement that would be to present a graph of the quadratic equation specified with the provided coefficients to visually indicate the x-intercepts and axis of symmetry.</p>
<p>JavaFX 2 makes it fairly straight-forward to write simple, user-friendly applications.</p>
<p>Original posting available at <a href="http://marxsoftware.blogspot.com/" rel="nofollow">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p>
    ]]></content>
  </entry>
  <entry>
    <title>JavaFX 2.1: JavaFX 2&#039;s @DefaultProperty Annotation</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8301" />
    <id>http://www.javaworld.com/community/node/8301</id>
    <published>2012-01-27T01:56:00-05:00</published>
    <updated>2012-01-27T02:00:16-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><p>The <a href="http://java.dzone.com/articles/focus-javafx-2-fxml-netbeans" rel="nofollow" rel="nofollow">JavaLobby/DZone syndicated version</a> of my blog post <a href="http://marxsoftware.blogspot.com/2012/01/focus-on-javafx-2-fxml-with-netbeans-71.html" rel="nofollow" rel="nofollow">Focus on JavaFX 2 FXML with NetBeans 7.1</a> was recently published and <a href="http://java.dzone.com/users/md54345" rel="nofollow" rel="nofollow">Mihai Dinca-panaitescu</a> (author of DZone article <a href="http://java.dzone.com/articles/tuning-your-java-vm" rel="nofollow" rel="nofollow">Tuning Your Java VM</a>) added an interesting and useful feedback comment.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>The <a href="http://java.dzone.com/articles/focus-javafx-2-fxml-netbeans" rel="nofollow">JavaLobby/DZone syndicated version</a> of my blog post <a href="http://marxsoftware.blogspot.com/2012/01/focus-on-javafx-2-fxml-with-netbeans-71.html" rel="nofollow">Focus on JavaFX 2 FXML with NetBeans 7.1</a> was recently published and <a href="http://java.dzone.com/users/md54345" rel="nofollow">Mihai Dinca-panaitescu</a> (author of DZone article <a href="http://java.dzone.com/articles/tuning-your-java-vm" rel="nofollow">Tuning Your Java VM</a>) added an interesting and useful feedback comment. Specifically, he stated:<br />
I needed to put <code>&amp;lt;children&amp;gt;</code> tag in JavaFx2Menus.fxml</p>
<p />
before MenuBar tag.</p>
<p />
otherwise an Exception is raised:</p>
<p />
javafx.fxml.LoadException: javafx.scene.layout.VBox does not have a default property.</p>
<p>I'm glad that Mihai posted this response for several reasons. First, it will help anyone else reading my post to be aware of that issue. Second, it has allowed me to speculate on the cause of this message in this blog post.</p>
<p>My first thought at reading Mihai's comment was that perhaps the difference was that I was using JavaFX 2.1 (still beta) when I ran the example and perhaps Mihai was using production-ready JavaFX 2.0. Assuming this is the case, the next question was, "What changed in JavaFX 2.1 to make this example work without the <code>children</code> element? Feeling that I need to balance out recent cogitations on my blog with rampant speculation, I decided to do some of that speculation in this post. I speculate that JavaFX 2.1 has applied <a href="http://docs.oracle.com/javafx/2.0/api/javafx/beans/DefaultProperty.html" rel="nofollow">@DefaultProperty</a> to more controls than in JavaFX 2.0 and that <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/layout/VBox.html" rel="nofollow">VBox</a> was one of these which now has it applied.</p>
<p>The Javadoc <a href="http://docs.oracle.com/javafx/2.0/api/javafx/beans/DefaultProperty.html" rel="nofollow">description of the DefaultProperty annotation</a> states, "Specifies a property to which child elements will be added or set when an explicit property is not given." The "<a href="http://docs.oracle.com/javafx/2.0/api/javafx/fxml/doc-files/introduction_to_fxml.html#default_properties" rel="nofollow">Default Properties</a>" section of the highly useful <a href="http://fxexperience.com/wp-content/uploads/2011/08/Introducing-FXML.pdf" rel="nofollow">Introducing FXML</a> adds:</p>
<p>A class may define a "default property" using the <code>@DefaultProperty</code> annotation defined in the <code>javafx.fxml</code> package. If present, the sub-element representing the default property can be omitted from the markup.</p>
<p />For example, if the <code>Group</code> class were to define a default property of "children", the <code>&amp;lt;children&amp;gt;</code> element would no longer be required.</p>
<p>My speculation was that JavaFX 2.1 had added <code>@DefaultProperty</code> annotation to the <code>VBox</code> (among others) control. Although the Javadoc for JavaFX 2.1's <code>VBox</code> does not show this annotation applied, the JavaFX 2.1 Javadoc documentation for its parent class, <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/layout/Pane.html" rel="nofollow">Pane</a>, does indicate the presence of the annotation (and the <code>@DefaultProperty</code> annotation is itself marked <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Inherited.html" rel="nofollow">@Inherited</a>). The next image shows <code>Pane</code> JavaFX 2.0 and JavaFX 2.1 Javadoc versions side-by-side.</p>
<p><a href="http://4.bp.blogspot.com/-er6W6BDQX7w/TyJI2lIdMYI/AAAAAAAAC-Y/Tkc1gv3H6fI/s1600/comparingPaneJavadocJavaFx20JavaFx21AnnotationCircled.png" imageanchor="1" rel="nofollow"></a></p>
<p>The circled portion of the JavaFX 2.1 API documentation for <code>Pane</code> shows that this control (and controls inheriting from it such as <code>VBox</code>) have <code>children</code> as the component's default property. This explains why <code>children</code> must be explicitly specified in JavaFX 2.0, but is optional for <code>VBox</code> in JavaFX 2.1.</p>
<p>The <code>@DefaultProperty</code> annotation has also been applied to the MenuBar control in JavaFX 2.1. Comparing Javadoc for <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/MenuBar.html" rel="nofollow">MenuBar in JavaFX 2.0</a> to the Javadoc for MenuBar in 2.1 proves this. The next screen snapshot shows them side-by-side.</p>
<p><a href="http://2.bp.blogspot.com/-i0nXz6WYg70/TyI7Zv-XOvI/AAAAAAAAC-M/_vD6zZ--IOY/s1600/comparingJavaFx20ToJavaFx21MenuBarJavadocCircledAnnotation.png" imageanchor="1" rel="nofollow"></a></p>
<p>The circled portion of the JavaFX 2.1 API documentation shows that an annotation has been added in JavaFX 2.1 to the <code>MenuBar</code> class to specify that the default sub-element for <code>MenuBar</code> is now "menus" in JavaFX 2.1. Incidentally, <code>Menu</code> also has a new <code>@DefaultProperty</code> with "items" as its default property. With the <code>@DefaultProperty</code> annotation of <code>MenuBar</code>, I decided to try removing the <code>&amp;lt;menus&amp;gt;</code> elements from my FXML and this appeared to work fine, removing a couple lines of XML from my source FXML and allowing many lines to be less indented. It worked and I had a little more concise of an FXML representation of the same menus application layout.</p>
<p>The more widespread use of the <code>@DefaultProperty</code> annotation is a small, but very welcome addition to JavaFX 2.1. Although adding opening and closing "children" tags adds only two lines per use, it does increase the indentation as well for a well-formatted FXML file. FXML can be appealing because of its visual similarity to the presentation itself and having fewer "extra" lines for common cases can make it even more readable. Although the <code>@DefaultProperty</code> annotation itself was available in JavaFX 2.0, it's much more widely applied and can be more widely used in FXML when using JavaFX 2.1.</p>
<p>Original posting available at <a href="http://marxsoftware.blogspot.com/" rel="nofollow">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p>
    ]]></content>
  </entry>
  <entry>
    <title>Recent Java-Related Posts Worthy of Special Notice</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8298" />
    <id>http://www.javaworld.com/community/node/8298</id>
    <published>2012-01-23T09:59:00-05:00</published>
    <updated>2012-01-23T10:00:19-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p>In this blog post, I reference and summarize recent Java-related posts that I have found to be particularly interesting and well worth the time spent reading them.</p>    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>In this blog post, I reference and summarize recent Java-related posts that I have found to be particularly interesting and well worth the time spent reading them.</p>

<strong style="font-size: 125%;">JDK 8 and Unsigned Integer Arithmetic</strong>

<p><a href="http://blogs.oracle.com/darcy/">Joe Darcy</a>'s post <a href="http://blogs.oracle.com/darcy/entry/unsigned_api">Unsigned Integer Arithmetic API now in JDK 8</a> states that "initial API support for unsigned integer arithmetic" has been pushed into <a href="http://openjdk.java.net/projects/jdk8/">Java 8</a>. Darcy explains that this is implemented largely via static methods on classes <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html">java.lang.Integer</a> and <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html">java.lang.Long</a>.</p>

<p>Although Darcy's post is not very long, he manages to talk about the specific unsigned arithmetic functionality that is supported (conversion of Strings to unsigned integers, conversion of unsigned integers to Strings, comparing unsigned values, and calculation of unsigned division and remainder) as well as why it was decided to not implement new types such as <code>UnsignedInt</code>. A consequence of not implementing specific unsigned types is that it is easier to inadvertently mix signed and unsigned values and Darcy suggests some ideas built on naming conventions or new built-in annotations to address this concern.</p>


<strong style="font-size: 125%;">Versions, Code Names, and Features of Java Releases</strong>

<p>Speaking of new versions of Java, another Joe (<a href="http://javapapers.com/about-me/">Joseph Kulandai</a>) started 2012 off with a nice post on <a href="http://javapapers.com/core-java/java-features-and-history/">Java Versions, Features and History</a>. In this post, Kulandai lists the versions of Java in backwards chronological order (Java SE 7 listed first and JDK Version 1.0 at the bottom of the post). Under each major version of Java, Kulandai provides bullet lists of new features in that release and provides the <a href="http://javachamp.blogspot.com/2008/07/java-code-names_04.html">code name</a> of each release.</p>


<strong style="font-size: 125%;">Java 8 Status Updates</strong>

<p>Continuing the theme of Java 8 updates, another post of interest is <a href="http://jthoenes.bergischweb.de/">Johannes Thönes</a>'s <a href="http://jthoenes.bergischweb.de/2011/12/23/java-8-status-updates/">Java 8 Status Updates</a>. This post looks at the status of "the two big new language features of the upcoming Java SE 8" (<a href="http://openjdk.java.net/projects/lambda/">Project Lambda</a> and <a href="http://openjdk.java.net/projects/jigsaw/">Project Jigsaw</a>).</p>


<strong style="font-size: 125%;">Java 7 Concurrency</strong>

<p><a href="http://www.blogger.com/profile/12402045792243894660">Niklas Schlimm</a> has written two recent posts on using Java 7 concurrency features. He introduces "a flexible thread synchronization mechanism called <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Phaser.html">Phaser</a>" in the post <a href="http://niklasschlimm.blogspot.com/2011/12/java-7-understanding-phaser.html">Java 7: Understanding the Phaser</a> and looks in detail at <a href="http://marxsoftware.blogspot.com/2011/12/java-7s-threadlocalrandom.html">ThreadLocalRandom</a> in the post <a href="http://niklasschlimm.blogspot.com/2012/01/java-7-how-to-write-really-fast-java.html">Java 7: How to write really fast Java code</a>.</p>


<strong style="font-size: 125%;">OutOfMemoryError: Using Command-line Tools</strong>

<p><a href="http://forum.plumbr.eu/template/NamlServlet.jtp?macro=user_nodes&amp;user=241253">Vladimir Šor</a>'s <a href="http://plumbr.eu/blog/solving-outofmemoryerror-jdk-tools">Solving OutOfMemoryError (part 5) - JDK Tools</a> is, as its title suggests, the fifth in a series on Java memory issues available on <a href="http://plumbr.eu/blog">that blog</a> ("Solving OutOfMemoryError blog post series"). This post provides a brief summary description and usage information for three <a href="http://docs.oracle.com/javase/7/docs/webnotes/tsg/other/tools-Windows.html">command-line tools</a> bundled with the Oracle Java SDK (<a href="http://marxsoftware.blogspot.com/2008/01/jps-java-virtual-machine-process-status.html">jps</a>, <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.html">jmap</a>, and <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/share/jhat.html">jhat</a>).</p>

<p>The previous entries in this series are written by Nikita Salnikov-Tarnovski: <a href="http://plumbr.eu/blog/solving-outofmemoryerror-story-of-a-developer">Solving OutOfMemoryError (part 1) - story of a developer</a>, <a href="http://plumbr.eu/blog/solving-outofmemoryerror-why-didnt-operations-solve-it">Solving OutOfMemoryError (part 2)- why didn’t operations solve it?</a>, <a href="http://plumbr.eu/blog/solving-outofmemoryerror-where-do-you-start">Solving OutOfMemoryError (part 3) - where do you start?</a>, and <a href="http://plumbr.eu/blog/solving-outofmemoryerror-memory-profilers">Solving OutOfMemoryError (part 4) - memory profilers</a>.</p>


<strong style="font-size: 125%;">Debugging the JVM</strong>

<p><a href="http://www.transylvania-jug.org/transilvania-jug/despre-noi">Attila Balazs</a>'s post <a href="http://www.transylvania-jug.org/archives/331">Debugging the JVM</a> provides interesting insight on something that we don't seem to have to do as often these days as in the earlier days of the JVM, but could be a very useful resource on the occasions this does occur. Balazs talks about "crashing the JVM itself" via <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7105883">null thread group name</a> and then goes onto explain using <a href="http://www.ibm.com/developerworks/library/l-gdb/">gdb in Linux</a> to debug the issue with the JVM.</p>


<strong style="font-size: 125%;">Groovy Introduction</strong>

<p><a href="http://www.blogger.com/profile/11632964711752480304">Alex</a>'s post provides an <a href="http://alexsotob.blogspot.com/2011/09/soy-el-capitan-de-la-nave-tengo-el.html">introduction to Groovy</a> including coverage of <a href="http://marxsoftware.blogspot.com/2009/11/slurping-xml-with-groovy.html">XML with Groovy</a>, <a href="http://marxsoftware.blogspot.com/2010/12/regular-expressions-in-groovy-via-java.html">regular expressions with Groovy</a>, and <a href="http://marxsoftware.blogspot.com/2009/05/groovysql-groovy-jdbc.html">SQL with Groovy</a>.</p>


<strong style="font-size: 125%;">A New Java Blog With Two JavaFX Posts</strong>

<p>I've posted before on why more <a href="http://marxsoftware.blogspot.com/2009/09/more-software-developers-should-write.html">developers should write blogs</a>. One of the reasons is the variety of opinions and ideas that are generated that way. With this in mind, I have been interested to read the first two posts of new blog <a href="http://saidandem.blogspot.com/">Experiments with Java</a>. Both of the blog's current posts have been written in January 2012 and are on JavaFX 2. The posts are <a href="http://saidandem.blogspot.com/2012/01/percent-width-for-tablecolumn-in-javafx.html">Percent Width for TableColumn in JavaFX 2.x TableView</a> and <a href="http://saidandem.blogspot.com/2012/01/sliding-in-javafx-its-all-about.html">Sliding in JavaFX (It’s all about clipping)</a>.</p>

<strong style="font-size: 125%;">Conclusion</strong>

<p>There have been several good Java-related posts in recent weeks and a sample of them are highlighted in this post.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-6690254032930193842?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/UK0YByKUOBw" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>Book Review: JavaFX 2.0: Introduction by Example</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8294" />
    <id>http://www.javaworld.com/community/node/8294</id>
    <published>2012-01-16T21:49:00-05:00</published>
    <updated>2012-01-16T22:00:14-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p>Although Oracle's changes to <a href="http://javafx.com/">JavaFX</a> at <a href="http://marxsoftware.blogspot.com/2010/09/javaone-2010-general-observations-and.html">JavaOne 2010</a> and <a href="http://marxsoftware.blogspot.com/2011/10/javaone-2011-overall-impressions-good.html">JavaOne 2011</a> have converted me from a <a href="http://marxsoftware.blogspot.com/2010/05/o-javafx-what-art-thou.html">skeptic</a> to a <a href="http://marxsoftware.blogspot.com/2011/05/javafx-2-beta-time-to-reevaluate-javafx.html">believer</a> when it comes to <a href="http://marxsoftware.blogspot.com/search/lab    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>Although Oracle's changes to <a href="http://javafx.com/">JavaFX</a> at <a href="http://marxsoftware.blogspot.com/2010/09/javaone-2010-general-observations-and.html">JavaOne 2010</a> and <a href="http://marxsoftware.blogspot.com/2011/10/javaone-2011-overall-impressions-good.html">JavaOne 2011</a> have converted me from a <a href="http://marxsoftware.blogspot.com/2010/05/o-javafx-what-art-thou.html">skeptic</a> to a <a href="http://marxsoftware.blogspot.com/2011/05/javafx-2-beta-time-to-reevaluate-javafx.html">believer</a> when it comes to <a href="http://marxsoftware.blogspot.com/search/label/JavaFX">JavaFX</a>, the shift in JavaFX vision has not been <a href="http://marxsoftware.blogspot.com/2011/12/challenges-of-javafx-reboot.html">without its downsides</a>. In particular, the JavaFX book market has been tricky because <a href="http://stackoverflow.com/questions/7754803/any-decent-books-on-javafx-2">nearly all available JavaFX books</a> have been about version 1.x. In this post, I review the only book that I'm aware of at time of this writing that is completely focused on <a href="http://javafx.com/roadmap/">JavaFX 2.0</a>: <a href="http://carlfx.wordpress.com/tag/carl-dea/">Carl Dea</a>'s <a href="http://www.apress.com/9781430242574">JavaFX 2.0: Introduction by Example</a>.</p>

<p>I'll start my review by stating the most important observation about <em>JavaFX 2.0: Introduction by Example</em>: it provided me exactly what I was looking for exactly when I needed it. There are some attributes of the book that might be considered negative by some readers that I felt were positives in my use of the book. I'll attempt in this post to articulate the finer points of these attributes so that perspective readers can make up their own minds.</p>

<p><em>JavaFX 2.0 Introduction by Example</em> does exactly what the title implies: it introduces JavaFX 2.0 via numerous and varied examples. This code-heavy book is roughly similar to a "recipes" or "cookbook" with individual item covered (AKA a "recipe" in a recipes or cookbook) featuring subsections on the problem to be solved, the solution or solutions to that problem, and how those solutions work. Like the best recipes-oriented or cookbook-oriented software development books, this one is constructed so that Chapter 1 ("JavaFX Fundamentals") covers some of the basics of JavaFX early on. In other words, the reader is not dropped into JavaFX without first getting some examples of how to write and deploy basic "Hello World" style JavaFX applications.</p>

<p>Although <em>JavaFX 2.0: Introduction by Example</em> does provide introductory examples early on, I really appreciated the author not spending significant time discussing esoteric features of the language or delving into the history of JavaFX in tedious detail or providing pages worth of explanation on why JavaFX is the <a href="http://idioms.thefreedictionary.com/the+best+thing+since+sliced+bread">greatest thing since sliced bread</a>. I'm usually in a hurry and I have come to resent books wasting my time on such things and this book doesn't do that. In this case, I was already familiar with these aspects of JavaFX (at least its history and why I might be interested in learning more about it), so I was especially appreciative of Dea not wasting paper and my time on that subject. In the book's concise "Introduction," Dea covers in a page and a half some advantages of JavaFX and "some history" of JavaFX along with a simple table articulating features of each release of JavaFX. It's a thing of beauty to be able to read all of this in less than two pages and in the introduction!</p>

<p>Dea covers some more background on JavaFX in the first chapter, but again limits that discussion to a single page. This page is more detailed than the introductory section and is a nice, brief segue into the technical meat of the book. This first page also contains the sentences that I think best sum up the value of this book:</p>
<blockquote>Although this book doesn't go through an exhaustive study of all of JavaFX 2.0's capabilities, you will find common use cases that can help you build richer applications. Hopefully, these recipes can lead you in the right direction by providing practical and real-world examples.</blockquote>

<p>This is exactly what <em>JavaFX 2.0: Introduction by Example</em> has done for me. It has provided me with a fast start into the world of JavaFX. Although I have since used several aspects of JavaFX not covered in this book, the book gave me the start that I needed and I was able to use <a href="http://www.oracle.com/technetwork/java/javafx/documentation/index.html">JavaFX documentation</a> for the areas not covered in this book.</p>

<p><em>JavaFX 2.0: Introduction by Example</em> gets to the point quickly. Besides common things like the very brief introduction and the index, the book contains four chapters (32 "recipes") spanning 174 pages of text, images, and code. Dea doesn't even waste time with a conclusion, but ends the book with "recipe" 4.5 ("Displaying Content from the Database"). Although some readers may need a conclusion to bring closure to their reading experience, I usually little value in this for me as a reader and I didn't miss it here. I typically don't read these types of book cover-to-cover anyway (instead focusing on sections or recipes I am most interested in), so the conclusion is often unnecessary. Lack of a conclusion is another example of how Dea's book focuses most on what I want: the technical meat.</p>

<p>The four chapters in <em>JavaFX 2.0: Introduction by Example</em> are "JavaFX Fundamentals," "Graphics with JavaFX," "Media with JavaFX," and "JavaFX on the Web." The first chapter was most useful for quickly immersing myself into the basics of JavaFX and how to apply it. The examples in that chapter tend to be simple and easy to follow. The examples in the other three chapters tend to be more sophisticated because the functionality being covered tends to be more sophisticated. There are numerous lengthy code listings in the book. Although code listings may not be the easiest to read, I like to see actual code in any book on a language. Dea typically follows each code sample with descriptive text on any new feature shown in the code sample that had not been covered previously in the book. The code samples can be downloaded from Apress's site. The book also features numerous screen snapshots, which I consider a must for a book focused on user interfaces.</p>

<p>The concise and introductory approach of <em>JavaFX 2.0: Introduction by Example</em> that appealed to me may not appeal to everyone. This book, as advertised in the above cited quotation from the first chapter, is intended to be introductory (hence the title) and not to be exhaustive. Some topics that I have not seen covered in this book include subjects such as <a href="http://marxsoftware.blogspot.com/2012/01/focus-on-javafx-2-fxml-with-netbeans-71.html">FXML</a>, the JavaFX <a href="http://marxsoftware.blogspot.com/2011/12/javafx-20-bar-and-scatter-charts-and.html">charting</a> functionality, <a href="http://groovy.codehaus.org/GroovyFX">GroovyFX</a>, and <a href="http://code.google.com/p/scalafx/">ScalaFX</a>. <a href="http://docs.oracle.com/javafx/2.0/deployment/deploy_quick_start.htm">Deployment</a> is only lightly covered (and mostly via NetBeans), but Dea does reference <a href="http://docs.oracle.com/javafx/2.0/deployment/jfxpub-deployment.htm">Deploying JavaFX Applications</a> for more details on JavaFX deployment. All of these areas, however, are fairly approachable given the JavaFX basics provided in this book. Dea recommends that readers reference forthcoming (<a href="http://learnjavafx.typepad.com/weblog/2012/01/zenpongfx-example-excerpt-from-pro-javafx-2-platform-book.html">mid-February 2012</a>, Apress) <a href="http://www.apress.com/9781430268727">Pro JavaFX 2.0 Platform</a> for an "invaluable resource" that provides "further insight into JavaFX."</p>

<p>Although a small number of the items/recipes covered in <em>JavaFX 2.0: Introduction by Example</em> are based on and assume use of <a href="http://netbeans.org/">NetBeans</a>, most examples in no way specific to any tool or IDE. Rather, most examples provide "raw" code that can be used in any IDE or favorite text editor. Indeed, many of the examples can be compiled with the <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html">javac</a> <a href="http://java.sun.com/javase/technologies/core/toolsapis/javac/index.jsp">compiler</a> and executed with the <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/java.html">java</a> <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html">application launcher</a>. I appreciated that in at least one NetBeans-oriented recipe, Dea took the page or two necessary to provide the code listing for code generated by NetBeans. This is invaluable for those who do not use NetBeans or who want to understand the code itself rather than simply understanding how to use NetBeans to generate the code.</p>

<p><em>JavaFX 2.0: Introduction by Example</em> was exactly what I needed for an efficient and effective start to my investigation of JavaFX. It may not provide quite the level of soft introduction someone completely unfamiliar with JavaFX might want (especially if that person's basic Java skills are a little rusty) and it isn't an "exhaustive" JavaFX 2.0 reference either. It falls in between these extremes and seems to be a fast start example-based introduction to JavaFX for those who want to get into the core of JavaFX as quickly as possible. That's what I wanted when I purchased this book and I was happy to find out that's exactly what this book provides. It's completely JavaFX 2.x-oriented and there is no sign of deprecated JavaFX Script in any of the code examples.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-6659861515267164433?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/MBVxgOUcrYI" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>Focus on JavaFX 2 FXML with NetBeans 7.1</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8292" />
    <id>http://www.javaworld.com/community/node/8292</id>
    <published>2012-01-16T10:06:00-05:00</published>
    <updated>2012-01-16T11:00:16-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p>In <a href="http://marxsoftware.blogspot.com/2011_10_01_archive.html">October 2011</a>, I used the post <a href="http://marxsoftware.blogspot.com/2011/10/hello-javafx-20-introduction-by.html">Hello JavaFX 2.0: Introduction by NetBeans 7.1 beta</a> to look at using <a href="http://netbeans.org/community/news/show/1539.html">NetBeans 7.1 beta</a> to build a simple <a href="http://en.wikipedia.org/wiki/Hello_world_program">Hello, World</a> style of <a href="http://javafx.com/roadmap/">JavaFX 2.0</a> application.    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>In <a href="http://marxsoftware.blogspot.com/2011_10_01_archive.html">October 2011</a>, I used the post <a href="http://marxsoftware.blogspot.com/2011/10/hello-javafx-20-introduction-by.html">Hello JavaFX 2.0: Introduction by NetBeans 7.1 beta</a> to look at using <a href="http://netbeans.org/community/news/show/1539.html">NetBeans 7.1 beta</a> to build a simple <a href="http://en.wikipedia.org/wiki/Hello_world_program">Hello, World</a> style of <a href="http://javafx.com/roadmap/">JavaFX 2.0</a> application. In this post, I look at using <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#JavaFX_2_Support">NetBeans 7.1</a> (<a href="http://marxsoftware.blogspot.com/2012/01/netbeans-71-released.html">no longer in beta</a>) to build a slightly more sophisticated JavaFX 2 application that makes heavy use of <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#FXML">FXML</a>.</p>

<p>Most of my posts on JavaFX 2 up to this point have emphasized the "pure Java" nature of JavaFX 2. The examples in these posts have been written in standard Java using JavaFX 2 APIs directly from the Java source code. These examples have also been built with the <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html">javac compiler</a> and executed with the <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html">java application launcher</a>. In this post, I take one of those examples [<a href="http://marxsoftware.blogspot.com/2011/12/pure-java-javafx-20-menus.html">(Pure Java) JavaFX 2.0 Menus</a>] and "port" it to use <a href="http://docs.oracle.com/javafx/2.0/fxml_get_started/jfxpub-fxml_get_started.htm">FXML</a> for presentation layout.</p>

<p>For convenience, I include the entire Java listing for the "pure Java" implementation of the JavaFX 2 menus demonstration.</p>

<strong>JavaFX 2.0 Menus Demonstration (Pure Java)</strong>
<pre name="code" class="java" style="font-size: 9pt; overflow: auto;">
package dustin.examples;

import static java.lang.System.out;

import javafx.application.Application;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 * Example of creating menus in JavaFX.
 * 
 * @author Dustin
 */
public class JavaFxMenus extends Application
{
   /**
    * Build menu bar with included menus for this demonstration.
    * 
    * @param menuWidthProperty Width to be bound to menu bar width.
    * @return Menu Bar with menus included.
    */
   private MenuBar buildMenuBarWithMenus(final ReadOnlyDoubleProperty menuWidthProperty)
   {
      final MenuBar menuBar = new MenuBar();

      // Prepare left-most 'File' drop-down menu
      final Menu fileMenu = new Menu("File");
      fileMenu.getItems().add(new MenuItem("New"));
      fileMenu.getItems().add(new MenuItem("Open"));
      fileMenu.getItems().add(new MenuItem("Save"));
      fileMenu.getItems().add(new MenuItem("Save As"));
      fileMenu.getItems().add(new SeparatorMenuItem());
      fileMenu.getItems().add(new MenuItem("Exit"));
      menuBar.getMenus().add(fileMenu);

      // Prepare 'Examples' drop-down menu
      final Menu examplesMenu = new Menu("JavaFX 2.0 Examples");
      examplesMenu.getItems().add(new MenuItem("Text Example"));
      examplesMenu.getItems().add(new MenuItem("Objects Example"));
      examplesMenu.getItems().add(new MenuItem("Animation Example"));
      menuBar.getMenus().add(examplesMenu);

      // Prepare 'Help' drop-down menu
      final Menu helpMenu = new Menu("Help");
      final MenuItem searchMenuItem = new MenuItem("Search");
      searchMenuItem.setDisable(true);
      helpMenu.getItems().add(searchMenuItem);
      final MenuItem onlineManualMenuItem = new MenuItem("Online Manual");
      onlineManualMenuItem.setVisible(false);
      helpMenu.getItems().add(onlineManualMenuItem);
      helpMenu.getItems().add(new SeparatorMenuItem());
      final MenuItem aboutMenuItem =
         MenuItemBuilder.create()
                        .text("About")
                        .onAction(
                            new EventHandler&lt;ActionEvent&gt;()
                            {
                               @Override public void handle(ActionEvent e)
                               {
                                  out.println("You clicked on About!");
                               }
                            })
                        .accelerator(
                            new KeyCodeCombination(
                               KeyCode.A, KeyCombination.CONTROL_DOWN))
                        .build();             
      helpMenu.getItems().add(aboutMenuItem);
      menuBar.getMenus().add(helpMenu);

      // bind width of menu bar to width of associated stage
      menuBar.prefWidthProperty().bind(menuWidthProperty);

      return menuBar;
   }

   /**
    * Start of JavaFX application demonstrating menu support.
    * 
    * @param stage Primary stage.
    */
   @Override
   public void start(final Stage stage)
   {
      stage.setTitle("Creating Menus with JavaFX 2.0");
      final Group rootGroup = new Group();
      final Scene scene = new Scene(rootGroup, 800, 400, Color.WHEAT);
      final MenuBar menuBar = buildMenuBarWithMenus(stage.widthProperty());
      rootGroup.getChildren().add(menuBar);
      stage.setScene(scene);
      stage.show();
   }

   /**
    * Main executable function for running examples.
    * 
    * @param arguments Command-line arguments: none expected.
    */
   public static void main(final String[] arguments)
   {
      Application.launch(arguments);
   }
}
</pre>

<p>Besides adding the ability to write JavaFX applications in "pure Java" as implemented in the last code listing, JavaFX 2 also provides <a href="http://tomsondev.bestsolution.at/2011/09/26/how-to-author-fxml/">FXML</a>, an XML grammar for specifying a JavaFX application's layout. This approach is very similar to that provided by <a href="http://learn.adobe.com/wiki/display/Flex/Getting+Started">Flex</a>'s <a href="http://learn.adobe.com/wiki/display/Flex/MXML">MXML</a>, by <a href="http://wiki.openlaszlo.org/Main_Page">OpenLaszlo</a>'s <a href="http://wiki.openlaszlo.org/Editing_LZX">LZX</a>, and by <a href="https://developer.mozilla.org/en-US/">Mozilla</a>'s <a href="https://developer.mozilla.org/En/XUL">XUL</a>. This approach works well with JavaFX's hierarchical Scene Graph.</p>

<p>The ported FXML code is shown next. It is easy to see the presentation structure in this XML.</p>

<strong>JavaFx2Menus.fxml</strong>
<pre name="code" class="xml" style="font-size: 9pt; overflow: auto;">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;?import java.lang.*?&gt;
&lt;?import javafx.scene.*?&gt;
&lt;?import javafx.scene.control.*?&gt;
&lt;?import javafx.scene.layout.*?&gt;

&lt;VBox id="vbox" prefHeight="400" prefWidth="800"
      xmlns:fx="http://javafx.com/fxml"
      fx:controller="dustin.examples.MenuController"&gt;
   &lt;MenuBar fx:id="menuBar" onKeyPressed="#handleKeyInput"&gt;
      &lt;menus&gt;
         &lt;Menu text="File"&gt;
            &lt;items&gt;
               &lt;MenuItem text="New"/&gt;
               &lt;MenuItem text="Open"/&gt;
               &lt;MenuItem text="Save"/&gt;
               &lt;MenuItem text="Save As"/&gt;
               &lt;SeparatorMenuItem  /&gt;
               &lt;MenuItem text="Exit"/&gt;
            &lt;/items&gt;
         &lt;/Menu&gt;
         &lt;Menu text="JavaFX 2.0 Examples"&gt;
            &lt;items&gt;
               &lt;MenuItem text="Text Example"/&gt;
               &lt;MenuItem text="Objects Example"/&gt;
               &lt;MenuItem text="Animation Example"/&gt;
            &lt;/items&gt;
         &lt;/Menu&gt;
         &lt;Menu text="Help"&gt;
            &lt;items&gt;
               &lt;MenuItem text="Search" disable="true"/&gt;
               &lt;MenuItem text="Online Manual" visible="false"/&gt;
               &lt;SeparatorMenuItem /&gt;
               &lt;MenuItem text="About" onAction="#handleAboutAction"/&gt;
            &lt;/items&gt;
         &lt;/Menu&gt;
      &lt;/menus&gt;
   &lt;/MenuBar&gt;
&lt;/VBox&gt;
</pre>

<p>The important portion of this simple FXML can be viewed on a single page within NetBeans 7.1 as shown in the next screen snapshot.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-dJsqer3WE7I/TxOJ2RwJUvI/AAAAAAAAC9s/k_N0iQSZ6XQ/s1600/JavaFxMenusFxmlInNetBeans71.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="320" width="302" src="http://4.bp.blogspot.com/-dJsqer3WE7I/TxOJ2RwJUvI/AAAAAAAAC9s/k_N0iQSZ6XQ/s320/JavaFxMenusFxmlInNetBeans71.png" /></a></div>

<p>Besides the conciseness of the FXML and the aesthetically pleasing hierarchical presentation, the FXML also should look familiar to anyone who has worked with Flex, OpenLaszlo, or XUL. Most of the presentation structure is easily identified in the FXML document. This example includes an <code>onAction</code> handler that responds to the "About" menu item and there is an <code>onKeyPressed</code> action associated with the menu bar as well (I could not figure out a way to easily associate this handler with the menu item itself). Both of these actions reference names that start with the <code>#</code> symbol. The names following the <code>#</code> are names of methods on the controller class (defined by the <code>fx:controller</code> attribute of the <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/layout/VBox.html">VBox</a> as the class named <code>dustin.examples.MenuController</code>). The source for this controller class is shown next.</p>

<strong>MenuController.java</strong>
<pre name="code" class="java" style="font-size: 9pt; overflow: auto;">
package dustin.examples;

import static java.lang.System.out;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.MenuBar;
import javafx.scene.input.InputEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;

/**
 * Controller class for JavaFX 2 Menus with FXML post and demonstration.
 * 
 * @author Dustin
 */
public class MenuController implements Initializable
{
   @FXML
   private MenuBar menuBar;

   /**
    * Handle action related to "About" menu item.
    * 
    * @param event Event on "About" menu item.
    */
   @FXML
   private void handleAboutAction(final ActionEvent event)
   {
      provideAboutFunctionality();
   }

   /**
    * Handle action related to input (in this case specifically only responds to
    * keyboard event CTRL-A).
    * 
    * @param event Input event.
    */
   @FXML
   private void handleKeyInput(final InputEvent event)
   {
      if (event instanceof KeyEvent)
      {
         final KeyEvent keyEvent = (KeyEvent) event;
         if (keyEvent.isControlDown() && keyEvent.getCode() == KeyCode.A)
         {
            provideAboutFunctionality();
         }
      }
   }

   /**
    * Perform functionality associated with "About" menu selection or CTRL-A.
    */
   private void provideAboutFunctionality()
   {
      out.println("You clicked on About!");      
   }

   @Override
   public void initialize(final URL url, final ResourceBundle rb)
   {
      menuBar.setFocusTraversable(true);
   }   
}
</pre>

<p>The above code from the controller class includes the two methods referenced as action handlers in the FXML with the <code>#</code> prefixes. These two methods are <code>private</code> and normally would not be visible to the FXML loader, but the use of the annotation <a href="http://docs.oracle.com/javafx/2.0/api/javafx/fxml/FXML.html">@FXML</a> gets around this problem. The <code>menuBar</code> attribute is also <code>private</code> but visible to the FXML loader thanks to its own <code>@FXML</code> annotation.</p>

<p>To get the application to respond to CTRL-A before any initial access of the menu bar, I found that I needed to have a reference to the menu bar in the controller and call <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/MenuBar.html">setFocusTraversable(true)</a> on that instance. Without doing that, the CTRL-A would only be responded to if I had first clicked on the menu bar once. The hook from the FXML to this attribute in the controller is the <code>fx:id</code> attribute used in the FXML. That attribute references the name "menuBar", which is (not coincidentally) also the name of the attribute in the controller class. In other words, the attribute <code>fx:id=&quot;menuBar&quot;</code> ties the XML element that attribute is on in the FXML to the attribute with the same name in the controller.</p>

<p>I did not show much in this post specific to NetBeans 7.1, but it is worth noting that I had all the pertinent files created in a new project using NetBeans 7.1's New Project wizard and selecting a JavaFX FXML Application as the project type. This created a basic FXML file, a basic controller file, and a main class for loading the FXML and running the application. I modified these to the examples above for the FXML and for the controller class. The modified class that loads the FXML and starts the JavaFX application is shown next. (There's not a lot to it!)</p>

<strong>JavaFxMenusWithFxmlDemo.java</strong>
<pre name="code" class="java" style="font-size: 9pt; overflow: auto;">
package dustin.examples;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 * Simple example of JavaFX 2 FXML used to demonstrate JavaFX 2 menus. This is a
 * "port" of the example featured using "pure Java" (no FXML) in the post
 * "(Pure Java) JavaFX 2.0 Menus"
 * (<a href="http://marxsoftware.blogspot.com/2011/12/pure-java-javafx-20-menus.html" title="http://marxsoftware.blogspot.com/2011/12/pure-java-javafx-20-menus.html">http://marxsoftware.blogspot.com/2011/12/pure-java-javafx-20-menus.html</a>).
 * 
 * @author Dustin
 */
public class JavaFxMenusWithFxmlDemo extends Application
{
   /**
    * Main function for running this application.
    * 
    * @param arguments Command-line arguments: none expected.
    */
   public static void main(String[] arguments)
   {
      Application.launch(JavaFxMenusWithFxmlDemo.class, arguments);
   }

   /**
    * Overridden Application.start(Stage) method.
    * 
    * @param stage Primary stage.
    * @throws Exception JavaFX application exception.
    */
   @Override
   public void start(final Stage stage) throws Exception
   {
      final Parent fxmlRoot = FXMLLoader.load(getClass().getResource("JavaFx2Menus.fxml"));
      stage.setScene(new Scene(fxmlRoot));
      stage.show();
   }
}
</pre>

<p>I won't show the output here because it's essentially what the "pure Java" version produced, which is shown in my post on that approach. Besides generating the files that I adapted for my application, NetBeans 7.1's new project wizard for a JavaFX FXML application also created a project that automatically packages up what I need for my JavaFX application in an executable JAR. The contents of the JAR in this case are shown in the next screen snapshot.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-nALb9zuq8VY/TxOSdnu4omI/AAAAAAAAC94/tTN_lnADn7I/s1600/JavaFxMenusFxmlExampleJarContentsFromNB71Project.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="234" width="320" src="http://4.bp.blogspot.com/-nALb9zuq8VY/TxOSdnu4omI/AAAAAAAAC94/tTN_lnADn7I/s320/JavaFxMenusFxmlExampleJarContentsFromNB71Project.png" /></a></div>

<p>The trickiest part about using FXML is the relatively less available documentation. The pure Java APIs have the strong <a href="http://docs.oracle.com/javafx/2.0/api/index.html">Javadoc API documentation</a>, but I know of no such thing for FXML (including no documentation or schema for the namespace <a href="http://javafx.com/fxml">http://javafx.com/fxml</a>). There are some great resources of FXML such as <a href="http://docs.oracle.com/javafx/2.0/fxml_get_started/jfxpub-fxml_get_started.htm">Getting Started with FXML</a> and <a href="http://docs.oracle.com/javafx/2.0/api/javafx/fxml/doc-files/introduction_to_fxml.html">Introduction to FXML</a>. Perhaps the best document for figuring out what elements and attributes FXML provides is <a href="http://fxexperience.com/wp-content/uploads/2011/08/Introducing-FXML.pdf">Introducing FXML: A Markup Language for JavaFX</a>, which explains the "mapping" of JavaFX standard Java API classes to JavaFX FXML elements and attributes.</p>

<p>FXML appears to be a fairly attractive approach for building a JavaFX application because it nicely separates presentation (FXML) from business logic (controller class and classes that would be called by controller methods). This can make it easier to visually see the GUI layout in the hierarchical XML and keep the logic and presentation from cluttering each other.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-5947065025213051525?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/nct__92lHGQ" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>Revealing Project Naughtiness with Tattletale</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8290" />
    <id>http://www.javaworld.com/community/node/8290</id>
    <published>2012-01-12T23:46:00-05:00</published>
    <updated>2012-01-13T00:01:21-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p><a href="http://www.jboss.org/tattletale">Tattletale</a> is a highly useful development tool that not only has a catchy name, but also has a clever slogan: "Betraying your project's naughty little secrets." <a href="http://docs.jboss.org/tattletale/presentations/tattletale-1.0.pdf">Tattletale</a> scours JAR files to find various naught little secrets about dependencies, multiple versions, extraneous versions of classes, JARs in multiple locations, and so forth.    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p><a href="http://www.jboss.org/tattletale">Tattletale</a> is a highly useful development tool that not only has a catchy name, but also has a clever slogan: "Betraying your project's naughty little secrets." <a href="http://docs.jboss.org/tattletale/presentations/tattletale-1.0.pdf">Tattletale</a> scours JAR files to find various naught little secrets about dependencies, multiple versions, extraneous versions of classes, JARs in multiple locations, and so forth. It is a simple tool that can be run from the command-line to generate simple HTML reports of multiple characteristics about JARs and classes.</p>

<p>To demonstrate Tattletale, I will execute it against a <a href="http://www.springsource.org/node/813">Spring Framework 2.5.6</a> installation. It is simple to run Tattletale and this is demonstrated in the next screen snapshot.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-eqN4gzxP2Sg/Tw-xfhpJznI/AAAAAAAAC8I/pYRRmvM6QcA/s1600/runningTattletaleAgainstSpring256.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="189" width="320" src="http://1.bp.blogspot.com/-eqN4gzxP2Sg/Tw-xfhpJznI/AAAAAAAAC8I/pYRRmvM6QcA/s320/runningTattletaleAgainstSpring256.png" /></a></div>

<p>The <code>tattletale.jar</code> is an executable JAR and so is run with <code>java -jar tattletale.jar</code>. The first argument passed to it is the directory to be recursively searched (Spring 2.5.6 distribution in this case) and the second argument is the directory to which the HTML reports should be written (<code>spring-output</code> in this example). The directory listing of the <code>spring-output</code> directory is shown next.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-eXOSBnipvvE/Tw-yghzAsSI/AAAAAAAAC8U/ChzDen9T1co/s1600/tattletaleSpring256OutputDirectoryListing.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="240" width="320" src="http://4.bp.blogspot.com/-eXOSBnipvvE/Tw-yghzAsSI/AAAAAAAAC8U/ChzDen9T1co/s320/tattletaleSpring256OutputDirectoryListing.png" /></a></div>

<p>As the two previous snapshots indicate, it is very straightforward to run Tattletale against a desired directory. A web browser can be used to open the <code>index.html</code> page as the starting page. This is shown in the next screen snapshot.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-T_1m75Y9buo/Tw-y3xW5jGI/AAAAAAAAC8g/Cf02TBGUslo/s1600/topOfTattletaleOutputForSpring256.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="320" width="203" src="http://2.bp.blogspot.com/-T_1m75Y9buo/Tw-y3xW5jGI/AAAAAAAAC8g/Cf02TBGUslo/s320/topOfTattletaleOutputForSpring256.png" /></a></div>

<p>Only a subset of the available reports are shown in the above snapshot. Clicking on links brings up the individual reports. I show portions of select reports (circular dependencies, class locations, multiple copies of JARs, transitive dependencies, and transitive dependents) next.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-uSFumGcmsHc/Tw-zoi4l5KI/AAAAAAAAC8s/jZfnIAv2oDY/s1600/tattletaleSpring256CircularDependency.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="135" width="320" src="http://1.bp.blogspot.com/-uSFumGcmsHc/Tw-zoi4l5KI/AAAAAAAAC8s/jZfnIAv2oDY/s320/tattletaleSpring256CircularDependency.png" /></a></div>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-L4868wc7_Kw/Tw-z1l8qmKI/AAAAAAAAC84/vkS0NC4heQU/s1600/tattletaleSpring256ClassListing.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="139" width="320" src="http://2.bp.blogspot.com/-L4868wc7_Kw/Tw-z1l8qmKI/AAAAAAAAC84/vkS0NC4heQU/s320/tattletaleSpring256ClassListing.png" /></a></div>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-dJMlkW5xaF8/Tw-0EU0EdGI/AAAAAAAAC9E/rEwCvZVasQU/s1600/tattletaleSpring256MultipleJars.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="145" width="320" src="http://3.bp.blogspot.com/-dJMlkW5xaF8/Tw-0EU0EdGI/AAAAAAAAC9E/rEwCvZVasQU/s320/tattletaleSpring256MultipleJars.png" /></a></div>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-GE83tFkgUUw/Tw-0R5UV8WI/AAAAAAAAC9Q/Qcuxe4vZDgw/s1600/tattletaleSpring256TransitiveDependsOn.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="179" width="320" src="http://2.bp.blogspot.com/-GE83tFkgUUw/Tw-0R5UV8WI/AAAAAAAAC9Q/Qcuxe4vZDgw/s320/tattletaleSpring256TransitiveDependsOn.png" /></a></div>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-csT6vLa2Qps/Tw-0V0QOD6I/AAAAAAAAC9c/O_LKquA8oS8/s1600/tattletaleSpring256TransitiveDependents.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="109" width="320" src="http://3.bp.blogspot.com/-csT6vLa2Qps/Tw-0V0QOD6I/AAAAAAAAC9c/O_LKquA8oS8/s320/tattletaleSpring256TransitiveDependents.png" /></a></div>

<p>Tattletale is so easy to use, very little <a href="http://www.jboss.org/tattletale/docs">documentation</a> is necessary. However, there is a <a href="http://docs.jboss.org/tattletale/presentations/tattletale-1.0.pdf">slide presentation</a> and a <a href="http://docs.jboss.org/tattletale/userguide/1.1/pdf/JBossTattletale-UsersGuide.pdf">User's Guide</a> with introductory information. The 32-page User Guide covers running Tattletale (similar to this post) along with providing details on how to configure the tool via <code>jboss-tattletale.properties</code> and providing an overview of the many reports that <a href="http://blog.carlossanchez.eu/2011/03/23/finding-duplicate-classes-in-your-war-files-with-tattletale/">Tattletale</a> provides about one's project.</p>

<p>To address and correct a project's naughtiest little secrets, one must know what they are. Tattletale is an easy-to-use tool that exposes these naughty secrets so that they can be addressed.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-8318244361010602655?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/DF6sfRDApP4" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>NetBeans 7.1&#039;s Unused Assignment and Dead Branch Hints</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8289" />
    <id>http://www.javaworld.com/community/node/8289</id>
    <published>2012-01-12T00:16:00-05:00</published>
    <updated>2012-01-12T09:00:20-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p>One of the <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Hints">new code hints</a> provided by <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71">NetBeans 7.1</a> is the <a href="http://wiki.netbeans.org/File%3AUnused-assignment.png">Unused Assignment</a> hint. A simple code sample that will cause this hint to be displayed in <a href="http://netbeans.org/community/releases/71/">NetBeans 7.1</a> is shown next.</p>    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>One of the <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Hints">new code hints</a> provided by <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71">NetBeans 7.1</a> is the <a href="http://wiki.netbeans.org/File%3AUnused-assignment.png">Unused Assignment</a> hint. A simple code sample that will cause this hint to be displayed in <a href="http://netbeans.org/community/releases/71/">NetBeans 7.1</a> is shown next.</p>

<strong>Demonstrating Unused Assignment</strong>
<pre name="code" class="java" style="font-size: 9pt; overflow: auto;">
   /**
    * Demonstrate NetBeans 7.1 code hint for situation in which variable
    * assignment is made but never used.
    * 
    * @return Integer.
    */
   private static int demoUnusedAssignment()
   {
      int i = 2;
      // ... do some good stuff, but without changing i's assignment or
      //     accessing i's value ...
      i = 3;
      return i;
   }
</pre>

<p>In the code above, the local variable "i" is initialized to 2, but is never used and then is initialized again, making the first initialization unnecessary. The next image is a screen snapshot that shows NetBeans 7.1 displaying a warning code hint for the unused assignment.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-eHnpaPM_6M4/Tw5x2kZr4MI/AAAAAAAAC7Y/G6_8sGf1sgU/s1600/NetBeans71AssignedValueIsNeverUsed.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="110" width="320" src="http://2.bp.blogspot.com/-eHnpaPM_6M4/Tw5x2kZr4MI/AAAAAAAAC7Y/G6_8sGf1sgU/s320/NetBeans71AssignedValueIsNeverUsed.png" /></a></div>

<p>As the above image indicates, NetBeans 7.1 warns of "The assigned value is never used."</p>

<p>The <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71">New And Noteworthy in NetBeans IDE 7.1 page</a> mentions this hint <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Hints">among others</a> and states:</p>
<blockquote><strong>Unused Assignment</strong><p />
A new pair of hints, Unused Assignment and Dead Branch, was introduced. The Unused Assignment finds values that are computed and assigned to a variable, but never used by reading the variable. The Dead Branch hint searches for branches of code that can never be executed.</blockquote>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-ghItHyo0P-U/Tw50Qi3qeLI/AAAAAAAAC7k/gFm0kYx-iGQ/s1600/NetBeans71AssignedValueIsNeverUsedWikiPageEntryWithDeadBranch.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="122" width="320" src="http://1.bp.blogspot.com/-ghItHyo0P-U/Tw50Qi3qeLI/AAAAAAAAC7k/gFm0kYx-iGQ/s320/NetBeans71AssignedValueIsNeverUsedWikiPageEntryWithDeadBranch.png" /></a></div>

<p />
<strong style="font-size: 125%;">Oh Dead Branch Hint, Where Art Thou?</strong>

<p>The Unused Assignment Hint seems to work as suggested based on the example shown above. However, I have not been able to generate code that demonstrates the "Dead Branch" hint. I wonder if the Dead Branch hint is not yet supported and text related to it is not supposed to be under the "Unused Assignment" heading.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-6K-jUDhuwtM/Tw54ayA7bQI/AAAAAAAAC78/ibgc2_Zhy7g/s1600/NetBeans71NewNoteworthyHintsOnDeadBranchText.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="121" width="320" src="http://3.bp.blogspot.com/-6K-jUDhuwtM/Tw54ayA7bQI/AAAAAAAAC78/ibgc2_Zhy7g/s320/NetBeans71NewNoteworthyHintsOnDeadBranchText.png" /></a></div>

<p>The following code contains a listing with several methods that I would expect might potentially lead to a warning about a dead code branch. None of these cause this code hint to appear in any form (warning or error) in my installation of NetBeans 7.1.</p>

<strong>Methods With Compilable Dead Code Branches</strong>
<pre name="code" class="java" style="font-size: 9pt; overflow: auto;">
package dustin.examples;

import static java.lang.System.out;

/**
 * Class demonstrating NetBeans 7.1's hint for dead code.
 * 
 * @author Dustin
 */
public class DeadCode
{
   /**
    * Nonsense method that includes an "else" clause that can never be executed.
    * 
    * @param someInt Any primitive int.
    */
   private static void neverExecutedElse(final int someInt)
   {
      if (someInt &lt; 0)
      {
         out.println("The integer you provided is less than zero.");
      }
      else if (someInt &gt; 0)
      {
         out.println("The integer you provided is greater than zero.");
      }
      else if (someInt == 0)
      {
         out.println("The integer is equal to zero.");
      }
      else
      {
         out.println("Unable to categorize provided integer.");
      }
   }

   /**
    * Nonsense method that has executable code following conditions that are
    * always true and always lead to premature termination of the method.
    */
   private static void codeAfterAlwaysTrueConditional()
   {
      if (true)
      {
         throw new RuntimeException("Ouch!");
      }
      final String nothingHere = "Nothing here.";
      out.println(nothingHere);

      if (true)
      {
         return;
      }
      final String nothingHereEither = "Nothing here either.";
      out.println(nothingHereEither);
   }

   /**
    * Nonsense method that prints text to standard output only if the provided
    * boolean can be both {@code true} and {@code false} at the same time.
    * 
    * @param boolValue Boolean value of no consequence.
    */
   private static void cannotHaveItBothWays(final boolean boolValue)
   {
      if (boolValue)
      {
         if (!boolValue)
         {
            out.println("Make up your mind (true or false)!");
         }
      }
      else
      {
         if (boolValue)
         {
            out.println("Make up your mind (false or true)!");
         }
      }
   }

   /**
    * Runs else-if that is same as previous if such that one conditonal
    * prevents the second conditional's implementation from ever being executed.
    * 
    * @param boolValue A boolean value of no consequence.
    */
   private static void pesterUntilItWorks(boolean boolValue)
   {
      boolValue = true;
      if (boolValue)
      {
         out.println("It matches once.");
      }
      else if (boolValue)
      {
         out.println("It matches twice.");
      }
      else if (!boolValue)
      {
         out.println("No match once.");
      }
      else if (!boolValue)
      {
         out.println("No match twice!");
      }
   }

   /**
    * Cover all conditions in first conditional and include a never-can-happen
    * else portion of conditional.
    */
   private static void completeConditionalCoverage()
   {
      boolean boolValue = true;
      if (boolValue || !boolValue)
      {
         out.println("I'm always going to happen.");
      }
      else
      {
         out.println("I'm never going to happen.");
      }

      if (boolValue && !boolValue)
      {
         out.println("I'll never happen either.");
      }
      else
      {
         out.println("I'll also always happen.");
      }
   }

   /**
    * Main executable function.
    * 
    * @param arguments Command-line arguments: none expected.
    */
   public static void main(final String[] arguments)
   {
      if (false)
      {
         neverExecutedElse(5);
         codeAfterAlwaysTrueConditional();
         cannotHaveItBothWays(true);
         pesterUntilItWorks(true);
         demoUnusedAssignment();
         completeConditionalCoverage();
      }
   }
}
</pre>

<p>Although none of the methods in the directly previous code listing lead to the Dead Branch code hint, NetBeans 7.1 does include configuration options for the Dead Branch hint. This is shown in the next screen snapshot (selecting Tools-&gt;Options followed by the "Editor" tab and then selecting "Hints").</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-WthE3CftRQs/Tw52be8_VgI/AAAAAAAAC7w/0LLdi2Ul5rA/s1600/NetBeans71DeadBranchHintWithUnusedAssignmentHintConfiguration.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="259" width="320" src="http://1.bp.blogspot.com/-WthE3CftRQs/Tw52be8_VgI/AAAAAAAAC7w/0LLdi2Ul5rA/s320/NetBeans71DeadBranchHintWithUnusedAssignmentHintConfiguration.png" /></a></div>

<p>The <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71">NetBeans 7.1 News and Noteworthy page</a> shows examples of <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Hints">other new hints</a>, but does not show an example of the Dead Branch hint. Also, the text talking about Dead Branch is mixed with the section on Unused Assignment and under a heading that only talks about Unused Assignment. As my previous code listing demonstrates, I attempted to come up with a code sample to demonstrate the Dead Branch hint, but have not been able to do so. The purpose of this hint ("search[ing] for branches of code that can never be executed") sounds like a nice complement to compiler errors such as "<a href="http://stackoverflow.com/questions/3795585/why-does-java-have-an-unreachable-statement-compiler-error">unreachable statement</a>" and "<a href="http://stackoverflow.com/questions/3222871/exception-already-caught-error">exception already caught</a>" and other NetBeans "green" warnings such as "variable such-and-such is not used."</p>

<p>I have <a href="http://marxsoftware.blogspot.com/2010/10/seven-indispensable-netbeans-java-hints.html">blogged about NetBeans hints</a> before and the <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Hints">addition of new hints</a> in <a href="http://wiki.netbeans.org/NetBeans_71">NetBeans 7.1</a> is welcome. If anyone knows of a code sample that will demonstrate the Dead Branch hint in NetBeans 7.1, please share!</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-5714015867394120818?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/xXPa0ofQ3YA" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>Comparing Heap Dumps with NetBeans 7.1</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8286" />
    <id>http://www.javaworld.com/community/node/8286</id>
    <published>2012-01-10T00:21:00-05:00</published>
    <updated>2012-01-10T02:00:17-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p>One of the "<a href="http://wiki.netbeans.org/NewAndNoteworthyNB71">new and noteworthy</a>" features of <a href="http://wiki.netbeans.org/NetBeans_71">NetBeans 7.1</a> is the ability to <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Compare_heap_dumps">compare two heap dumps</a>. Specifically, the easy-to-use feature allows one to quickly ascertain the difference in number of each class's instances between two dump files. This brief post shows how easy it is to use.</p>    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>One of the "<a href="http://wiki.netbeans.org/NewAndNoteworthyNB71">new and noteworthy</a>" features of <a href="http://wiki.netbeans.org/NetBeans_71">NetBeans 7.1</a> is the ability to <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Compare_heap_dumps">compare two heap dumps</a>. Specifically, the easy-to-use feature allows one to quickly ascertain the difference in number of each class's instances between two dump files. This brief post shows how easy it is to use.</p>

<p><a href="http://docs.oracle.com/javase/6/docs/technotes/tools/share/jhat.html">Heap dumps</a> can be generated in a <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/share/jhat.html#description">variety of ways</a>. For purposes of this post, I have created two heap dumps on two totally separate applications using the Oracle JDK-provided <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/share/jmap.html">jmap</a> (Java Memory Map) tool to attach to the processes's Java PIDs and create heap dumps (creatively named <code>Heap1.map</code> and <code>Heap2.map</code> in my example). It's probably not useful in most cases to compare heap dumps of two entirely different applications. I only do so in this example to make the differences calculated in the comparison results obvious.</p>

<p>The next screen snapshot shows <a href="http://marxsoftware.blogspot.com/2012/01/netbeans-71-released.html">NetBeans 7.1</a> started with the option "Load heap dump..." being selected under the "Profile" menu. This is done to load the first heap dump of the two to be compared.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-w1IQfVSQOBQ/TwvFoVkUeqI/AAAAAAAAC6E/hZf3VUADRiA/s1600/loadingHeapDumpInNetBeans71.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="229" width="320" src="http://3.bp.blogspot.com/-w1IQfVSQOBQ/TwvFoVkUeqI/AAAAAAAAC6E/hZf3VUADRiA/s320/loadingHeapDumpInNetBeans71.png" /></a></div>

<p>The next screen image shows the results of selecting "Load heap dump..." (the popup titled "Open Heap Dump File") and indicates selecting one of the heap dumps (<code>Heap1.map</code>).</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-xN-spvzmBAg/TwvGWLiOLnI/AAAAAAAAC6Q/75WIFPswzr8/s1600/netbeans71openHeapDumpFileSelector.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="203" width="320" src="http://4.bp.blogspot.com/-xN-spvzmBAg/TwvGWLiOLnI/AAAAAAAAC6Q/75WIFPswzr8/s320/netbeans71openHeapDumpFileSelector.png" /></a></div>

<p>The next screen snapshot shows how NetBeans 7.1 looks with the selected heap dump displayed with the "Summary" tab in focus.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-Hek3R_yAVtc/TwvGv7VCX2I/AAAAAAAAC6c/OefRBr7X6Ac/s1600/netbeans71Heap1Displayed.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="155" width="320" src="http://3.bp.blogspot.com/-Hek3R_yAVtc/TwvGv7VCX2I/AAAAAAAAC6c/OefRBr7X6Ac/s320/netbeans71Heap1Displayed.png" /></a></div>

<p>The last image showed the heap file loaded in NetBeans 7.1 with the "Summary" tab in focus. The next image is a snapshot of the IDE switched to the "Classes" tab in the heap dump report area.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-Mu6dptEMWLE/TwvHFPm_cuI/AAAAAAAAC6o/dApxbvRjDpc/s1600/netbeans71Heap1DisplayedClassesTab.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="189" width="320" src="http://1.bp.blogspot.com/-Mu6dptEMWLE/TwvHFPm_cuI/AAAAAAAAC6o/dApxbvRjDpc/s320/netbeans71Heap1DisplayedClassesTab.png" /></a></div>

<p>The last image indicates that NetBeans shows the number of instances of different classes in the Java application whose heap dump is being analyzed. By default, the instances are listed in descending order of number of instances, but one can click on the "Size" column header to sort by total size. Just above the column headings "Instances" and "Size" is a link that says, "Compare with another heap dump" and that is the main focus of this post.</p>

<p>Clicking on the "Compare with another heap dump" link in the "Classes" tab of NetBeans 7.1's heap dump analysis tool leads to a popup ("Select Heap Dump to Compare") for selecting the second heap dump to be compared. This is indicated in the next screen snapshot.</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-OCtcRzpI3VY/TwvILSyLS_I/AAAAAAAAC60/Gzf-eEq6U78/s1600/netbeans71SelectHeapDumpToCompare.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="190" width="320" src="http://2.bp.blogspot.com/-OCtcRzpI3VY/TwvILSyLS_I/AAAAAAAAC60/Gzf-eEq6U78/s320/netbeans71SelectHeapDumpToCompare.png" /></a></div>

<p>In my example, I had two other heap dump files in the same directory as the originally selected one (<code>Heap2.map</code> and <code>Heap3.map</code>). Selecting <code>Heap3.map</code> leads to the comparison being made. This can take a few seconds for the NetBeans IDE to update the representation and it might be worth moving the scroll bar on the right down and back up to make sure it has updated. The next two screen snapshots show the comparison displayed with the first screen snapshot showing the types for which the first heap dump has more instances than the other (top) and the second image showing the types for which the second heap dump has more instances than the other (bottom).</p>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-sa9YEq0vx5c/TwvI5b7b5_I/AAAAAAAAC7A/yJUrMw8qbkw/s1600/netbeans71showingHeapDumpDifferences.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="189" width="320" src="http://2.bp.blogspot.com/-sa9YEq0vx5c/TwvI5b7b5_I/AAAAAAAAC7A/yJUrMw8qbkw/s320/netbeans71showingHeapDumpDifferences.png" /></a></div>

<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-VCLWWvURvvU/TwvJG1C6p8I/AAAAAAAAC7M/JRp9Jp8gMhA/s1600/netbeans71showingHeapDumpDifferencesBottom.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="190" width="320" src="http://3.bp.blogspot.com/-VCLWWvURvvU/TwvJG1C6p8I/AAAAAAAAC7M/JRp9Jp8gMhA/s320/netbeans71showingHeapDumpDifferencesBottom.png" /></a></div>

<p>The + and - signs indicate the number of instances greater (+) or fewer (-) in the first heap dump file analyzed (<code>Heap1.map</code>) as compared to that of the second heap dump file analyzed (<code>Heap3.map</code>). In other words, types with positive numbers have more instances represented in the originally loaded heap dump and types wiuth negative numbers have fewer instances represented in the originally loaded heap dump.</p>

<p>When comparing two separate applications, this doesn't provide much that's interesting other than to illustrate the tool. However, given two instances of the same application at the same execution point with different context or data sets might prove more interesting when comparing heap dumps. Perhaps the most enlightening use of this tool is for comparing heap dumps taken from the same application at different points in its execution. With NetBeans 7.1, it is easy to rapidly determine the difference between two heap dumps in terms of instances loaded at the time each heap dump was taken. When it's the delta or difference that matters, this tool can be useful.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-2784351831669665490?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/b_6P8FvZ1j0" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>First Impressions of Book &#039;JBoss AS 7 Configuration, Deployment and Administration&#039;</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8284" />
    <id>http://www.javaworld.com/community/node/8284</id>
    <published>2012-01-08T00:48:00-05:00</published>
    <updated>2012-01-08T02:00:13-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p><a href="http://www.packtpub.com/">Packt Publishing</a> recently invited me to review the book <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book">JBoss AS 7 Configuration, Deployment and Administration</a>. I readily accepted because I have not used or even read about <a href="http://www.jboss.org/">JBoss</a> in several years and welcomed the opportunity to read about its latest features.    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p><a href="http://www.packtpub.com/">Packt Publishing</a> recently invited me to review the book <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book">JBoss AS 7 Configuration, Deployment and Administration</a>. I readily accepted because I have not used or even read about <a href="http://www.jboss.org/">JBoss</a> in several years and welcomed the opportunity to read about its latest features. In this post, I provide a very brief first impression of the PDF version of this book similar to the <a href="http://marxsoftware.blogspot.com/2011/08/first-impressions-of-java-ee-6.html">brief preliminary review I previously provided</a> of the Packt book <a href="http://www.packtpub.com/java-ee-6-development-with-netbeans-7/book">Java EE 6 Development with NetBeans 7</a>. I intend to provide a more thorough review of <em>JBoss AS 7 Configuration, Deployment and Administration</em> in a future post with a level of detail <a href="http://marxsoftware.blogspot.com/2011/08/book-review-java-ee-6-development-with.html">similar to that I provided</a> for <em>Java EE 6 Development with NetBeans 7</em>.</p>

<p>The subtitle of author Francesco Marchioni's book <em>JBoss AS 7 Configuration, Deployment and Administration</em> is: "Build a fully-functional, efficient application server using JBoss AS." The "About the Author" section of the book states that Marchioni runs the site <a href="http://www.mastertheboss.com/">http://www.mastertheboss.com/</a>, which has a main page with the subtitle "JBoss and Java EE tutorials." Two links currently shown on that main page are to posts about <a href="http://www.mastertheboss.com/jboss-application-server/342-jboss-as-7-book-published-.html">publication</a> of <em>JBoss AS 7 Configuration, Deployment and Administration</em> and about <a href="http://www.mastertheboss.com/component/content/article/349-win-free-copies-of-jboss-as-7-configuration-deployment-and-administration-book.html">winning a free copy</a> of <em>JBoss AS 7 Configuration, Deployment and Administration</em>. Marchioni has also written the books <a href="http://www.packtpub.com/jboss-as-5-development/book">JBoss AS 5 Development</a> and <a href="https://www.packtpub.com/jboss-5-performance-tuning/book">JBoss AS 5 Performance Tuning</a>.</p>

<p>The <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book">Packt Publishing page</a> for <em>JBoss AS 7 Configuration, Deployment and Administration</em> provides a look at the book's <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents">Table of Contents</a>, provides a free sample chapter, and provides more <a href="http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book#in_detail">details on what the book covers</a>.</p>

<p>Perusing the <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents">Table of Contents</a> of <em>JBoss AS 7 Configuration, Deployment and Administration</em> leads me to believe that the 11 chapters will provide broad coverage of administrating and developing with <a href="http://www.jboss.org/as7">JBoss AS 7</a>. The chapters include the titles <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_1">Installing JBoss AS 7</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_2">Configuring the Application Server</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_3">Configuring Enterprise Services</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_4">JBoss Web Server Configuration</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_5">Configuring a JBoss AS Domain</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_6">Deploying Applications on JBoss AS 7</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_7">Managing the Application Server</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_8">Clustering</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_9">Load-balancing Web Applications</a>, <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_10">Securing JBoss AS 7</a>, and the particular trendy title <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_11">Taking JBoss AS 7 in the Cloud</a>. The <a href="http://www.packtpub.com/toc/jboss-7-configuration-deployment-and-administration-table-contents#chapter_12">Appendix</a> looks useful with sections summarizing options and commands for <a href="http://community.jboss.org/wiki/CommandLineInterface">JBoss 7 Command Line Interface</a> (<a href="https://docs.jboss.org/author/display/AS7/Admin+Guide#AdminGuide-RunningtheCLI">CLI</a>).</p>

<p>I look forward to reading <em>JBoss AS 7 Configuration, Deployment and Administration</em> and learning more about <a href="http://www.jboss.org/as7">JBoss AS 7</a>. I will post a lengthier review based on my experience reading it.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-9221837748482857529?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/jB3ZUM2VEok" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>Java Back in the OSCON 2012 Fold</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8283" />
    <id>http://www.javaworld.com/community/node/8283</id>
    <published>2012-01-07T23:26:00-05:00</published>
    <updated>2012-01-08T00:01:26-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p>By all accounts <a href="http://marxsoftware.blogspot.com/2011/08/oscon-java-2011-by-proxy.html">I have read</a> and <a href="http://weblogs.java.net/blog/editor/archive/2011/08/03/experiencing-oscon-java-afar-those-who-didnt-attend">others have expressed</a>, <a href="http://www.oscon.com/oscon2011/public/content/java">OSCON Java 2011</a> was a <a href="http://blogs.oracle.com/java/entry/oscon_java_already_great">tremendous success</a>.    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>By all accounts <a href="http://marxsoftware.blogspot.com/2011/08/oscon-java-2011-by-proxy.html">I have read</a> and <a href="http://weblogs.java.net/blog/editor/archive/2011/08/03/experiencing-oscon-java-afar-those-who-didnt-attend">others have expressed</a>, <a href="http://www.oscon.com/oscon2011/public/content/java">OSCON Java 2011</a> was a <a href="http://blogs.oracle.com/java/entry/oscon_java_already_great">tremendous success</a>. <a href="http://blogs.oracle.com/arungupta/entry/oracle_at_oscon_java">OSCON Java 2011</a> was <a href="http://radar.oreilly.com/programming/">O'Reilly</a>'s Java-specific conference held in conjunction with <a href="http://www.oscon.com/oscon2011">OSCON 2011</a> and the post <a href="http://radar.oreilly.com/2011/06/oscon-java.html">Why OSCON Java?</a> explains some of the reasons for the Java-specific conference being held last year. In 2012, it appears that the separate Data and Java conferences of 2011 are being brought back into the main <a href="http://www.oscon.com/oscon2012">OSCON 2012</a> conference. The page states, "Those who attended last year's OSCON Data and OSCON Java told us that they wanted to be part of the 'main' OSCON, so we're bringing Data and Java back into fold in 2012."</p>

<p>The <a href="http://www.oscon.com/oscon2012/public/content/about">About OSCON page</a> explains OSCON: "Now in its 14th year, OSCON is the best place on the planet to prepare for what comes next ... OSCON is a unique gathering of all things open source." One example of praise for the OSCON conference is available in the post <a href="http://redmonk.com/sogrady/2011/07/24/oscon-2011/">Why I Won’t Be At OSCON This Year</a>.</p>

<p>According to the main <a href="http://www.oscon.com/oscon2012">OSCON 2012 page</a>, "roughly 400 people will be presenting" and <a href="http://www.oscon.com/oscon2012/public/cfp/197">speaker proposals</a> are due 12 January 2012. OSCON 2012 is to be held July 16-20, 2012, in Portland, Oregon, with registration opening in March.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-4590310332033043435?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/LrM_3bAk2pU" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>NetBeans 7.1 Released</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8282" />
    <id>http://www.javaworld.com/community/node/8282</id>
    <published>2012-01-07T20:35:00-05:00</published>
    <updated>2012-01-07T23:00:14-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><!--paging_filter--><p>Perhaps the <a href="http://www.oracle.com/us/corporate/press/1448202">biggest news</a> in all of Javadom this past week was the release of <a href="http://wiki.netbeans.org/NetBeans_71">NetBeans 7.1</a>.</p>    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>Perhaps the <a href="http://www.oracle.com/us/corporate/press/1448202">biggest news</a> in all of Javadom this past week was the release of <a href="http://wiki.netbeans.org/NetBeans_71">NetBeans 7.1</a>.</p>

<p><a href="http://javafx.com/roadmap/">JavaFX 2.0</a> [specifically <a href="http://netbeans.org/community/releases/71/relnotes.html#javafx">JavaFX 2.0.2 SDK support</a> (<a href="http://docs.oracle.com/javafx/2.0/release_notes_2-0-2/jfxpub-release_notes_2-0-2.htm">release notes</a>), which is <a href="http://www.oracle.com/technetwork/java/javafx/downloads/index.html">downloaded separately</a>] is the <a href="http://wiki.netbeans.org/NetBeans_71#JavaFX_2.0">featured attraction</a> for <a href="http://wiki.netbeans.org/NB71_FX2_Plan">NetBeans 7.1</a>. The <a href="http://www.oracle.com/us/corporate/press/1448202">Oracle press release</a> (5 January 2012) announcing <a href="http://netbeans.org/">NetBeans 7.1</a> refers to it as the "first IDE to Support JavaFX 2.0" and the <a href="http://netbeans.org/community/releases/71/">NetBeans 7.1 Release Notes</a> list "Support for JavaFX 2.0" first on the list of new features. In <a href="http://www.javaworld.com/javaworld/jw-01-2012/120105-netbeans-7-1.html">NetBeans 7.1 geared for building better user interfaces</a>, <a href="http://twitter.com/Joab_Jackson">Joab Jackson</a> states that this release "adds full support for Swing, JSF, and JavaFX 2."</p>

<p>The title of <a href="http://www.infoq.com/author/Charles-Humble">Charles Humble</a>'s post is "<a href="http://www.infoq.com/news/2012/01/netbeans71">NetBeans 7.1 Shipped with JavaFX 2.0 and CSS3 Support</a>" and talks about NetBeans "active users" exceeding one million last summer. As that post's title suggests, improved <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#CSS">CSS3 support</a> (including <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#CSS3_support">for JavaFX</a>) is also featured in NetBeans 7.1. The NetBeans for PHP blog features a <a href="http://blogs.oracle.com/netbeansphp/entry/netbeans_7_1_is_now">post on NetBeans 7.1</a> and its <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#PHP">improved PHP features</a>.</p>

<p>NetBeans 7.1 offers other new features and improvements such as <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Hints">more hints</a> (see my post <a href="http://marxsoftware.blogspot.com/2010/10/seven-indispensable-netbeans-java-hints.html">Seven Indispensable NetBeans Java Hints</a> for more information on NetBeans hints). Improvements and new <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Maven_2">features related to Maven</a> are offered as are <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#C.2FC.2B.2B">C/C++ improvements</a>. The new <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Visual_Debugger">Visual Debugger</a> and <a href="http://wiki.netbeans.org/NewAndNoteworthyNB71#Profiler">profiler improvements</a> are also welcome.</p>

<p>No product is perfect, especially when first released, and NetBeans 7.1 has some <a href="http://netbeans.org/community/releases/71/relnotes.html#known_issues">known issues</a>. The post <a href="http://cameotutorials.blogspot.com/2012/01/netbeans-71-is-out-but-watch-out-before.html">Netbeans 7.1 is out but watch out before you grab that hot cake!</a> references some of these.</p>

<p>Not only has the release of NetBeans 7.1 generated significant press and blogosphere coverage, but adoption seems robust as well. Although still in its very early stages, a new <a href="http://home.java.net/">Java.net</a> <a href="http://home.java.net/today/polls/index.csp">poll</a> asking "<a href="http://home.java.net/poll/how-soon-do-you-plan-start-using-just-released-netbeans-71">How soon do you plan to start using the just-released NetBeans 7.1?</a>" currently shows 33% of the respondents stating they are already using NetBeans 1.7 and another 15% stating they intend to upgrade within the month. Given that almost 1/3 of the respondents are saying "Never, since I don't use NetBeans," that's a large percentage of the NetBeans users who have or soon will be upgrading.</p><div class="blogger-post-footer"><p>Original posting available at <a href="http://marxsoftware.blogspot.com/">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/6517450204508339514-7407897029531494274?l=marxsoftware.blogspot.com" alt="" /></div><img src="http://feeds.feedburner.com/~r/InspiredByActualEvents/~4/wtD5WgOAgog" height="1" width="1" />    ]]></content>
  </entry>
  <entry>
    <title>Pair Class Coming to Java via JavaFX?</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8280" />
    <id>http://www.javaworld.com/community/node/8280</id>
    <published>2012-01-05T09:39:00-05:00</published>
    <updated>2012-01-05T11:00:13-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><p>The <a href="http://www.cplusplus.com/reference/std/utility/pair/" rel="nofollow" rel="nofollow">pair class</a> is familiar to those of us who have used C++ for any considerable length of time. Although there has been <a href="http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-March/003988.html" rel="nofollow" rel="nofollow">talk of adding it to Java</a> as a standard part of the SDK, it is a somewhat <a href="http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-March/003994.html" rel="nofollow" rel="nofollow">controversial topic</a>.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>The <a href="http://www.cplusplus.com/reference/std/utility/pair/" rel="nofollow">pair class</a> is familiar to those of us who have used C++ for any considerable length of time. Although there has been <a href="http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-March/003988.html" rel="nofollow">talk of adding it to Java</a> as a standard part of the SDK, it is a somewhat <a href="http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-March/003994.html" rel="nofollow">controversial topic</a>. <a href="http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-March/003973.html" rel="nofollow">Several folks</a> have formally <a href="http://www.developer.com/java/ejb/article.php/3813031/Java-Needs-to-Get-a-Pair-and-a-Triple.htm" rel="nofollow">requested</a> it and bugs have even been filed (<a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4947273" rel="nofollow">4947273</a>, <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4983155" rel="nofollow">4983155</a>, and <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6229146" rel="nofollow">6229146</a>) to get it in Java. In a post asking the question <a href="http://tech.puredanger.com/2010/03/31/do-we-want-a-java-util-pair/" rel="nofollow">Do we want a java.util.Pair?</a>, <a href="http://tech.puredanger.com/about" rel="nofollow">Alex Miller</a> does a nice job of covering both sides of the issue.</p>
<p>There are already implementations of <code>Pair</code> or a <code>Pair</code>-like equivalent out there for Java. Besides the unknown number of custom ones in local code bases, there are publicly available examples such as those provided by the post <a href="http://www.factsandpeople.com/facts-mainmenu-5/8-java/10-java-pair-class" rel="nofollow">Java Pair Class</a>, examples provided in a <a href="http://stackoverflow.com/questions/156275/what-is-the-equivalent-of-the-c-pairl-r-in-java" rel="nofollow">StackOverflow thread</a>, <a href="http://www.ideograph.com/" rel="nofollow">Ideograph</a>'s <a href="http://www.ideograph.com/content/generic-pair-java" rel="nofollow">Generic Pair</a>, and (<a href="http://marxsoftware.blogspot.com/2011/10/java-posts-of-interest-19-october-2011.html" rel="nofollow">no surprise</a>) <a href="http://www.javatuples.org/" rel="nofollow">Java Tuples</a>'s <a href="http://www.javatuples.org/apidocs/org/javatuples/Pair.html" rel="nofollow">Pair</a>. The <a href="http://developer.android.com/sdk/index.html" rel="nofollow">Android SDK</a> also features a <a href="http://developer.android.com/reference/android/util/Pair.html" rel="nofollow">Pair</a> class. The one that has surprised me the most is the existence of <a href="http://javafx.com/roadmap/" rel="nofollow">JavaFX 2.0</a>'s <a href="http://docs.oracle.com/javafx/2.0/api/javafx/util/Pair.html" rel="nofollow">javafx.util.Pair</a> class.</p>
<p>The package and class name most often proposed for an SDK version of the <code>Pair</code> class has been <code>java.util.Pair</code> and the JavaFX version is similar in package name: <code>javafx.util.Pair</code>. Running <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javap.html" rel="nofollow">javap</a> against this class in the JavaFX SDK, leads to the following output.</p>
<p>Compiled from "Pair.java"<br />
public class javafx.util.Pair&lt;K, V&gt; {<br />
  public K getKey();<br />
  public V getValue();<br />
  public javafx.util.Pair(K, V);<br />
  public java.lang.String toString();<br />
  public int hashCode();<br />
  public boolean equals(java.lang.Object);<br />
}</p>
<p>As the above <code>javap</code> output indicates, this is a relatively simple class with a basic parameterized constructor, "get" methods for the key and value portions of the <code>Pair</code>, and "common" methods <code>toString()</code>, <code>equals(Object)</code>, and <code>hashCode()</code>. The next code listing demonstrates using the parameterized constructor to provide the key and value to each instance of <code>Pair</code> that is instantiated.</p>
<p>   /**<br />
    * Provide a collection of famous pairs.<br />
    *<br />
    * @return Collection of famous pairs.<br />
    */<br />
   private static Collection&lt;Pair&lt;String,String&gt;&gt; createFamousPairs()<br />
   {<br />
      final Collection&lt;Pair&lt;String,String&gt;&gt; pairs =<br />
         new ArrayList&lt;Pair&lt;String,String&gt;&gt;();<br />
      pairs.add(new Pair("Yin", "Yang"));<br />
      pairs.add(new Pair("Action", "Reaction"));<br />
      pairs.add(new Pair("Salt", "Pepper"));<br />
      pairs.add(new Pair("Starsky", "Hutch"));<br />
      pairs.add(new Pair("Fox", "Mulder"));<br />
      pairs.add(new Pair("Batman", "Robin"));<br />
      pairs.add(new Pair("Fred Astaire", "Ginger Rogers"));<br />
      pairs.add(new Pair("Flotsam", "Jetsam"));<br />
      pairs.add(new Pair("Brutus", "Nero"));<br />
      pairs.add(new Pair("Tom", "Jerry"));<br />
      pairs.add(new Pair("Jekyll", "Hyde"));<br />
      pairs.add(new Pair("Holmes", "Watson"));<br />
      pairs.add(new Pair("Mario", "Luigi"));<br />
      pairs.add(new Pair("Pinky", "The Brain"));<br />
      pairs.add(new Pair("Wallace", "Gromit"));<br />
      return pairs;<br />
   }</p>
<p>Accessing the key and value of each <code>Pair</code> is also easy as shown in the next code sample.</p>
<p>   /**<br />
    * Write provided collection of pairs to standard output.<br />
    *<br />
    * @param title Title for output written to standard output.<br />
    * @param pairsToPrint Pairs to be written to standard output.<br />
    */<br />
   private static void writeCollectionOfPairs(<br />
      final String title,<br />
      final Collection&lt;Pair&lt;String,String&gt;&gt; pairsToPrint)<br />
   {<br />
      out.println(title + ":");<br />
      for (final Pair&lt;String,String&gt; pair : pairsToPrint)<br />
      {<br />
         out.println("\t" + pair.getKey() + " and " + pair.getValue());<br />
      }<br />
   }</p>
<p>The above example is relatively contrived, but could be argued to be a most effective use of <code>Pair</code> because, in that particular example, it really is a "pair" concept being represented. One of the biggest complaints about adding <code>Pair</code> to the SDK or using it in general is that it is not named specific enough to cover the business purpose for an object's existence. I actually had thought about using the JavaFX <code>Pair</code> class when I wrote my Christmas Tree example for the post <a href="http://marxsoftware.blogspot.com/2011/12/javafx-20-christmas-tree-javafx-20.html" rel="nofollow">JavaFX 2.0 Christmas Tree (JavaFX 2.0 Shapes)</a>. I ended up deciding against this and used a more appropriately-named nested <code>Coordinate</code> class. However, I could have easily used <code>Pair</code> in that example. The next code listing contains that very example with the nested <code>Coordinate</code> class removed and references to it replaced by <code>Pair</code>.</p>
<p>package dustin.examples;</p>
<p>import javafx.application.Application;<br />
import javafx.event.EventHandler;<br />
import javafx.scene.Group;<br />
import javafx.scene.Scene;<br />
import javafx.scene.effect.Glow;<br />
import javafx.scene.input.MouseEvent;<br />
import javafx.scene.paint.Color;<br />
import javafx.scene.paint.Paint;<br />
import javafx.scene.shape.*;<br />
import javafx.scene.text.Font;<br />
import javafx.scene.text.Text;<br />
import javafx.stage.Stage;<br />
import javafx.util.Pair;</p>
<p>/**<br />
 * Simple example of using JavaFX 2.0's Path to create a simple Christmas tree.<br />
 *<br />
 * @author Dustin<br />
 */<br />
public class ChristmasTreePathWithPair extends Application<br />
{<br />
   /** Number of branches on Christmas tree. */<br />
   private final static int NUMBER_BRANCHES = 4;<br />
   /** X-coordinate of very top of Christmas tree. */<br />
   private final static int TOP_CENTER_X = 400;<br />
   /** Y-coordinate of very top of Christmas tree. */<br />
   private final static int TOP_CENTER_Y = 25;<br />
   /** Horizontal distance to end of each branch. */<br />
   private final static int DELTA_X = 125;<br />
   /** Vertical distance to end of each branch. */<br />
   private final static int DELTA_Y = 100;<br />
   /** Length of each branch as measured on bottom of branch. */<br />
   private final static int BRANCH_LENGTH = 75;<br />
   /** Width of tree stump. */<br />
   private final static int STUMP_WIDTH = 100;<br />
   /** Height of tree stump. */<br />
   private final static int STUMP_HEIGHT = 150;<br />
   /** X-coordinate of top left corner of tree stump. */<br />
   private final static int LEFT_STUMP_X = TOP_CENTER_X - STUMP_WIDTH/2;<br />
   /** Y-coordinate of top left corner of tree stump. */<br />
   private final static int LEFT_STUMP_Y = TOP_CENTER_Y + DELTA_Y * NUMBER_BRANCHES;<br />
   /** Width of Christmas tree bottom. */<br />
   private final static int TREE_BOTTOM_WIDTH = (DELTA_X-BRANCH_LENGTH) * NUMBER_BRANCHES * 2;</p>
<p>   /**<br />
    * Draw left side of the Christmas tree from top to bottom.<br />
    *<br />
    * @param path Path for left side of Christmas tree to be added to.<br />
    * @param startingX X portion of the starting coordinate.<br />
    * @param startingY Y portion of the starting coordinate.<br />
    * @return Coordinate with x and y values.<br />
    */<br />
   private Pair&lt;Integer, Integer&gt; drawLeftSide(<br />
      final Path path, final int startingX, final int startingY)<br />
   {<br />
      int coordX = startingX - DELTA_X;<br />
      int coordY = startingY + DELTA_Y;<br />
      final LineTo topLeft = new LineTo(coordX, coordY);<br />
      path.getElements().add(topLeft);</p>
<p>      coordX += BRANCH_LENGTH;<br />
      final LineTo topLeftHorizontal = new LineTo(coordX, coordY);<br />
      path.getElements().add(topLeftHorizontal);</p>
<p>      coordX -= DELTA_X;<br />
      coordY += DELTA_Y;<br />
      final LineTo secondLeft = new LineTo(coordX, coordY);<br />
      path.getElements().add(secondLeft);</p>
<p>      coordX += BRANCH_LENGTH;<br />
      final LineTo secondLeftHorizontal = new LineTo(coordX, coordY);<br />
      path.getElements().add(secondLeftHorizontal);</p>
<p>      coordX -= DELTA_X;<br />
      coordY += DELTA_Y;<br />
      final LineTo thirdLeft = new LineTo(coordX, coordY);<br />
      path.getElements().add(thirdLeft);</p>
<p>      coordX += BRANCH_LENGTH;<br />
      final LineTo thirdLeftHorizontal = new LineTo(coordX, coordY);<br />
      path.getElements().add(thirdLeftHorizontal);</p>
<p>      coordX -= DELTA_X;<br />
      coordY += DELTA_Y;<br />
      final LineTo fourthLeft = new LineTo(coordX, coordY);<br />
      path.getElements().add(fourthLeft);</p>
<p>      coordX += BRANCH_LENGTH;<br />
      final LineTo fourthLeftHorizontal = new LineTo(coordX, coordY);<br />
      path.getElements().add(fourthLeftHorizontal);</p>
<p>      return new Pair(coordX, coordY);<br />
   }</p>
<p>   /**<br />
    * Draw right side of the Christmas tree from bottom to top.<br />
    *<br />
    * @param path Path for right side of Christmas tree to be added to.<br />
    * @param startingX X portion of the starting coordinate.<br />
    * @param startingY Y portion of the starting coordinate.<br />
    * @return Coordinate with x and y values.<br />
    */<br />
   private Pair&lt;Integer, Integer&gt; drawRightSide(<br />
      final Path path, final int startingX, final int startingY)<br />
   {<br />
      int coordX = startingX + BRANCH_LENGTH;<br />
      int coordY = startingY;<br />
      final LineTo bottomHorizontal = new LineTo(coordX, coordY);<br />
      path.getElements().add(bottomHorizontal);</p>
<p>      coordX -= DELTA_X;<br />
      coordY -= DELTA_Y;<br />
      final LineTo bottomBranch = new LineTo(coordX, coordY);<br />
      path.getElements().add(bottomBranch);</p>
<p>      coordX += BRANCH_LENGTH;<br />
      final LineTo secondHorizontal = new LineTo(coordX, coordY);<br />
      path.getElements().add(secondHorizontal);</p>
<p>      coordX -= DELTA_X;<br />
      coordY -= DELTA_Y;<br />
      final LineTo secondBottomBranch = new LineTo(coordX, coordY);<br />
      path.getElements().add(secondBottomBranch);</p>
<p>      coordX += BRANCH_LENGTH;<br />
      final LineTo thirdHorizontal = new LineTo(coordX, coordY);<br />
      path.getElements().add(thirdHorizontal);</p>
<p>      coordX -= DELTA_X;<br />
      coordY -= DELTA_Y;<br />
      final LineTo thirdBottomBranch = new LineTo(coordX, coordY);<br />
      path.getElements().add(thirdBottomBranch);</p>
<p>      coordX += BRANCH_LENGTH;<br />
      final LineTo fourthHorizontal = new LineTo(coordX, coordY);<br />
      path.getElements().add(fourthHorizontal);</p>
<p>      coordX -= DELTA_X;<br />
      coordY -= DELTA_Y;<br />
      final LineTo fourthBottomBranch = new LineTo(coordX, coordY);<br />
      path.getElements().add(fourthBottomBranch);</p>
<p>      return new Pair(coordX, coordY);<br />
   }</p>
<p>   /**<br />
    * Draw stump of tree.<br />
    *<br />
    * @return Path representing Christmas tree stump.<br />
    */<br />
   private Path buildStumpPath()<br />
   {<br />
      final Path path = new Path();</p>
<p>      int coordX = LEFT_STUMP_X;<br />
      int coordY = LEFT_STUMP_Y;<br />
      final MoveTo startingPoint = new MoveTo(coordX, coordY);<br />
      path.getElements().add(startingPoint);</p>
<p>      coordY += STUMP_HEIGHT;<br />
      final LineTo leftStumpSide = new LineTo(coordX, coordY);<br />
      path.getElements().add(leftStumpSide);</p>
<p>      coordX += STUMP_WIDTH;<br />
      final LineTo stumpBottom = new LineTo(coordX, coordY);<br />
      path.getElements().add(stumpBottom);</p>
<p>      coordY -= STUMP_HEIGHT;<br />
      final LineTo rightStumpSide = new LineTo(coordX, coordY);<br />
      path.getElements().add(rightStumpSide);</p>
<p>      coordX -= STUMP_WIDTH;<br />
      final LineTo topStump = new LineTo(coordX, coordY);<br />
      path.getElements().add(topStump);</p>
<p>      path.setFill(Color.BROWN);</p>
<p>      return path;<br />
   }</p>
<p>   /**<br />
    * Build the exterior path of a Christmas Tree.<br />
    *<br />
    * @return Path representing the exterior of a simple Christmas tree drawing.<br />
    */<br />
   private Path buildChristmasTreePath()<br />
   {<br />
      int coordX = TOP_CENTER_X;<br />
      int coordY = TOP_CENTER_Y;<br />
      final Path path = new Path();<br />
      final MoveTo startingPoint = new MoveTo(coordX, coordY);<br />
      path.getElements().add(startingPoint);</p>
<p>      final Pair&lt;Integer, Integer&gt; bottomLeft = drawLeftSide(path, coordX, coordY);<br />
      coordX = bottomLeft.getKey() + TREE_BOTTOM_WIDTH;<br />
      coordY = bottomLeft.getValue();</p>
<p>      final LineTo treeBottom = new LineTo(coordX, coordY);<br />
      path.getElements().add(treeBottom);</p>
<p>      drawRightSide(path, coordX, coordY);</p>
<p>      path.setFill(Color.GREEN);</p>
<p>      return path;<br />
   }</p>
<p>   /**<br />
    * Create a bulb based on provided parameters and associate a MouseEvent to<br />
    * it such that clicking on a bulb will increase its size and enable the glow<br />
    * effect.<br />
    *<br />
    * @param centerX X-coordinate of center of bulb.<br />
    * @param centerY Y-coordinate of center of bulb.<br />
    * @param radius Radius of bulb.<br />
    * @param paint Paint/color instance to be used for bulb.<br />
    * @return Christmas tree bulb with interactive support.<br />
    */<br />
   private Circle createInteractiveBulb(<br />
      final int centerX, final int centerY, final int radius, final Paint paint)<br />
   {<br />
      final Circle bulb = new Circle(centerX, centerY, radius, paint);<br />
      bulb.setOnMouseClicked(<br />
         new EventHandler&lt;MouseEvent&gt;()<br />
         {<br />
            @Override<br />
            public void handle(MouseEvent mouseEvent)<br />
            {<br />
               bulb.setEffect(new Glow(1.0));<br />
               bulb.setRadius(bulb.getRadius() + 5);<br />
            }<br />
         });<br />
      return bulb;<br />
   }</p>
<p>   /**<br />
    * Add colored circles (bulbs) to the provided Group.<br />
    *<br />
    * @param group Group to which 'bulbs' are to be added.<br />
    */<br />
   private void addBulbs(final Group group)<br />
   {<br />
      final Circle bulbOne = createInteractiveBulb(350,100,10, Color.RED);<br />
      group.getChildren().add(bulbOne);<br />
      final Circle bulbTwo = createInteractiveBulb(285,210,10, Color.YELLOW);<br />
      group.getChildren().add(bulbTwo);<br />
      final Circle bulbThree = createInteractiveBulb(325,300,10, Color.WHITE);<br />
      group.getChildren().add(bulbThree);<br />
      final Circle bulbFour = createInteractiveBulb(475,290,10, Color.BLUE);<br />
      group.getChildren().add(bulbFour);<br />
      final Circle bulbFive = createInteractiveBulb(380,150,10, Color.CADETBLUE);<br />
      group.getChildren().add(bulbFive);<br />
      final Circle bulbSix = createInteractiveBulb(550,390,10, Color.VIOLET);<br />
      group.getChildren().add(bulbSix);<br />
      final Circle bulbSeven = createInteractiveBulb(375,400,10, Color.GOLD);<br />
      group.getChildren().add(bulbSeven);<br />
      final Circle bulbEight = createInteractiveBulb(445,195,10, Color.SILVER);<br />
      group.getChildren().add(bulbEight);<br />
      final Circle bulbNine = createInteractiveBulb(220,385,10, Color.DARKSALMON);<br />
      group.getChildren().add(bulbNine);<br />
   }</p>
<p>   /**<br />
    * Add text portions to Christmas Tree group.<br />
    *<br />
    * @param group Group for text to be added to.<br />
    */<br />
   private void addText(final Group group)<br />
   {<br />
      final Text text1 = new Text(25, 125, "Merry\nChristmas!");<br />
      text1.setFill(Color.RED);<br />
      text1.setFont(Font.font(java.awt.Font.SERIF, 50));<br />
      group.getChildren().add(text1);</p>
<p>      final Text text2 = new Text(600, 150, "2011");<br />
      text2.setFill(Color.DARKGREEN);<br />
      text2.setFont(Font.font(java.awt.Font.SERIF, 75));<br />
      group.getChildren().add(text2);<br />
   }</p>
<p>   /**<br />
    * Starting method of JavaFX application.<br />
    *<br />
    * @param stage Primary stage.<br />
    * @throws Exception Thrown for exceptional circumstances.<br />
    */<br />
   @Override<br />
   public void start(final Stage stage) throws Exception<br />
   {<br />
      stage.setTitle("JavaFX 2.0: Christmas Tree 2011 (Pair)");<br />
      final Group rootGroup = new Group();<br />
      final Scene scene = new Scene(rootGroup, 800, 600, Color.WHITE);<br />
      stage.setScene(scene);<br />
      rootGroup.getChildren().add(buildChristmasTreePath());<br />
      rootGroup.getChildren().add(buildStumpPath());<br />
      addBulbs(rootGroup);<br />
      addText(rootGroup);<br />
      stage.show();<br />
   }</p>
<p>   /**<br />
    * Main function that kicks off this JavaFX demonstrative application.<br />
    *<br />
    * @param arguments Command-line arguments; none expected.<br />
    */<br />
   public static void main(final String[] arguments)<br />
   {<br />
      Application.launch(arguments);<br />
   }<br />
}</p>
<p>Removing the nested <code>Coordinate</code> class reduces the overall lines of code for the application, but argument against this is that <code>Pair</code> is not as readable or specific as <code>Coordinate</code> was. This example exemplifies what I typically do: make simple custom classes rather than using a generic <code>Pair</code>.</p>
<p>What's perhaps most interesting to me about JavaFX having a <code>Pair</code> class is the implication of this when one considers that JavaFX will likely be <a href="http://marxsoftware.blogspot.com/2011/10/javaone-2011-strategy-keynote.html" rel="nofollow">standardized</a> and made <a href="http://marxsoftware.blogspot.com/2011/10/coupling-of-javafxs-history-with.html" rel="nofollow">part of Java SE</a>. This <code>Pair</code> class could very well end up in the Java SDK as-is. Other options would be to include a standard <code>java.util.Pair</code> class as a replacement for the JavaFX version, to have both in the SDK (having more than one in the SDK itself), or to not add the new one and remove the JavaFX version. There are ramifications on maintenance of existing applications either way. Several people have commented that it is a code smell or feels dirty to use a <code>Pair</code> rather than a custom object pairing two attributes. It would probably only make things feel even dirtier to use an implied JavaFX-specific class (<a href="http://docs.oracle.com/javafx/2.0/api/javafx/util/Pair.html" rel="nofollow">javafx.util.Pair</a>) in code that has nothing to do with JavaFX or even with presentation or user interface.</p>
<p>Original posting available at <a href="http://marxsoftware.blogspot.com/" rel="nofollow">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p>
    ]]></content>
  </entry>
  <entry>
    <title>JavaFX 2&#039;s Tri-State CheckBox</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/8279" />
    <id>http://www.javaworld.com/community/node/8279</id>
    <published>2012-01-04T09:20:00-05:00</published>
    <updated>2012-01-04T10:00:22-05:00</updated>
    <author>
      <name>Dustin Marx</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><p><a href="http://javafx.com/roadmap/" rel="nofollow" rel="nofollow">JavaFX 2.0</a> provides the <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/CheckBox.html" rel="nofollow" rel="nofollow">CheckBox</a> (notice capital 'B' versus <a href="http://docs.oracle.com/javase/7/docs/api/java/awt/package-frame.html" rel="nofollow" rel="nofollow">AWT</a>'s <a href="http://docs.oracle.com/javase/7/docs/api/java/awt/Checkbox.html" rel="nofollow" rel="nofollow">Checkbox</a>'s lowercase 'b') control that supports three states ("undefined", "checked", and "unchecked").</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p><a href="http://javafx.com/roadmap/" rel="nofollow">JavaFX 2.0</a> provides the <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/CheckBox.html" rel="nofollow">CheckBox</a> (notice capital 'B' versus <a href="http://docs.oracle.com/javase/7/docs/api/java/awt/package-frame.html" rel="nofollow">AWT</a>'s <a href="http://docs.oracle.com/javase/7/docs/api/java/awt/Checkbox.html" rel="nofollow">Checkbox</a>'s lowercase 'b') control that supports three states ("undefined", "checked", and "unchecked"). The AWT <code>Checkbox</code> only supports two states (on/true or off/false), but JavaFX's <code>CheckBox</code> can optionally support three states. If one desires the JavaFX version to support three states (the third being indeterminate), this is done by invoking <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/CheckBox.html#allowIndeterminateProperty()" rel="nofollow">allowIndeterminateProperty()</a> on the <code>CheckBox</code> instance. Alternatively, <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/CheckBox.html#setAllowIndeterminate(boolean)" rel="nofollow">setAllowIndeterminate(boolean)</a> can be used to enable three states (passing it <code>true</code>) or only two states (passing it <code>false</code>).</p>
<p>The next code listing provides the source code for a simple JavaFX application that demonstrates the tri-state JavaFX <code>CheckBox</code> control. All the application does is to change the text associated with the <code>CheckBox</code> to indicate what state that <code>CheckBox</code> is in. As described in the <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/CheckBox.html" rel="nofollow">CheckBox's Javadoc documentation</a>, the three states of the <code>CheckBox</code> consist of "undefined" (indeterminate), "checked" (determinate and selected), or "unchecked" (determinate and not selected). This simple example boils these three states down to "determinate", "selected", and "unselected" and uses nested conditional <a href="http://marxsoftware.blogspot.com/2010/09/how-i-learned-to-stop-worrying-and-love.html" rel="nofollow">ternary operators</a> to set that String.</p>
<p><strong>CheckboxExample.java</strong></p>
<p>package dustin.examples;</p>
<p>import javafx.application.Application;<br />
import javafx.event.EventHandler;<br />
import javafx.scene.Group;<br />
import javafx.scene.Scene;<br />
import javafx.scene.control.CheckBox;<br />
import javafx.scene.control.CheckBoxBuilder;<br />
import javafx.scene.input.MouseEvent;<br />
import javafx.scene.paint.Color;<br />
import javafx.stage.Stage;</p>
<p>/**<br />
 * Simple example of JavaFX 2.0 Checkbox control.<br />
 *<br />
 * @author Dustin<br />
 */<br />
public class CheckboxExample extends Application<br />
{<br />
   /**<br />
    * Provides a checkbox instance with specified String and supporting three<br />
    * states (supporting indeterminate state).<br />
    *<br />
    * @param checkboxText Text to go with checkbox.<br />
    * @return Checkbox with text.<br />
    */<br />
   private CheckBox buildTriStateCheckbox(final String checkboxText)<br />
   {<br />
      // Note that AWT's Checkbox does not have capital 'b'<br />
      final CheckBox checkbox =<br />
         CheckBoxBuilder.create()<br />
                            .allowIndeterminate(true)<br />
                            .indeterminate(true)<br />
                            .prefHeight(50)<br />
                            .prefWidth(300)<br />
                            .text(checkboxText)<br />
                            .build();</p>
<p>      checkbox.setOnMouseClicked(<br />
         new EventHandler&lt;MouseEvent&gt;()<br />
         {<br />
            @Override<br />
            public void handle(final MouseEvent mouseEvent)<br />
            {<br />
               final String newText =<br />
                    checkbox.isIndeterminate()<br />
                  ? "Indeterminate!"<br />
                  : checkbox.isSelected() ? "Selected!": "Unselected!";<br />
               checkbox.setText(newText);<br />
            }<br />
         }<br />
      );<br />
      return checkbox;<br />
   }</p>
<p>   /**<br />
    * Overridden method defined in parent class and used in JavaFX application<br />
    * lifecycle.<br />
    *<br />
    * @param stage<br />
    * @throws Exception Exception during JavaFX sample application.<br />
    */<br />
   @Override<br />
   public void start(final Stage stage) throws Exception<br />
   {<br />
      stage.setTitle("JavaFX 2 Checkbox Demo");<br />
      final Group rootGroup = new Group();<br />
      rootGroup.getChildren().add(buildTriStateCheckbox("Tri-State CheckBox"));<br />
      final Scene scene = new Scene(rootGroup, 300, 50, Color.CADETBLUE);<br />
      stage.setScene(scene);<br />
      stage.show();<br />
   }</p>
<p>   /**<br />
    * Main function for running demonstration of JavaFX 2 Checkbox example.<br />
    *<br />
    * @param arguments Command-line arguments: none expected;<br />
    */<br />
   public static void main(final String[] arguments)<br />
   {<br />
      Application.launch(arguments);<br />
   }<br />
}</p>
<p>This is another all-Java example of JavaFX and it can be compiled with the normal <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html" rel="nofollow">Java compiler</a> (assuming JavaFX on the classpath) and executed with the normal <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html" rel="nofollow">Java application launcher</a> (again assuming JavaFX on the classpath). When executed it behaves as demonstrated in the following series of static snapshots. The first screen snapshot is its initial appearance with initially set text and the three images following that one indicate the changing of the state of the <code>CheckBox</code> as it is clicked on.</p>
<p><a href="http://2.bp.blogspot.com/-4KqMZ8p__dE/TwPuk1HZ9qI/AAAAAAAAC5U/oYn-nzlZqUI/s1600/initialViewOfCheckBoxExampleIndeterminate.png" imageanchor="1" rel="nofollow"></a></p>
<p><a href="http://1.bp.blogspot.com/-Jqv95oW1jrA/TwPupCAbu4I/AAAAAAAAC5g/xLs1qXiL008/s1600/secondViewOfCheckBoxExampleSelected.png" imageanchor="1" rel="nofollow"></a></p>
<p><a href="http://2.bp.blogspot.com/-Aixs483Iefc/TwPusa2rxaI/AAAAAAAAC5s/P7NgdtDi0Ec/s1600/thirdViewOfCheckBoxExampleUnselected.png" imageanchor="1" rel="nofollow"></a></p>
<p><a href="http://2.bp.blogspot.com/-zmBEKdbMkyA/TwPuv3jlM-I/AAAAAAAAC54/T0i4Q7RwBlY/s1600/fourthViewOfCheckBoxExampleIndeterminate.png" imageanchor="1" rel="nofollow"></a></p>
<p>The JavaFX 2 <a href="http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/CheckBox.html" rel="nofollow">CheckBox</a> class, like other JavaFX controls, provides significant more <a href="http://docs.oracle.com/javafx/2.0/ui_controls/checkbox.htm" rel="nofollow">styling flexibility</a> than the defaults I've shown here. The <code>CheckBox</code> is easy to use and can support two or three states as needed.</p>
<p>Original posting available at <a href="http://marxsoftware.blogspot.com/" rel="nofollow">http://marxsoftware.blogspot.com/</a> (Inspired by Actual Events)</p>
    ]]></content>
  </entry>
</feed>

