Tuesday, 23 September 2014


By the end of this article you will be able to 

1)Install java into your system

2)Create and Run (Execute ) a Java program by yourself.


Lets us first discuss about the java installation topic.

So, you people know that to run or execute your java programs in your system you need JDK (java)or Java Development Kit, which contain the necessary files useful to run programs in your system.

Oracle is the company which is developing the java jdk.

So to download jdk we need to go for oracle website which host java jdk for download.

Java JDK Downloading site details



As shown in above figure. You have to go to

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

And choose the appropriate version to download.

To know which version to install follow below steps:


 Go to my computer or right click on computer and then go for properties there you can see the windows version of your system.So, basing on that you can download the respective version from the site.

Downloading jdk 


                          Then you need to double click on the downloaded file. Then one pop up window will be displayed asking for permission to install in hard disk.Click OK then the installation process will start.click next option for next screens.




                          Then It will prompt you for jdk installation directory there you can leave it to install in default drive (i.e. max in c drive) or you can choose any other location you want.
And then after the jdk will be installed in your system.

Now you can go to the installed jdk folder and see the structure.

jdk Architecture

It will be like the above showed picture.

Now to tell the system that you have installed the java jdk and to run programs using this jdk 

follow these steps carefully.

Setting the path variable in windows:

1)Go to installed  jdk folder and copy the bin directory address as shown in below figure.

Copy the bin folder address



2)Go to computer and right click on it.

3)choose  properties option

4) then go for Advanced system settings at the left side of screen as shown below.

Go for Advanced system setting 


5)Then in the appeared window go to environment variables button.

Go for Environment Variables


6)in the shown window under user variables click on new .


7)Now in the first field enter path as shown in the above figure and in the second filed add the 
the path of your bin folder which is copied earlier.

8)click OK and then click OK in remaining screens as well.

That's it. Now you installed java in your system successfully.


Now you can check whether java is installed successfully or not in your system by following below steps.

Java installation check:

1)Go to start button.

2)Then in search type cmd.you will get command prompt .

3)clicking on command prompt will open it.

4)Then at the > symbol type   javac and click enter key in keyboard.

checking java installation



Then if it displays so much content as shown in the above figure, then that means java is installed in your system successfully.

congratulations you installed java successfully !.

Now lets create and execute java programs.


Creating and Executing Java Program:

1) open one text editor. For example notepad is a text editor.So open notepad.



2) In the notepad write the code you want if you know java progamming language or write the code as shown in the below figure. I will explain the whole program and its structure in the coming articles. For now just copy the code as shown in the below figure into the notepad file.


A simple java code to display Helloworld.



                    Here as you can see, I am writing one class with name Helloworld and in that class I am writing on main method in the method  I am writing one console print statement to display Helloworld message on console.I will clearly explain these in the next concepts.

3) Now, save this file in your jdk folder with name as Helloworld and with .java extension.
So your file name will be  Helloworld.java.So now our source file is ready.Note that our file name is similar to name  of the class which is public.Here Helloworld is the name of the class which is public in our source file, that is why we have saved the source file as Helloworld.java.Don't worry we will see this concept later.

 Executing the source file:


1)Go to command prompt

2) go to the jdk folder by typing the command as shown in the below figure

i.e if your jdk folder is in c directory just copy the jdk folder address and paste it after typing cd
ex: c:\>cd programing files\java\jdk

or else enter the driver name if you have installed jdk in other drives  and : ( colon)
ex: c:\>e:then it will change to e drive.

 then after that copy the jdk folder address where we have saved our source file.And paste it after typing cd space.And click enter.



Go to the folder where we have stored our file 



3) And now, type javac Helloworld.java.
here javac is compiler and Helloworld.java is our source file.So we are telling our computer to compile the Helloworld.java file with the compiler javac. If it is success it will display next line.Otherwise it will display the respective error.

4) Now our source file is compiled and the .class file is generated for us.You can check whether .class file is created or not by simply going to folder where we have stored the source file.And there we can fie a file Helloworld.class .This file is also called as byte code file. which contain only 0's and 1's.

5)Now we have to interpret and run this .class file.To do that go to command prompt and type 
java Helloworld.




Note that we should not give any extention after Helloword. Here the Helloworld is class file and java is the interpreter.So we are telling the machine that interpret and run the Helloworld class which is generated with java interpreter and display the output.

If there are no errors then  you can see Helloworld ! message on you console here command prompt.


Congratulations as you had written and executed your java program successfully.

Summary:

By reading this article you are able to understand the jdk architecture and also able to create , execute the java file successfully.

Thank you.
.

No comments:

Post a Comment