Wednesday 28 August 2013

Simple program development and execution


How to develop and run program through Command prompt.
first of all open notepad . write the code .
Development:-


save this program with .java extension. ex A.java.
always save the program by the class name.

Compilation and Running:-first of all you must set the path of bin folder.how we set the path. click here.
open command prompt.go to that location where you save your .java file.

write
>javac A.java //compilation.
>java A//running

by compiling .class file will be generated consist of byte code.
but it is not advisable to keep both .java and .class files in same folder.
so to place them in separate place we will use -d option during compilation.
now create 2 folders name source and class
in source folder save .java files and in class folder .class file will automatically generated during compile time.

Example:-create one folder named java under any drive suppose we take E: drive.
make two folder under java folder name source and class.
save your .java file in source folder.open command prompt go to E: drive
then go to java folder and then to source folder
write the command.
compilation:-
E:\java\source>javac  -d  ../class  A.java

where:-
-d is used to separate the files
..  indicates one directory back
/class means enters into class folder
A.java generate class file .
which generate under class folder.

Run
now goto class folder and write command.

E:\java\class>java  A
which display the output Hello World!

so by this you can keep your files in separate folder.




No comments :

Post a Comment