dimanche mars 14, 2010

Hey Mark, we missed the point here !

I was recently watching Mark Reinhold's interview on Oracle Technology Network. Mark is Principal Engineer at Sun Oracle and works on OpenJDK and future Java SE releases.

The interview went over many different subjects around Java SE : projects coin (simplification), jigsaw (modularity), closures (...)  

Mark was also insisting on the many -ities of the Java platform : security, availability, scalability, readability, ...

One of my favorite is readability ! It is important to understand how a piece of code is expected to behave just by reading it.  This helps to reduce bugs when we write code and / or to easily catch bugs when reading code written by our peers.

Java SE 5, released about 5 years ago, introduced a feature called auto boxing, allowing to mix and match Java's primitive types (such as int, boolean, ...) with their Object counterpart (such as Integer, Boolean, ...)

The objective of autoboxing is to simplify code and increase readability and, as such, is a welcome addition. But the devil lies into the details.

The example of code below shows incoherent behavior introduced by auto boxing : 

Integer integer1 = 127;
Integer integer2 = 127;
System.out.println(integer1 == integer2); //true

Integer integer3 = 128;
Integer integer4 = 128;
System.out.println(integer3 == integer4); //false

You read it right : the first equality is true, while the second is false.

I would expect either both expressions to be false (Object references never must be compared for equality, my grand mother learned me) Or both expressions to be true (should auto boxing fullfil its promises). 

This weird behavior is caused by some compiler optimizations happening behind the scene.  When the compiler is auto boxing values between -127 and 127, it always reuse the same Object instance.  In our example, integer1 and integer2 are therefore references to the same Integer object, hence the first equality. 

For values outside of this (-127, 127) range, the compiler creates different Object instances for each reference, even when the values are identical.

We all learned that we should not use object references when comparing values, but auto boxing encourages us to write such code and when doing so, we end up with incoherent behaviors such as the one described above, which can make bugs very difficult to catch.

Hey Mark, if readability is really a concern : we missed the point with auto boxing !  

samedi févr. 06, 2010

Oracle + Kenai : clarifying the message ...

Last week, when publishing a serie of webcasts explaining the Oracle + Sun product strategy, Oracle clearly announced the end of Sun's sponsored source forge Kenai.com.

Today, Oracle sent a very different message to the community and recognized they poorly communicated about this.  To summarize it : current plans are to reuse Kenai.com infrastructure to power another Sun's sponsored source forge : java.net (hosting projects such as GlassFish, OpenSSO and OpenESB amongst others).

Communities and projects currently hosted on Kenai.com will be migrated to Java.net 

Is it really a poorly executed communication ?  Or does Oracle step back due to community feedback ?

Should the later be correct, this is a good sign that Oracle is (very) quickly learning how to deal with the many communities it inherits when acquiring Sun Microsystems. 

lundi févr. 01, 2010

Oracle + Sun : Java Developer Tools and Communities FAQ

Earlier today, Oracle posted a FAQ answering the most common questions regarding development tools and developer comunities.  It addresses questions about java.net, Kenai, GlassFish, NetBeans, JavaONE etc ...

This complements the previous Java Development tools FAQ posted last week. 

For more details about Oracle+Sun product strategy, you might have a look at the many webcasts available.

vendredi janv. 29, 2010

Oracle + Sun IDM Strategy

Since Oracle's Sun acquisition completed on January 27th, Oracle started a massive communication campaign to detail product's roadmap and integration.

Regarding Identity Management (IDM) products and technologies strategy and integration, you can view the full web cast (18 minutes) or just read through my summary below.

Directory (LDAP)

Authorization and Access Management

As with other products, Oracle will extend OpenSSO support until 2014 (for premium support) and 2017 (for extended support).

Provisioning

  1. Oracle Identity Manager is strategic
  2. Oracle Identity Manager will be enhances with functionality of Sun Identity Manager (mainly SPML provisioning)
  3. Oracle plans to create migration tools from Sun Identity Manager to Oracle Identity Manager 
  4. Sun Identity Manager will be renamed Oracle WaveSet

Compliance

Oracle + Sun SOA Strategy

Since Oracle's Sun acquisition completed on January 27th, Oracle started a massive communication campaign to detail product's roadmap and integration.

Regarding SOA products and technology strategy and integration, you can view the full web cast (17 minutes) or just read through my summary below.

Oracle will obviously continue to focus on it's Fusion Middleware offering, and more specifically, Oracle SOA Suite and Oracle Service Bus (formerly known as Aqualogic Service Bus from Bea).  This is the strategic SOA platform for the future.

  • Java CAPS will be maintained and improved for existing customers 
  • GlassFish ESB will continue as an open source project
  • Oracle plans to support collaboration between Java CAPS and Oracle SOA Suite through bridges technology, allowing to bring new features to Java CAPS such as SOA Governance, Workflow etc ...
  • Oracle expects to integrate key features of Java CAPS into Oracle SOA Suite 

Oracle also extends the End of Support dead line for SRE 5.0.5, eGate 4.5.3, GlassFish ESB 2.1 and Java CAPS 6.2  to January 2014 (premium support) or Jan 2017 (extended support) 

As always, Oracle also proposes a lifetime sustaining support.

By the way, for those of you wanted to start with Oracle's SOA Suite, my colleague Patrice just published an excellent three-parts tutorial in addition to the material published by Oracle.

mercredi janv. 13, 2010

Java European Roadshow

Java European Roadshow, coming to a city near you ....

Join us to get an insight into recent trends, strategies and applications in the areas of Java and Java for Business. Learn how to keep your Java applications safe, reliable and secure and how to get the best out of your current Java platform, be it embedded, standard or enterprise edition, or Real-Time Java.

Meet and discuss with Sun experts David Hofert, Simon Ritter, Steve Elliott, Alexis Moussine-Pouchkine and others.

Register today !

mardi janv. 12, 2010

Java EE 6 online code camp is starting today

The first online Java EE 6 code camp is starting today, it is not too late to register.

The objectives of this code camp is to let you practice and code, code, code using key Java EE 6 technologies.

Online mentors (top notches guys from the Java community) will be available online to answer your questions.

One more thing : this is entirely free, so do not hesitate and register today

lundi juil. 27, 2009

JavaFX presentations and demo during our last JUG meeting

A couple of days ago, the Luxembourg Java User Group - YaJuG - and the Lorraine JUG held a last meeting before the holiday season.  They invited Simon Ritter and myself to talk about ademo JavaFX.

The meeting was organized on a boat (une péniche) usually dedicated for theatre performances

The slides are now posted on YaJuG's web site while Lorraine JUG posted some pictures on Picassa.

French local newspaper "Le Républicain Lorrain" wrote a short paper about this and even sent a photograph for the occasion (lower left of the page, in french !). 

lundi juin 15, 2009

Fun with JavaFX, how to subclass UI controls

While I was doing a JavaFX demo to a group of partners, someone asked the questions : "Does JavaFX provides more specialized UI controls, like SearchTextBox, Table etc ... ?"

As of today, JavaFX 1.2 proposes this list of controls and, of course, it is relatively easy to subclass these to get the behavior you want.

But I wondered how easy it really might be, so I tried.

My goal was to create a "Search Text Box", you know ?  These TextBoxes used in Apple's iTunes for example to clearly indicate that this control is to search.

It has a small glass in the front of the text area and a "cancel" button appears when text is typed to allow user to reset it's content in a click.

It took me a couple of hours to create it, here is the result on the right side. 

I basically extended JavaFX 1.2 TextBox control and added two groups :

  • One is the "Cancel" button, made of gray Circle and two Rectangles
  • The other is the glass, made of one Circle and one Rectangle

I positioned these inside the TextBox, relatively to the original control's size.

I added two callback functions to notify about possible events : new search text is available (onSearchItemAvailable) and search is reset (onResetSearch).

I finally struggled a little bit to find a way to prevent text to draw itself beneath these two icons.  It was solved using the skin's padding-left and padding-right CSS attributes (Thanks Philippe from Sun's Developpers Forum to point me in the right direction).

You can download the full source code here or you can start the test application directly from this page by clicking on the image below.

As usual, comments and remarks are welcome.



mardi mai 12, 2009

Next JUG Event : Java & Web Applications Security

The next YaJuG (the Luxembourg Java User Group) event will cover some security topics for Java developers :

  • How to  implement cryptography (encryption, key generation, signature, etc.) from within your Java applications
  • A review of the Java top-10 security breaches in your web applications.

More details and registration are available online.  Book your agendas : May, the 27th 2009

mardi mars 24, 2009

GlassFish Tools for Eclipse are available

Sun is making available GlassFish Tools for Eclipse (v0.9, final version to be release soon).  This is a pre-configured package containing Eclipse 3.4.1 alongside with GlassFish v2.1 and GlassFish v3 prelude and the required Eclipse plugins to effectively manage and deploy applications to GlassFish right from the IDE.

Q: Who is the target for this offering?
A: Developers or organizations that have already standardized on or prefer Eclipse over NetBeans.

Q: Why has Sun created this offering?
A: Sun has created a strong preference for GlassFish among NetBeans users. However, a large community of developers have chosen Eclipse as their IDE of choice.  Today those developers have to download open source products from multiple locations and configure them to work together (error prone), increasing the barrier to entry. This offering creates a positive feature-rich out-of-the-box experience for Eclipse developers. In additional, developers can now leverage the open source plugins created by competitive frameworks (Spring, SEAM, Hibernate, etc) within a GlassFish-focused IDE. This bundle will also improve the relationship between the community of Eclipse developers and Sun.

Q: Is Sun moving away from Netbeans towards Eclipse?
A: No. Sun is expanding its reach by embracing not just the NetBeans developer community, but also the Eclipse community. This is a consistent with Sun's strategy of using open source to "lower the barrier to entry" - in this case to a large developer community.

mercredi févr. 25, 2009

JavaFX within WebSpace Portlets

I am attending a WebSpace bootcamp this week, which gives me some extra time to discover Sun's new Identity Based Content Portal.

I couldn't resist to try to deploy my JavaFX PieChart application in a JSR 268 portlet.

Here is the result



Here are a few caveats / things to know

  • Use NetBeans' project properties on the JavaFX side to generate the required HTML and proper embedding of the JavaFX librairies. Choose “Run” category, then specify “Run in a browser”. This will generate the HTML for you

  • Create a Web Application / JSR 268 Portlet project and copy/paste the HTML from the previous step to the portlet view JSP

  • Deploy the WAR file using Web Space admin tool (the web based Control Panel – Plugin Installer)

  • Add the portlet to an organization / community / user page.

Be careful about the path to your JAR file, it must be downloadable from your client browser. WebSpace overwrites the main context-root “/” and redirects everything to its own pages. I was lazy and just pointed to a file:/// URL :-(

Have Fun !


lundi févr. 23, 2009

Create a reusable PieChart component with JavaFX - Part II

In my previous blog entry, I described how to build a reusable PieChart component with JavaFX.

In this blog entry, we will improve the component to make it visually more appealing :

  • we will add a small space between pieces of the pie

  • we will add a 3D like effect to the component

  • we will add behavior : when the user will move the mouse over one of the piece, it will slightly step outside the chart.

End result will be like this :

Before:

After:





The 3D effect

Let's start with the simplest modification, the 3D effect.

JavaFX does provide with many lightning effects that can be applied either to simple, individual component or to complete scene.
Many of these lightning effects create 3D like effects on the component they are applied.

To achieve the effect shown above, I just added a DistantLight effect to the component, as show below.

 public override function create(): Node {
    return Group {
       content: bind ARCS;
       effect: Lighting {
          light: DistantLight {
             azimuth: 225
             elevation: 60
          }
          surfaceScale: 3
       }
   }
}

The three first line are taken from my previous code. It creates a subclass of Node, for which the content is an array of ARC. Please read the previous blog entry to have details about this.

I added to the group an effect attribute. This attribute contains a Lighting instance which, in turn, contains a DistantLight lighting effect.

This is as simple as this, it will create the lighting and shadow effects to create the illusion of a 3D component.

Back to your Math basics

The other changes will require some math first ...

We want to move a piece of the chart outside the pie chart when the mouse is over it.

Moving an Arc is easy, JavaFX provides us with many transformations, including a simple TranslateTransformation that will move the Arc from a source coordinate (a,b) to a destination coordinate (x,y).

The source point is well known, it is the center of the PieChart component. How can we compute the destination point ?

The target point dependents on two factors : the direction where we will move the piece and the distance from the center where we want to stop.

For the direction, we will use the angle in the middle of the arc, i.e. (end angle – start angle) / 2

For the distance, we will use a percentage of the radius, 15% in this case (you might wonder how I found 15% ... it was using trial and mistake approach, 15% seems to give the best result, feel free to use whatever other value you like)

So, how can we compute the x,y point as destination of the Translate movement ? This is where we need to go back to our first grade math course - or – wikipedia :-) .

Any point on the circumference on a circle can be expressed with the following equation :

  • x = a + r cost t
  • y = b + r sin t

where (x,y) is the destination point, (a,b) is the source point, r is the radius of the circle and t the angle to (x,y) (aka the direction where we want to go)

Should I translate these equations to our PieChart component :

  • (a,b) is the center of the component

  • r is 15% of the component's radius

  • t is (end angle – start angle) / 2

All the values are known: x,y is easy to compute !

Apply the formula in JavaFX

Now than we know how to compute the destination point of an Arc, adding the Translate transformation is relatively easy.

Let's first define a couple of constants

 def ANIMATION_DURATION = 0.5s;
 def ANIMATION_DISTANCE = 0.15;

The distance is expressed as a percentage of the component's radius, while the duration is expressed in seconds.

Then, in the Arc component definition, add the onMouseEntered and onMouseExited method to apply the transformation.

def ARCS: Arc[] = bind for (angle in ANGLE_VALUES) {
   (...)

   var cos = Math.cos(Math.toRadians(0 - start - angle / 2));
   var sin = Math.sin(Math.toRadians(0 - start - angle / 2));
   Arc {
   (...)
   Code to define the Arc, see full code source in previous blog entry
   (...)

   onMouseEntered: function(e: MouseEvent):Void {
     //pie is moved to the outside of the circle
     //cfr Circle equations 
     var transTransition = TranslateTransition {
        duration: ANIMATION_DURATION
        node: ARCS[indexof angle]
        fromX: 0
        fromY: 0
        toX: (radius \*  ANIMATION_DISTANCE) \* cos;
        toY: (radius \*  ANIMATION_DISTANCE) \* sin;
     }
     transTransition.play();
   }
   onMouseExited: function(e: MouseEvent):Void {
      //piece if moved back to center
      var transTransition = TranslateTransition {
         duration: ANIMATION_DURATION
         node: ARCS[ indexof angle]
         toX: 0
         toY: 0
         fromX: (radius \*  ANIMATION_DISTANCE) \* cos;
         fromY: (radius \*  ANIMATION_DISTANCE) \* sin;
      }
      transTransition.play();
   }
 }
}

First, we compute the cos and sin values as they will be used in multiple places. We are using the java.lang.Math package for this. Note that these methods are expecting angles expressed in radians, not in degrees, hence the required conversion.

As their names implies, the onMouseEntered and onMouseExited function are called whenever the mouse enters or exists the Node where the functions are defined.

The code in these function creates a TranslateTransition object with the following properties:

  • duration: the duration to play the animation

  • node: the graphical component it applies to, in our case, the Arc we are currently building

  • fromX, fromY: the start of the transition (aka the center of the Pie Chart when the Arc is moving out)

  • toX, toY: the end coordinate of the transition, this is where we do apply our math formula : ( radius \* percentage) multiplied by cos or sin, for x and y respectively.

