Paths java 64 bit

How to set Java Path and Classpath in Windows 7, 8 and Windows 10 — Tutorial

So, you just bought a new PC or Laptop with Windows 8 operating system, and wondering how to set PATH and Classpath on Windows 8; Or, you might have just upgraded your Windows 7 laptop to the professional edition of Windows 8 and looking to set JDK Path to compile Java programs. Not to worry, this is the second step for anyone who wants to learn Java programming. Of course, the first step is to install JDK. In this Java tutorial, we will see step by step guide to set Java PATH and CLASSPATH in the Windows 8 operating system. By the way, if you are learning Java in Windows 10 operating system, You should still be able to set the Java path and classpath in Windows 10 by following the steps given here, because navigation steps for modifying environment variables on Windows 10 and Windows 8 are almost same.

For absolutely Java beginners, It’s important to know What is Path Environment variable is and Why do you need to set Path for Java? PATH is an environment variable, which contains the location of executable or commands. When you type a command in the command prompt, Operating System like Windows 7 or Windows 8, looks PATH to find and execute that command.

Читайте также:  Редакторы кода html вывод

Actually, for running a Java program, you don’t need to set PATH because Windows 8 comes with bundled JRE which is sufficient for running Java applications. Setting PATH simply means including the JDK bin directory into the PATH environment variable.

You need to set PATH to compile Java source code and create Java class files. JDK bin directory contains javac and java commands to compile and run Java programs. CLASSPATH is a little different than Path and it’s used by JVM rather than Operating System to load classes at runtime.

I suggest reading the difference between Path and Classpath and How Classpath works in Java and to know more about these fundamental concepts.

And, If you are new to the Java world then I also recommend you go through The Complete Java MasterClass on Udemy to learn Java in a better and more structured way. This is one of the best and up-to-date courses to learn Java online.

Setting JDK Path and Classpath in Windows 7, 8 and Windows 10

This tutorial assumes that you know how to download and install JDK on Windows 8 machine. By the way, if you are an absolute beginner and just starting with Java, then it’s important to download the correct version of JDK based upon whether you are running a 32-bit or 64-bit version of Windows 8.

See how to install JDK 7 on Windows 8 operating system to learn more about installing JDK in Windows 7 and 8.

Once successfully installed, it’s time to set PATH and Classpath for Java. By the way, If you know how to set PATH in Windows XP, then this would be very easy for you.

Steps to set JDK Path and Classpath in Windows 7 and Windows 8

Before setting JDK Path, let’s first verify Type javac in command prompt in windows 8 and see the output, if you get javac is not recognized as an internal or external command, means JDK Path is not set.

  1. Confirm that PATH is not set for Java by typing javac in the command prompt.
  2. Open Control Panel and select System and Security
  3. Select System
  4. Select Advanced System Settings
  5. Select Environment Variables
  6. Select and Edit Path Environment variable
  7. Verify Java path by typing javac in command prompt

How to set PATH in Windows 8 operating System

How to set Classpath in Windows 8

How to set path in Windows 7

How to set Classpath in Windows 7 operating system

set path environment variable in windows 8 operating system

just type javac command, this time, you will see different output which shows various details of the java command rather than getting an earlier error. You can follow a similar process to set Classpath in Windows 8 as well.

But it’s not a good practice to use the CLASSPATH environment variable to run Java applications, instead, every Java application should use –classpath option to specify classpath. You can also see How Classpath works in Java for more details on Java Classpath.

Now you are ready to write Java code and compile and run them. Why not just try with the HelloWorld Java program . By the way, to know more about PATH and Classpath, which is essential for Java developers, See the following tutorials

  • Difference between JAVA_HOME and java.home
  • Difference between Path and Classpath in Java
  • Difference between overloading and overriding in Java
  • Top 10 Interview Questions on Abstract class and Interface
  • 20 questions on Java design pattern and Software Design
  • How to run Java program from the command line
  • How to create and execute JAR file in Java
  • How to remote debug Java program in Eclipse
  • Top 10 Object-Oriented Design Principles
  • Why Prefer Composition over Inheritance in Java
  • 5 Books and Courses to learn Object-Oriented Programming
  • 25 Software Design Interview Questions for Interviews
  • 5 Best Books to learn Software Architecture
  • My Favorite Courses to learn Software Architecture

Thanks for reading this Java tutorial so far. If you find this step-by-step guide to set Java Path and Classpath in Windows then please share it with your friends and colleagues.

Источник

PATH and CLASSPATH

