CLASSPATH

 

📌 The CLASSPATH in Java

What is CLASSPATH?

The CLASSPATH is an environment variable that tells the Java compiler (javac) and Java runtime (java) where to find:

  • User-defined classes and packages

  • External .jar libraries


🔍 Why Is CLASSPATH Important?

If your .class files or .jar files are not in the current directory, Java needs the CLASSPATH to locate them.


Setting the CLASSPATH Temporarily:


# Linux/Mac export CLASSPATH=/path/to/classes # Windows set CLASSPATH=C:\path\to\classes

Or use it while running the program:


java -cp . Test

-cp . tells Java to look for classes in the current directory (.).


⚠️ Common CLASSPATH Issues:

  • ClassNotFoundException” when the class isn’t in the path

  • Incorrect directory structure (package name must match folder name)

Comments

Popular posts from this blog

Object Oriented Programming PBCST304 KTU BTech CS Semester 3 2024 Scheme - Dr Binu V P

Introduction to Java Programming

Inheritance and Polymorphism