Question:
what is class path in java?
lakshminarasimhan_n
2006-05-04 05:03:50 UTC
it is related with java technology.
Five answers:
anonymous
2006-05-04 05:05:06 UTC
The class path can be set using either the -classpath option when calling an SDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.
wd5gnr
2006-05-04 12:06:45 UTC
The classpath is where the Java virtual machine searches for class files. So when you name a class, its .class file has to be in a directory or jar file named in the classpath.



You can set the classpath via an environment variable or a command line option ot the JVM. Also, many IDEs let you set it using a GUI (but, of course, they then use one of the other two methods to do the dirty work).
hash
2006-05-04 12:14:10 UTC
dude dont worry about classpath and all

if u wanna set the path permanently here is the tip

right click on my comp-->properties

on advanced tab u wil have environment variables

open it

in the below box(system variables box) u wil have somethin like path just select it and ediit

and keep the entire path of the bin in the path variable at the end (ex:c:/java/bin) directory at the end and keep a semicolon

now logoff and login

open cmd

in that type in java -version

u shud get somethin like this

java version num

java TM

java hot spot

then ur done

bye dude
Rafter
2006-05-04 12:07:14 UTC
well to make ur programrum u need 2 set d path for its execytion..its called a classpath coz d command links d class file 2 d java compiler
marto
2006-05-04 12:23:03 UTC
The class path is the path that the Java runtime environment searches for classes and other resource files. The class search path (more commonly known by the shorter name, "class path") can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.

C:> sdkTool -classpath classpath1;classpath2...



-or-



C:> set CLASSPATH=classpath1;classpath2...



where:



sdkTool

A command-line tool, such as java, javac, javadoc, or apt. For a listing,



classpath1;classpath2

Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:

For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.

For .class files in an unnamed package, the class path ends with the directory that contains the .class files.

For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).

Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).



The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.



Classpath entries that are neither directories nor archives (.zip or .jar files) are ignored.



Description

The class path tells JDK tools and applications where to find third-party and user-defined classes -- that is, classes that are not Java extensions or part of the Java platform. The class path needs to find any classes you've compiled with the javac compiler -- its default is the current directory to conveniently enable those classes to be found.



The JDK, the JVM and other JDK tools find classes by searching the Java platform (bootstrap) classes, any extension classes, and the class path, in that order. (For details on the search strategy, see How Classes Are Found.) Class libraries for most applications will want to take advantage of the extensions mechanism. You only need to set the class path when you want to load a class that's (a) not in the current directory or in any of its subdirectories, and (b) not in a location specified by the extensions mechanism.



If you are upgrading from an older version of the JDK, your startup settings may include CLASSPATH settings that are no longer needed. You should remove any settings that are not application-specific, such as classes.zip. Some third-party applications that use the Java Virtual Machine may modify your CLASSPATH environment variable to include the libaries they use. Such settings can remain.



You can change the class path by using the JDK tools' -classpath option when you invoke the JVM or other JDK tools or by using the CLASSPATH environment variable. Using the -classpath option is preferred over setting CLASSPATH environment variable because you can set it individually for each application without affecting other applications and without other applications modifying its value.



Classes can be stored either in directories (folders) or in archive files. The Java platform classes are stored in rt.jar. For more details on archives and information on how the class path works, see Understanding the class path and package names near the end of this document.



Important Note: Some older versions of the JDK sofware included a /classes entry in the default class path. That directory exists for use by the JDK software, and should not be used for application classes. Application classes should be placed in a directory outside of the JDK directory hierarcy. That way, installing a new JDK does not force you to reinstall application classes. For compatibility with older versions, applications that use the /classes directory as a class library will run in the current version, but there is no guarantee that they will run in future versions


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...