Java TUTORIAL for beginners

As we had indicated, it is not a good idea to have your source code in the bin directory. You should create a new directory and keep your source files in that.

The problem with this approach is, the javac command line will not work, since the operating system will not know where is the exe file. There are two approaches to fix this issue. Let us say you created a directory called javatutorial, and you copied the file in C:\javatutorial

You can navigate to the javatutorial directory in dos and give the following comnands to compile and run

C:\javatutorial Program Files\Java\jdk1.7.0\bin>javac

C:\javatutorial Program Files\Java\jdk1.7.0\bin>java HelloWorld

Basically we are giving the full pathname where javac.exe and java.exe reside.

TO simplify the whole process, we can specify the path using a system varialble. To do so you right click "Computer" and select "properties" -> Advanced system settings -> Advanced -> Environment Variables. Under the "System variables" click on the variable that says Path and click Edit. Add the ; followed by the path where java is installed in the "variable value" ( it is typically C:\Program Files\Java\jdk1.7.0_17\bin). If there is no path variable, click on new in the System variable - give path in variable name and path where java is installed in the Variable value.

( An important caution - Many wesites ask you to add a new variable called path and give the path name of the place where java is installed. While it will still work we caution that it will render any older path invalid. So your older programs may not work properly. The best practice is to add path at the end. )

When you set the path variable the operating system looks for the binaries first in the current directory and then in the directory pointed by the path variable. This way we can invoke the java compiler from any directory we want.

If you are missing something in the path variable here is the step shown in youtube.