Sunday Sep 07, 2008

Sunday work - Tracing in FX and Blog Change :-)

 I did some fine tuning in my blog page after long time :-). I have added two more link in Links section, which can be helpful in :

1. Telling which JRE's are there on your machine(blog readers) machine.

2. And second will install the latest JRE(It will start installation directly, so careful :-D)

Alright, So now again one post for JavaFX. Finally I am able to write tracing path code in JavaFX. I have seen this in lot of Physics Motions where they show motion with tracing effect. Have a look at the output :

Here the ball is moving in a cosine fashion and so the trace. Easiest way to achieve this is to write code in update method. Have a look on the code, its small:

package tracemotion;

import javafx.scene.Node;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.application.Frame;
import javafx.application.Stage;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.scene.geometry.\*;
import javafx.scene.effect.\*;
import javafx.scene.paint.\*;

import java.lang.System;
import java.lang.Math;

var t : Number = 0.0;

Frame {
    var input : TracingBall = TracingBall {};
    stage : Stage {
        fill: Color.BLACK;
        content : bind [
    visible : true
    title : "Tracing Ball"
    width : 600
    height : 600
    closeAction : function() { java.lang.System.exit( 0 ); }

class TracingBall extends CustomNode {

    attribute tracingballs : Circle[];
    attribute length : Integer = 600;
    attribute timer : Timeline = Timeline {
        repeatCount: Timeline.INDEFINITE
        keyFrames :
            KeyFrame {
                time : 100ms
                action : function() {
                    t = t+0.3;
 public function update() : Void {
        for( i in [0..length - 30] ) {
            tracingballs[i].centerX = tracingballs[i+30].centerX;
            tracingballs[i].centerY = tracingballs[i+30].centerY;
            tracingballs[i].radius = tracingballs[i+30].radius;
        tracingballs[length] = Circle {
           centerX : bind(100 + t \* 30), 
           centerY : (300 + Math.cos(t) \* 100), 
           radius : 30, 
           fill : bind LinearGradient {
                    proportional: true
                    stops: [
                        Stop { offset: 0.0 color: Color.RED },
                        Stop { offset: 1.0 color: Color.GAINSBORO },
           opacity : 1.0 
 public function create(): Node {
        return Group {
            content : bind[tracingballs]   
 init {
        for( i in [0..length] ) {
            insert Circle { fill : bind LinearGradient {
                    proportional: true
                    stops: [
                        Stop { offset: 0.0 color: Color.RED },
                        Stop { offset: 1.0 color: Color.GAINSBORO },
                } into tracingballs;
Some lines in code are filling those fancy colors in ball(some lines are hard coded as well).I am a real bad guy in filling nice catchy colors(this color looks like a sun and a moon combination). Any comments/improvements are welcome !

Saturday Jun 14, 2008

Add JRE/ Run Old JRE - 6u10 :)

Yesterday, I have started making a presentation on J2SE 6u10. And I will be like delighted again seeing the new features of Plug-in which we called Next Generation Plug-in. Some of the common problems I used to face while doing my job :

Installation and Un-Installation of JRE's - This was a region of major concern. Most of the time I never install JDK or JRE, I love to untar or unzip it, so that it will not play with my registry. But the problem with those when I run Applet. Untar JDK/JRE not used to be a suitable candidate for applet because it takes only the installed JRE. But now, we can point our applet to the untared/unziped JRE and it will all work. Uncheck all the other JRE's which is not required, run the applet. It will all rock :)

I have clicked on the Find button and added the JRE 1.7. Now, I unchecked all the other JRE and ran my applet. It will run on JRE 1.7 (Remember IE6+ and FF3 or + only)

Here is the snap shot of old Java Control Panel:

And now we will also get rid of running applet on older installed JDK/JRE. Initially it used to be if I have to check one applet on 2 different JRE, I have to install and uninstall it again. But now it all work with one checkBox option :)

Thursday Mar 13, 2008

How many JRE on my Windows machine

Today we are doing some discussion on JRE and one of my friends Lawrence asked me a question "How to find how many JRE are installed on system by Java Code ? " Now I don't think Java have any such API which will tell how many JRE are installed on System and what are they ? But my another friend Vikram has a saying that JRE installation write information in Registry. And here I tried to write this code. It will only run on Windows :) because again I have used Runtime class. I would love to know how the same could be achieved in Unix Systems. This code is not doing anything, just do query from registry and reflectes the answer on the console. 

class NoofJRE {
static String REG_PATH = "reg query " +
    "\\"HKLM\\\\Software\\\\JavaSoft\\\\Java Runtime Environment";
  public static void  getJREInfo() {
    try {
    Process process = Runtime.getRuntime().exec(REG_PATH);
      InputStream inputstream = process.getInputStream();
      InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
      BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
      String line;
      while ((line = bufferedreader.readLine()) != null) {
    catch (Exception e) {
      System.out.println("I am in Exception");
  public static void main(String s[]) {

And here is my output:

E:\\Program Files\\Java\\jdk1.6.0\\bin>java NoofJRE
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment
    CurrentVersion      REG_SZ  1.6
    BrowserJavaVersion  REG_SZ  1.6.0_01
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.4.2_17
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6.0
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6.0_01

Which sounds true in my case. It is clearly telling me that I have JRE 1.4.2_17, 1.6.0 and 1.6.0_01. I have old bad habit on not uninstalling JRE's :). Please let me know if there is any other way to know how many and which JRE is/are installed in my system.

And to know where it is installed is also easy by querying  JAVA_HOME in registry value.



Vaibhav Hi, I am Vaibhav Choudhary working in Oracle with JDK team. This blog is all about simple concept of Java, JVM and JavaFX.


« February 2016