How to set path to execute JAVA program
Creating path for JDK
Before creating path you already need to install the JDK, click the given below link to see how to install JDK in you system.
" How to install JDK on system "
1. Creating Path with Environment Variables in system
The java programs outputs are executed in Command Prompt. For executing java programs we need to set path. Without path, we can't execute java programs.
If you want to execute a java program in cmd, initially you need to set the path like,
set path C:\Program Files\Java\Installed_java_version_name\bin
After that you need to execute a java program. Instead of setting path in cmd, every time. We can easily set the path in Windows.
- In Windows 10, in search bar, search for "Environment variables". In other OS, press "Winkey + R" the "Run" dialogue box will be open. In that, you can search for the "Environment variables".
- Select "Edit Environment variables".
- In that, choose "Edit Environment Variables" and click "OK"..
- Choose "Path" option from second dialogue box and click "Edit".
- In that click "New". An empty row will be created.
- Open your "This PC" or "My Computer" open like this
Local Disk (C) --> Program Files --> Java --> Installed_java_version_name --> bin
- Copy this location link from "Location bar" in you system.
- Paste this link in that empty row and click "OK".
- Close all the dialogue box by clicking "OK".
In end of this, we set the path correctly for the JDK.
2. Executing a Java program
For example, consider a java program has been stored in
Local Disk (D) --> Java --> Your_Java_Programs
- You can create your java program in any text editor. But, the file must be stored in extension of ".java".
- Open your library, where the programs were stored.
- In "Location bar", tap one time and type as "cmd". It will lead you to the command prompt with the directory, where you stored your programs in you system.
- For example, I have already created a java program with the name of addoftwo.java.
- Initially, we need to compile a java program to convert into the "*.class" file. After only the java program will be executed.
- Command "javac" is to compile java program to "*.class" file.
- During compiling is there any errors the cmd will be show the errors which occurred in the program.
- Command "java" is to execute java program.
If you have any doubts on this you can comment on the post or ask questions in contact form which is available in menu bar of the blog.
Comments
Post a Comment