Custom Search

Saturday 16 June 2012

How To Compile and Run Java Programs

Java is a powerful programming language.

You can divide Java into two main parts. The first part (the Java Virtual Machine) executes Java
programs. The second part (the Software Development Kit) is the set of tools used to develop Java
programs.
For execution, you need a compiled program and a Java Virtual Machine (JVM), which serves as the
intermediary between your program and the host computer. The JVM provides cross-platform
portability because your program will work on any JVM regardless of the operating system or
hardware involved. Of course, there are different versions (or editions) of the JVM, so in practice
some programs will require specific JVM versions. However, the idea is that one Java program can
run on many JVMs regardless of the operating system or computer hardware involved.


Steps for writing, compiling and running java programs on your computer


1.Write the code of the program in any text editor like Notepad.,etc.
2.Save that file in .java extention (eg:"MyFirst.java")
3.Save it anywhere on your computer (for convenience let us assume we save it in "D\myprograms\' folder 
         Now we need to compile the program,for that you need java development kit installed in your computer you can find it here http://www.oracle.com/technetwork/java/javase/downloads/index.html
4.Now run command prompt(short cut:win+R ,type cmd and press enter)
    you may see something like this






To change the drive simply type the drive name followed by a ' : '.
eg:    d:
press enter




 Now goto the folder where you have saved your java file
and copy the directory address as shown in below picture




In command prompt type

cd "directory address"
 to change the directory


eg:





Now goto the folder where you have installed the java development kit downloaded earlier
and goto the bin folder 
now copy the addresslike this


In command promt type
set path="paste the copied address"
shown here




now you have half way there
its the time for compiling our program
type the below code in cmd
javac yourprogramname.java
Note:Java is case sensitive you have to write the exact name of your program with care 
eg" 




if you find anything error rewrite your code
else you can run your program by typing this code
java yourprogramname
eg



Done...

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...