Now we have to start usng it. For that go to start ,type cmd over there and press enter.A new window pop up titled command prompt.here type javac and press enter.Oops nothing worked rather a error echoed.This is because the cmd doesn't know where is this javac file(exe) is ? actually when we type such sommands in it cmd it searches for the file in it's default loaction.but since the javac is at diff. loaction so we have to add it's path in the default value of cmd. for thi follow the steps.
1.>go to desktop,right click on my computer go to properties.
2.>click advance system settings. then under advanced tab,click environment variables
now click on NEW(the upper side), Anew window will pop-up.filll "path" (without quotes) as variable name and fill
variable value with the following path:
C:\Program Files\Java\jdk1.6.0_20\bin
then press ok.
NOTE :dont add a new path in system vriables else many of commands will not work properly in cmd.
Now let us check whether it is installed properly or not.go to start type cmd and press enter.now type javac in the cmd window.if it gives a long list of commands cum help then u installed jdk successfully else wise you have done some mistake so go back in the beginning and start again.
now suppose i have a file "firstprog.java" in the test folder in C drive containig the following code=>
public class grapes {
public static void main(String args[]){
System.out.println("hello world");
}
}
Now in cmd type "cd /" which will bring you to root directory that is c:/ drive(fullform of cd is change directory). Now type "dir" which will list down all the sub-directories in that directory.
Now find the apropriate folder you are looking for which is test in our case so now type "cd test" in cmd which will bring you in test folder.
now to find java file again type "dir" which will list all the sub-directories and files.now type "javac firstprog.java" and press enter.
if no repy message or error so it means it have been converted into byte code and its .class file have been created
now to see the name of the .class file again type "dir". A new file named "grapes.class" have been created.now to execute it type "java grapes".and your output will be below this command.
0 comments:
Post a Comment