This section explains how to use the PATH and CLASSPATH environment variables on Microsoft Windows, Solaris, and Linux. Consult the installation instructions included with your installation of the Java Development Kit (JDK) software bundle for current information.

After installing the software, the JDK directory will have the structure shown below.

The bin directory contains both the compiler and the launcher.

Update the PATH Environment Variable (Microsoft Windows)

You can run Java applications just fine without setting the PATH environment variable. Or, you can optionally set it as a convenience.

Set the PATH environment variable if you want to be able to conveniently run the executables ( javac.exe , java.exe , javadoc.exe , and so on) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable every time you run it, such as:

C:\Java\jdk1.7.0\bin\javac MyClass.java

The PATH environment variable is a series of directories separated by semicolons ( ; ). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should have only one bin directory for the JDK in the path at a time (those following the first are ignored), so if one is already present, you can update that particular entry.

The following is an example of a PATH environment variable:

C:\Java\jdk1.7.0\bin;C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem

It is useful to set the PATH environment variable permanently so it will persist after rebooting. To make a permanent change to the PATH variable, use the System icon in the Control Panel. The precise procedure varies depending on the version of Windows:

  1. Select Start, select Control Panel. double click System, and select the Advanced tab.
  2. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New .
  3. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
  1. From the desktop, right click the My Computer icon.
  2. Choose Properties from the context menu.
  3. Click the Advanced tab (Advanced system settings link in Vista).
  4. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New .
  5. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
  1. From the desktop, right click the Computer icon.
  2. Choose Properties from the context menu.
  3. Click the Advanced system settings link.
  4. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New .
  5. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Note: You may see a PATH environment variable similar to the following when editing it from the Control Panel:

%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

Variables enclosed in percentage signs ( % ) are existing environment variables. If one of these variables is listed in the Environment Variables window from the Control Panel (such as JAVA_HOME ), then you can edit its value. If it does not appear, then it is a special environment variable that the operating system has defined. For example, SystemRoot is the location of the Microsoft Windows system folder. To obtain the value of a environment variable, enter the following at a command prompt. (This example obtains the value of the SystemRoot environment variable):

Update the PATH Variable (Solaris and Linux)

You can run the JDK just fine without setting the PATH variable, or you can optionally set it as a convenience. However, you should set the path variable if you want to be able to run the executables ( javac , java , javadoc , and so on) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable every time you run it, such as:

% /usr/local/jdk1.7.0/bin/javac MyClass.java

To find out if the path is properly set, execute:

This will print the version of the java tool, if it can find it. If the version is old or you get the error java: Command not found, then the path is not properly set.

To set the path permanently, set the path in your startup file.

For C shell ( csh ), edit the startup file (~/.cshrc ):

set path=(/usr/local/jdk1.7.0/bin $path)

For bash , edit the startup file ( ~/.bashrc ):

PATH=/usr/local/jdk1.7.0/bin:$PATH export PATH

For ksh , the startup file is named by the environment variable, ENV . To set the path:

PATH=/usr/local/jdk1.7.0/bin:$PATH export PATH

For sh , edit the profile file ( ~/.profile ):

PATH=/usr/local/jdk1.7.0/bin:$PATH export PATH

Then load the startup file and verify that the path is set by repeating the java command:

% source ~/.cshrc % java -version

Checking the CLASSPATH variable (All platforms)

The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes. (Classes that are part of the JRE, JDK platform, and extensions should be defined through other means, such as the bootstrap class path or the extensions directory.)

The preferred way to specify the class path is by using the -cp command line switch. This allows the CLASSPATH to be set individually for each application without affecting other applications. Setting the CLASSPATH can be tricky and should be performed with care.

The default value of the class path is «.», meaning that only the current directory is searched. Specifying either the CLASSPATH variable or the -cp command line switch overrides this value.

To check whether CLASSPATH is set on Microsoft Windows NT/2000/XP, execute the following:

On Solaris or Linux, execute the following:

If CLASSPATH is not set you will get a CLASSPATH: Undefined variable error (Solaris or Linux) or simply %CLASSPATH% (Microsoft Windows NT/2000/XP).

To modify the CLASSPATH , use the same procedure you used for the PATH variable.

Class path wildcards allow you to include an entire directory of .jar files in the class path without explicitly naming them individually. For more information, including an explanation of class path wildcards, and a detailed description on how to clean up the CLASSPATH environment variable, see the Setting the Class Path technical note.

Previous page: Miscellaneous Methods in System
Next page: Questions and Exercises: The Platform Environment

Источник

Оцените статью