Monday, September 6, 2010

What is JDK / How to Install it / Hello World Program

In this Post, We shall learn:

  1. What is JDK ?
  2. How do I install JDK on my machine?
  3. Execute - "Hello World" Program.
Here I go:
1) What is JDK?
The Java Development Kit (JDK) is a Sun Microsystems product aimed at Java developers. 
Since the introduction of Java, it has been by far the most widely used Java SDK
(SDK = Software Development Kit).

The JDK has as its primary components, a collection of programming tools; 
Here are a few (Actually these are the commands, which we have to use, to compile and execute our Java Programs) :
  • java – The loader for Java applications. This tool is an interpreter and can interpret the class files generated by the javac compiler.
  • javac – The compiler, which converts Source Code into Java bytecode  (Java bytecode is the form of instructions that the Java Virtual Machine (JVM) executes).  (JVM =  It is a platform independent Execution Environment that converts Java bytecode into machine code/language and executes it. Most programming languages compile source code directly into machine code/language, that is designed to run on a specific Microprocessor Architecture or Operating System. A JVM - a machine within a machine -- mimics a real Java processor, enabling Java bytecode to be executed as actions or operating system calls on any processor regardless of the operating system).
  • jar – The archiver, which packages related class libraries into a single JAR file.  (JAR file = Java ARchive ,aggregates many files into one).
  • javadoc – the documentation generator, which automatically generates documentation from your source code comments.
  • jdb – the debugger.

The JDK also comes with a complete Java Runtime Environment (It consists of a Java Virtual Machine and all of the class libraries).

JDK also include a wide selection of example programs. (Please find the examples, in the directory where you have install JDK).
______________________________________________________________________________________________
2) How do I install JDK on my machine?

Follow these simple steps:
  1. Click to visit the Site.
  2. Click on "Download" button (Just below - Download Java SE Development Kit 6u21).
  3. Select your Operating System (Platform) from the drop down list.(Ex: Windows).
  4. Hit "Continue" button. (No need to enter username/password).
  5. Search for  "jdk-6u21-windows-i586.exe"  and Click It (Approx size 75MB).
Once the download is over, double click to install the same:

The GUI is intuitive, should there be any doubts, please visit:

Please, note you need to set CLASS PATH in the environment variables (i.e add some settings to the Windows environment, so that the java compiler and runtime becomes available for compiling and running the java application).

Once done with all the steps mentioned, Then java environment is available for development. 
Open the dos prompt and type javac on the console, it should show the a brief report about java compiler.
______________________________________________________________________________________________

3) Execute - "Hello World" Program.

Steps:

1) Open any text editor (say - Notepad).

2) Type:   
   
        public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World\n");
                                                             }
                                              }
3) Save the file as a HelloWorld.java , 
4) Go to command prompt; To compile your source file, change your current directory to the directory where your file is located. 
5) Type: 
javac 
HelloWorld.java 
//The above command , compiles and generates a 
HelloWorld
.class file.
6) Now, execute the .class file using:
java 
HelloWorld  

Expected Output:
HelloWorld  

7) Should there be any confusion, please visit: 

Request: Any Comments/ Doubts, post in the Blog itself. 




No comments:

Post a Comment

Slides - Java Theory

Slides - Lab Programs