What is Classpath in Java? - Definition & Example

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next:

You're on a roll. Keep up the good work!

Take Quiz
Your next lesson will play in 10 seconds
  • 0:04 Which Path?
  • 0:22 Classpath
  • 0:53 When to Change
  • 2:08 Reset
  • 2:25 Lesson Summary
Save Save Save

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up

Speed Speed

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

Even computer languages need to know where to find things, including Java. The CLASSPATH variable lets Java know where to find class libraries. This lesson will define CLASSPATH and provide code examples for its use.

Which Path?

In this lesson, we'll explore a path many of us remember fondly - or didn't know existed. That path is the DOS prompt. Yes, the pre-Windows, command-line interface. In Windows, you can type Start -> Run and the keyword cmd to access it. It looks like this:

Command Prompt


CLASSPATH is actually an environment variable in Java, and tells Java applications and the Java Virtual Machine (JVM) where to find the libraries of classes. These include any that you have developed on your own. An environment variable is a global system variable, accessible by the computer's operating system (e.g., Windows). Other variables include COMPUTERNAME and USERNAME. In Java, CLASSPATH holds the list of Java class file directories and the JAR file, which is Java's delivered class library file.

When to Change

If you're trying to run a stand-alone Java program, you may find it necessary to change the CLASSPATH variable. When the program runs, Java's run-time system, called the interpreter, is working through your code. If it comes across a class name, it will look at each directory listed in the CLASSPATH variable. If it does not find the class name, it will error out.

We can set the value of CLASSPATH in DOS. The following example changes the variable to a local folder that we've created called CustomClasses; it's located in a folder on the C: drive called Java:

If you have your classes saved in a zip file, you can use the same command as above, except add the name of the zip file like this:

Java classpath zip file

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account