Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Local Development Environments How it Works The Java Virtual Machine

Dhruv Patel
Dhruv Patel
8,287 Points

CLASSPATHS -cp

Can someone please explain to me what a classpath is, I've explored around a lot and still don't know what it is.

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hi Dhruv!

A classpath essentially tells your program where to look for it's additional code. By default that is just the current directory. If you want it to look elsewhere, like in another folder, you need to specify that folder. It's very similar to PATH in most Operating Systems.

Does that help?

Matthew Francis
Matthew Francis
6,967 Points

Hey Craig,

I'm in the "IDE(InteliJ) Introduction", just referencing back.

With the video's code, do you know why you don't have to force a classpath in an IDE? but it is required to do so in the workspace so it does not return a "."?

  public static void main(String[] args) {
    System.out.printf("This is the classpath: %s %n",System.getProperty("java.class.path"));
  }
Dhruv Patel
Dhruv Patel
8,287 Points

Thank you for the answer Craig.

Craig Dennis
Craig Dennis
Treehouse Teacher

Glad it helped!

Keep at it!