The last line actually starts playing the transformation.

The onMouseExited method only differs by the fact we switched the from and to coordinates.

Add a small line between the pieces

I noticed that PieCharts are prettier when individual slices are separated by a couple of pixels instead of being sticked together (if you are not convinced, check the “before” and “after” screenshots above).

I first implemented this by drawing smaller Arcs, i.e. using a start angle + 1 and an end angle – 1.  This technique gives indeed a small white line between the pieces, but the line is getting smaller and smaller towards the center of the Pie, as the center stays the same for all pieces.

To get the result I wanted, I shifted the whole piece away from the center by a couple of pixels.  Each piece needs to be shifted away in different directions.  Instead of giving x,y the coordinate of the center, I am using center + ...  and this is where our math basics are needed again.

We just need to apply the same equation to compute the x,y coordinate, slightly away from the center.  I chose 1% of the original radius as a distance from the center.

//center is adjusted in the direction
//of the pie to create a gap between pieces
centerX: center + (radius \* 0.01) \* cos
centerY: center + (radius \* 0.01) \* sin

The Final Touch

Now that we added a 3D like effect and a movement in and out when the mouse is over a piece of the chart ... let's add our final touch.

We will add a gentle Glow effect on a piece when the mouse is over it.

We will add a couple of lines of code in the onMouseEntered and onMouseExited created previously.

 //very discrete glow effect
 ARCS[ indexof angle]. effect = Glow {
   level: 0.1;
 }

level is set to 0.1 when the mouse enters the piece and set to 0 when the mouse leaves the piece.

Full source code is provided as a NetBeans project or you can start the test application directly from this page by clicking on the image below.


vendredi févr. 20, 2009

Luxembourg Java User Group - Fun with Lego, Wii and Bluetooth

Last Tuesday, the Luxembourg Java User group (YaJuG) held its first 2009 meeting and the agenda was quite fun.

The slides (in french) are available and the full video of the sessions will be posted soon.

