How to run a java code without an IDE


Hi friends today I’m going to explain how to run java program without an IDE, using command prompt on windows systems.

First of all you should code your program using a text editor such as notepad and save it as a java program, do not forget to set your file name exactly to same with java class.

 Here this is an example,

 

I coded my program in notepad and its class name is “a11” (I think you have a little knowledge about java basics)

And now im going to save my notepad document,
File name must be same with class so here you can see File name is a11.java, no need to confuse about file extension we are going to run a little java program. So it’s should be a java file.  In this tutorial I will save this file in a folder already I created on my desktop.

Well document saved, now what you have to do? Now you are ready to your java program. Mmmm wait before that you have few steps to do.

Hit windows key and type “cmd” on your start screen, or type on Cortana.

Now hit enter, or click on the command prompt, then you will see command prompt window,

This is the command prompt, (guys do not worry about the colors of your command prompt window usually it is black and light text. I have a special edition  J ha ha im kidding I just change colors because I like this way that’s all)
To access my file im going to open Desktop in my command prompt. To do this type this little command and hit the Enter key

cd Desktop

Well now you are in the Desktop, to access the folder type same command with your folder name, my folder name is My Java Works

Now you are in your folder that contain your java file before you saved.
Ok now we want to set the path to do this you have to go to the bin folder in the JDK installation directory
C:\Program Files\Java\jdk1.8.0_40
And open the bin folder, now copy the address in the address bar its look like this
“C:\Program Files\Java\jdk1.8.0_40\bin”
That’s all go back to the command prompt and paste the address you copied. (Remember you are not allow to use “ctrl+v” paste shortcut in command prompt.) So be kind to right click and select paste.
This is the command
Set path=”C:\Program Files\Java\jdk1.8.0_40\bin”;%setpath%

Nothing will happen so do not confuse, then set the class path
Type this command,
set classpath=“.;%classpath%     then hit enter


Well you completed setting paths, few more thing you have to do,
Now we can compile our java program this is the command,
Javac {filename. Extension} 
May be it will take 2 or 3 seconds depending on your java program nothing will pop out,
Now you can run your java program to do this type this command in your cmd,
java {file name without extension} and hit enter


This is the output of my java program

Ok guys thank you very much for reading this and I think if you didn’t know how to run java programs on command prompt, now you know J 

No comments: