- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do we set the Java environment variable in cmd.exe?
When you install Java in your system first of all you need to set the environment variables which are path and class path.
PATH− The path environment variable is used to specify the set of directories which contains executional programs.
When you try to execute a program from command line, the operating system searches for the specified program in the current directly, if available, executes it.
In case the programs are not available in the current directory, operating system verifies in the set of directories specified in the ‘PATH’ environment variable.
You need to set path for compiler (javac.exe) and JVM(java.exe),which exists in the bin folder of the JDK.
CLASSPATH − The class path environment variable is used to specify the location of the classes and packages.
When we try to import classes and packages other that those that are available with Java Standard Library.
JVM verifies the current directly for them, if not available it verifies the set of directories specified in the ‘CLASSPATH’ environment variable.
The rt.jar file in the lib folder of JRE contains all the basic packages for Java therefore, you need to set classpath for this folder.
Setting environment variable from the command prompt
To set path −
- Open command prompt.
- Copy the location of the javac and java commands i.e. bin folder of JDK example: C:\Program Files\Java\jdk1.8.0_101\bin
- Using the SET command set the path variable in the command prompt as −
SET PATH=C:\Program Files\Java\jdk_version\bin
To set classpath −
- Open command prompt.
- Copy the location of the rt.jar file i.e. lib folder of JDK example: C:\Program Files\Java\jdk1.8.0_101\lib
- Using the SET command set the classpath variable in the command prompt as −
SET CLASSPATH= C:\Program Files\Java\jdk1.8.0_101\lib
- Related Articles
- How to set the GOPATH environment variable on Ubuntu?
- How to set python environment variable PYTHONPATH on Linux?
- How to set python environment variable PYTHONPATH on Mac?
- How to set python environment variable PYTHONPATH on Windows?
- What is JAVA_HOME variable in Java Environment?
- How do we declare variable in Python?
- How do we do variable formatting using the tag in HTML?
- How do we initialize a variable in C++?
- How to get the value of environment variable in Postman?
- How do I write variable names in Java?
- How do we print a variable at the MongoDB command prompt?
- How do we set text font in HTML?
- How do we set the type of element in HTML?
- How to set JAVA_HOME environment variables on Windows OS in Java?\n
- How to get environment variable value using PowerShell?