A short, one minute, video overview of the evening is also published.


     


    lundi févr. 16, 2009

    Create a reusable PieChart component with JavaFX - Part I

    In my last blog entry, I described how to code asynchronous remote communications between a JavaFX application and a REST service.

    I used, as sample JavaFX application, a pie chart component.

    In this blog entry, I will explain how to build a PieChart, i.e. a reusable JavaFX class to be embedded in your own applications.

    This blog entry will be in two parts :

    • Part 1 will describe the basic of creating a Pie Chart component (this blog entry)

    • Part 2 will describe how to make the component nice looking by adding behavior and 3D effects (to be published soon)

    Before writing any piece of JavaFX code, you will need to download and install the JavaFX SDK, either standalone, either bundled with NetBeans IDE.

    As a component user, I would like a reusable component with an easy to use API that let me specify the following :

    • the values to be part pf the pie chart

    • the center and size of the component

    • the colors to be used

    These will be the public attributes that end users will be able to specify. Because I want the component to be easy to use, all these attributes (except the pie chart values) will have defaults, freeing component users to specify a value for each of these.

    The first draft of the code will therefore look like this :

    public class PieChartFX extends CustomNode { 
       public-init var colors = [ Color.rgb(83,130,161), Color.rgb(0,84,128), 
                                  Color.rgb(248,152,29), Color.rgb(194,205,0),
                                  Color.rgb(255,199,38), Color.rgb(253,185,19)];

       public-init var radius: Integer = 100;
       public-init var center = 125;
       public var values = [ 0.0 ];
    }

    The values are expressed as an array of values.

    center and radius are self explaining

    The colors are expressed as an array of Color that will be used in a sequential order in the Pie.
    The default values for the colors are the one from the Sun Color Palette, feel free to replace with whatever makes sense for you.

    What makes a Pie ?

    Technically, drawing a Pie is very easy. A Pie is a set of Arc components, all having the same center and where the sum of Arc's angles is a full circle, i.e. 360 degrees.

    There are two main steps in your Pie drawing code

    • Step 1 : convert the array of (arbitrary) values to an array of values where the sum is 360, each value being proportional to the original array value. For example, when the component user is giving us [25, 50, 25] it will be converted to [90, 180, 90]
      This array will contain the angle values for each part of the Pie

    • Step 2: draw an Arc component of the given angle (see Step 1), starting at the angle where the previous Arc finished. Our code will need to count the sum of angles we've drawn so far.

    Actually, to make the drawing code easier, I chose to build two arrays : one to contain the angle values, the other to contain the start angle values.

    Code goes like this :

    //count the total values of the sequence
    var totalValue: Number = 0; 
    for (v in values) 
        totalValue += v; 
    var sum = 0.0; 

    //create array of ANGLE_VALUES, sum is 360, 
    //pondered by percentage of each value 
    for (v in values) { 
       var percentage: Number = (v / totalValue);
       var newAngle = 360 \* percentage;
       insert newAngle into ANGLE_VALUES;
       insert sum into START_VALUES;
       sum += newAngle;
    }

    Having these two arrays will make the drawing code itself extra simple : just walk through each of these arrays and create an Arc with the corresponding start angle, angle value and color.

    def ARCS : Arc[] = for (angle in ANGLE_VALUES ) {
       var start =  START_VALUES[ indexof angle]; 

       Arc {
          centerX:  center
          centerY:  center
          radiusX:  radius
          radiusY:  radius
          startAngle: start
          length: angle
          type: ArcType. ROUND
          fill: colors[(indexof angle) mod colors.size()]
       }
    }

    The code above will create an array of Arc instances, in the order of the values computed in the ANGLE_VALUES array. The colors will be using in the corresponding order of the colors array, going back (mod) to the first one when all colors have been used.

    Creating the component

    Classes that extends CustomNode must overwrite the create() method to actually return something displayable in a Scene.

    public override function create(): Node {
       return Group {
          content:  bind ARCS;
       }
    }

    In this code, we create a Group object made of our previously build array of Arc.

    Redrawing when values changes

    Wouldn't it be cool to have our Pie Chart to redraw itself automatically when the user change the array of values, either replacing values, removing some or inserting new ones ?

    JavaFX makes it very simple to code this type of behavior with two keywords : bind and on replace. Bind allows to link, at runtime, the value of a variable or attribute with the value of an expression. Each time the expression is changed, the value is recalculated and updated.
    On replace behaves like a trigger in a RDBMS, it allows to execute code when the value of a variable or attribute is changing.

    First, we want to recompute our angles when the values provided are changing.

      public var values = [ 0.0 ] on replace oldValue[firstIdx .. lastIdx] = newValues { ... }

    The code between { and } is the code listed above to compute ANGLE_VALUES and START_VALUES

    Secondly, I want my ARC array to be changed each time new values are provided. This is where the bind keyword is used, just replace the ARC definition listed above with

      def ARCS : Arc[] = bind for (angle in ANGLE_VALUES ) { ... }

    Using the component

    In your Main class, use the code below to actually create and display a PieChart

    Stage {
       title:  "Application title"
       width: 250
       height: 270
       scene: Scene {
          content: PieChartFX {
             values: [ 110, 50, 80, 10, 30] 
          }
       }
    }

    The end result is displayed below.



    My next blog entry will improve this component : we will add some 3D look and we will add code to slightly move a piece out of the PieChart when the mouse is over it.  Full source code will be provided.

    Stay Tuned !



    About

    Sébastien Stormacq is a Senior Software Architect at Sun Microsystems. He uses his 15+ years of professional experience to design large scale, secured and highly transactional architectures based on Sun's middleware solutions.

    Search

    Categories
    Archives
    « avril 2014
    lun.mar.mer.jeu.ven.sam.dim.
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
        
           
    Today