• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us

How to Set Classpath for Java in Windows and Linux

October 1, 2023 //  by Talha Malik

Classpath is considered one of the most significant parts of coding in Java. Before starting coding it is important to understand where the files are located, how the classes are fetched and where are the packages brought from. Classpath in Java is a list of directories that contain all the classes, user-defined classes, resources, and packages.

This write-up will illustrate a detailed procedure for setting up the classpath for Java in Linux and Windows.

Setting up Classpath for Java in Windows/Linux Operating Systems

The Classpath is responsible for loading the user-defined classes that do not belong to the Java platform, external libraries, etc. These classes are loaded using the Classpath. It is important to keep in mind that the path and classpath are two different aspects. The path in Java is responsible for getting the binary files from the CMD whereas the Classpath is responsible for getting the library files. 

Setting up the Classpath for Java in Windows Operating System

Below are the steps for setting the classpath for Java programming in the Windows operating system. These steps using the control panel in Windows will set the classpath for Java easily.

Step 1: Open the Control Panel

Navigate to the start menu, search for the control panel, and hit the “Enter” key or select the open button to launch the Control panel. Upon doing so, the below screen will appear.

Step 2: Open System Settings

Select the “System and Security” settings from the available options, as a result, the below-depicted window will emerge: 

Select the third option which is System.

Step 3: Click on Advanced Setting

After selecting the System option go to the Advanced setting option as depicted below.

Step 4: Move on Environment Variables

Now, navigate to the environment variables.

Step 5: Select System Variables.

In the System variable portion click on New.

Now, enter the variable name and the value of the variable which is basically the path where Java is present on your device.

Step 6: Close the Windows

Click OK and end the process.

Setting up the Classpath for Java in Linux Operating System

The steps below depict the implementation for setting the classpath in Java on Linux machines.

Step 1: Search for the Path

Locate the location/directory where Java is installed/located. Java is usually installed in /usr/lib/jvm.

Step 2: Set the Classpath

The second step involves the setting of the Classpath in etc/environment by the following statement:

sudo <editor name> /etc/environment

Step 3: Add Certain Lines

The below statements state whether the Classpath for Java has been set accurately or not.

JAVA_HOME = "/usr/lib/jvm/<java folder (eg. java-1.8.0-openjdk-amd64>)/bin"
export JAVA_HOME
CLASSPATH=".:/usr/lib/jvm/<java folder>/lib:/home/name/Desktop"
export CLASSPATH

This sums up the way to set the classpath for Java in Windows and Linux.

Conclusion

Open the control panel, select system and security settings, navigate to system settings, go to advanced Settings, navigate to the environment variables, move to the system variables, and set the classpath for Java. The Classpath is an important aspect that loads the user-defined classes which are not available in the Java platform. This article aids in setting the classpath for Java in Windows/Linux operating systems.

Category: Java

Previous Post: « How to Implement Multidimensional Array in Java
Next Post: How to Use Java Callable and Future for Asynchronous Processing »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Use Math.min() Method in Java?

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact