Monday Dec 01, 2008

One scene to other - JavaFX

Any middle or big application demands to change one window to other at some point of time. A window type of thing in JavaFX is represented by Scene and its each to switch between scene or to run multiple scenes.

Here is a small application in which clicking on image will put you in another window, written "Hello World" 

package sample6;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;

var s_new:Scene;
var s = Scene {
   content: [
       Text {
           font: Font {
               size: 24
           x: 10,
           y: 30
           content: "HelloWorld"

var s1 = Scene {
   content: [
       ImageView {
           image: Image {
               url: "{__DIR__}im2.PNG"
           onMouseClicked: function( e: MouseEvent ):Void {
               s_new = s;

s_new = s1;
Stage {
   title: "Application title"
   width: 250
   height: 280
   scene: bind s_new

So, its simple, on mouse click, I have bind a scene variable with a new scene. That's it !

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.


Friday Dec 07, 2007

OpenJDK Build on Netbeans with Windows / Solaris - Part IV

So its all done for Windows. Now coming on to Solaris, here the work is little less in compare to Windows(the same is valid for Linux as well, can be a excuse for me as I don't have Linux machine right now). Here is the list of downloads:

-> OpenJDK - Same link as mentioned in the previous blog (download the Solaris part, we have worked on Solaris x86)
-> Binary Plugin - Download from here.
-> CUPS Header - Download the latest cups from here.
NOTE: CUPS is Common Unix Printing System. It is doing a smart job of putting browser information into a printable format. I mean you don't have to worry about how printing is going to happen, it will be taken care by CUPS.
-> FreeType - Download from the same link provided in the previous blog. Any of the platform independent version will work for us.
-> jtreg - jtreg can be downloaded from the same link from where you are downloading OpenJDK. jtreg is a test suite that contains tons of testcase. Responsibility is to write a safe code and code change will not screw anything.

Thats it ! I am assuming that you have Netbeans 6+ and JDK 1.7 and JDK 1.6 binaries installed with you.

Now setting the file. Its very small in comparison to windows. Here it is:

// this is important because code contains many
//line which work on if(OPENJDK==true) code
OPENJDK=true \\

All done. Time to fire the build. More likely you will face the same problem what we have mentioned for Windows. If you are lucky enough then you will get the message "BUILD SUCCESSFUL"
(If I missed some step, please follow as it is in previous blog)

Sunday Dec 02, 2007

OpenJDK Build on Netbeans with Windows / Solaris - Part III

Now if you all set according to the last blog. This is/are the possible error(s) :

1. Error in make file : Multiple target \*\*\* . Yes, you need to downgrade the version of make file. "make.exe" resides in /cygwin/bin/make.exe. Check out its version, if its not 3.80, time to downgrade it. Download from here. Replace the make.exe of cygwin with this new make.exe ( make -version should be 3.80).
NOTE: make.exe is responsible to run make files. Makefiles are the one which contains instructions for a specific project, which file to compile and in which order.

2. Compilation error in - Try out Igor's solution
NOTE: Cygwin(make of Cygwin) still have some problem in understanding \\r character. So, this error may go with the upcoming binaries of Cygwin. One way is just remove \\r from the sh file - But then you will not get the proper file.

3. freetype.dll not found: Yes, freetype installation is  not creating any file like freetype.dll and this is surprising. If you investigate properly, you will get one file with name freetype.dll.a. Right now, lets rename it to freetype.dll(later we will check the problem of renaming this file)
NOTE: Just one line about freetype, it is providing uniform interface to access font files, support anti-aliasing as well.

4. I guess this is the main three error we came across. If anything else coming, then you need to check the installation of Cygwin again.  Errors like zip or tar.exe not found, means you have not installed the archive package of Cygwin.

Now if you are lucky enough, all things go fine and build will be ready. Again note that, jdk project module of Netbeans is only responsible for j2se build which mostly contains Java API not containing hotspot part. So, check the javac.exe and java.exe of your own openJDK build in the folder /openjdk/windows-i586/bin/.

5. Give a try to your Program. Ah it is running :-) cool. Now give a try on in which you are creating a Frame. If unluck you will get this error: not a proper dll file: freetype.dll. So, renaming is not actually working which we did in Error 2. Actually .a is a library achieve which is not a proper  file at this point. So, what to do ? Either find proper freetype.dll file from somewhere or take the source of freetype and compile it on .NET according to these rule.

Now its all yours. If you get any additional error, please let me know via comment or drop me a mail


Saturday Dec 01, 2007

OpenJDK Build on Netbeans with Windows / Solaris - Part II

Talking of some of the details about OpenJDK building(on Netbeans), we can start with Windows build(x86). In general,building on windows is tougher than Solaris/Linux because there are lot of dependencies on other tools and we can't set up the tools on network. Now lets see the list of the downloads required (don't abuse me, I know its too much :-))

- OpenJDK - Download open source JDK

- Binary Plugin - Download Binary Plugin 

We need to install binary of Java SE 6, which we can get from Sun site and Java SE 7 which we can download from

Now this is all about JDK downloads. Time to put hand into the dirty world of other dependent tools:

1. As we have lot of C++ code(native code) inside JDK, we need a C++ compiler. For windows, JDK document suggests to use .NET2003. Though we have made the build on .NET 2003 but I guess compiler of .NET 2003 is free on net and you can give one try with free compiler. Note here: Don't try with .NET 2005 as many of the API get deprecated.

2. Cygwin Installation: This is a area of concern. We have invested(wasted :D) 90 percent of the build time in this tool. Installing, uninstalling, reinstalling .. and  it keep on going. On the first installation page of Cygwin itself , you will get two options: Unix/Binary or Dos/Text. Any option can work, can't work depending on your luck :-). Most of the engineer suggested me to install Unix/Binary but Dos/Text worked for us :D. Download from: Cygwin Site

NOTE: Don't forget to download Developer, System, Utility, Archive  package of its full mode not the default mode.

3. Install Microsoft DirectX 9.0 SDK(Summer Package) - Download it from Microsoft site

4. Download and Install FindBugs and Ant

5. Download Microsoft Unicode Library

6. Download and install latest version of freetype from

7. Oops, if you don't have Netbeans 6 then download that also :)

Time to take a cup of coffee. Let the download to go on.

OK, back from coffee ...

Add Ant, Findbugs, Cygwin(till \\bin) in the path variable of system.  Open cmd, run vsvars32.bat (Micros~1.NET\\Common7\\Tools\\vsvars32.bat) to initialize the .NET variables. Run Netbeans.exe from the same command line.

Open openjdk/jdk/make/netbeans/ in netbeans and open project jdk. Open some of the important file like build.propertied and make.xml. In make.xml file, you will get the path of make, change it to the cygwin make file {cygwin/bin }.

Now IMPORTANT, get ready to write file:

// this is important because code contains many
//line which work on if(OPENJDK==true) code
// write the path in ~ format (dir /x)
ALT_COMPILER_PATH={MS.NET2003_PATH}/Vc7/bin \\    
ALT_MSDEVTOOLS_PATH= {MS.NET2003_PATH}/Common7/Tools/Bin \\
SHLVL=1 \\     

All Done ! Fire the build now, if you are lucky enough you will get it done in some 20-30 minutes. In the next blog, we are going to talk about the problem(s) with some of this software and version dependencies.

Friday Nov 30, 2007

OpenJDK Build on Netbeans with Windows / Solaris - Part I

Our team is ready with OpenJDK build for FOSS.IN, better to
say partially ready :). Me and Vikram is going to give the live demo about
building OpenJDK and how you can optimize the source code according to your own
need. For Example, if you don't like the default LookAndFeel of Java, change it according to
your like because now its your world, its your Java. Let me show you one simple
code change we have done with the gradient color. This
is the normal Ocean LookAndFeel of Java.

Before the code Change:


 After the code change:



Though building OpenJDK is little cumbersome process but come on, its a one time process. Just make the build ready once and then screw it as you want both on the Java level and on native level . Even more process and standard documents will come as OpenJDK goes into its maturity stage. You will love to know that Netbeans 5.5+ is giving a high class support for making OpenJDK across all platforms.

So for the real die-hard of Java, I am going to write Part II, III, ... upto N(covering some technicalities of building process) till I am not able to make you happy. Thanks to Igor and Sandeep who have replied my all shots of stupid questions.



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


« August 2016