Sunday, February 20, 2011

Magnifying Hello World Application : Part One

(JDK Insight & -verbose option)
This is 2011 end of second month. We spent two months in this newly started year 2011. I’m glad this is my fist blog article in 2011.I would prefer to say welcome to 2011 even if 2011 is already started.Again,Welcome to the year 20eleven, everyone have their own plans to be executed. I wish all we could do better in this year 2011 with no regret of what mistakes we have done and what we missed in last year. 

Let’s get back to business, when you see the topic of this article you might feel how this guy magnifies the simple 5 lines of code programme. You might have dozen of intriguing questions blow in your mind, what is the story behind this simple programme? What a big deal, you might say to yourself "I have written this programme more than 10 times and then run without any error".Right good point, journey begins here. From way down to the deep end of the hello world programme, No choice I will show you how far this simple hello world programme goes

This is the code for HelloWorld programme in Java. I mentioned it below for you reference.

Short and sweet, it is simple programme which prints the ‘Hello World Java’ on the console. In order to run the Java programme you have to compile it to the byte code that is in HelloWorld.class file. Byte codes are instruction to the java virtual machine which executes the java programme. After that you run the programme invoking the java virtual machine by typing the ‘java’ command in the command prompt. Figure below shows the way you get the output through console.

So far so good, I guess that you would never get a chance to use the –verbose option with javac & java commands.This figure shows the output you get when you use -verbose option with javac command.

Things are getting complicated by now; being worried about what happens behind the sense will lead you to work out your brain a little bit. Simply have a look at the verbose output again. It shows that compiler begins to start parsing the source code then looking for classes which are used in your programme. You are able to find out what classes loaded form the screen shot of the verbose output.

It is obvious that you do have many questions in mind J; I will start from ground zero, java development kit (JDK) that you have installed before you begin the java programming has these directories. This diagram shows the folder structure of the JDK 1.5. 

  |           |                      |
 bin        lib                 jre
  |           |                 __|__________
java*     tools.jar      |                   |       
javac*    dt.jar      bin                 lib               
javap*                  |             ___ ___|___ __      
javah*               java*        |          |          |                 
javadoc*                       rt.jar      ext   security       
                               charsets.jar   |              /    \
                                  localedata.jar  server  client                                                                         

It is not that much important to understand entire folder structure but it is required to keep these points in mind.
  •  /jdk1.5.0/bin
    This folder contains the entire executables that are used in java development. PATH enlivenment variable should have access to this folder in order to run the executables.

  • /jdk1.5.0/lib
    This folder holds the files that is used by tools and utilities in java development kit. If you want more to know what this folder is up to, just give a try with a Google search.

  • /jdk1.5.0/jre/bin
    This folder contains all the executables & libraries which is used by Java platform. For an instance, java.exe is inside this folder that helps to lunch the java application

  • /jdk1.5.0/jre/lib
    Important, this folder is the heart of java platform. It has core java libraries, property files, and resource files used by java run time environment. The point you have to keep in your mind is, number one, rt.jar file is the place where the entire java platform core API resides. It is the base library in java platform. Most of the classes are loaded to java virtual machine for this jar file and another point is to remember, the charsets.jar file that used to convert characters.

  •  /jdk1.5.0/jre/bin/client
    I’m ashamed to say that if you don’t know this folder you don’t learn java going through the right path. You have heard enough and enough about java virtual machine and you might learn, it is the core component in Java platform and it gives the brightness to the java landscape with platform independence. Jvm.dll is the real component that runs your java byte code by means of mechanism interacting with operating system. What I need to point out is this folder contains the jvm.dll file which acts as a Java virtual machine. Depending on your JDK version you might have client version and the server version. It will be a separate topic in my blog ‘Client JVM vs. Server JVM’.

Here we go, now we are going to run the HelloWorld programme by using -verbose option. I included the part of output here. I hope that you will be eager to see rest of it by yourself.  You read that most of the core libraries are resides in rt.jar file. Now figure shows, by default JVM loads the minimum class libraries to run the java programme.  Don’t be hurry and don’t be worry things that you don’t know, let it go until you read the next article ‘Magnifying HelloWorld Part Two: JVM Insights’.

Up to now, you have used the magnifying glass to learn folder structure of the JDK & purpose of the each and every important directory in JDK then you find where jvm.dll file resides. Moreover Javac compiler option: -verbose shows you what happens when you compile source code. Don’t you think how long we come and how far we have to go? We came 30% of the HelloWorld magnification journey by clearing road blocks. Stay tuned we are 70% away…..!!. 

Enjoy your life and have a nice day.Stay tune to read the next article. 

  © Nuwan Arambage-"transcending verge of life"

No comments:

Post a Comment