This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes path and class path Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "path and class path" Watch "path and class path" New topic
Author

path and class path

dhanashree ghaskadbi
Greenhorn

Joined: Apr 26, 2001
Posts: 6
What is a path and classpath?
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
PATH and CLASSPATH are two Windows variables you set in AUTOEXEC.BAT to allow you to compile and run Java programs.
Setting PATH allows you to type

java KnightsTour
at the
C:\>
prompt, and run your class file KnightsTour.class. Without setting this PATH variable, you would have to type

jdk1.3\bin\java KnightsTour
at the C:\> prompt every time. (In this example, your PATH variable would have to contain "C:\jdk1.3\bin".)
Just as the PATH variable tells Windows where to look for the command you're passing to it ("java"), the CLASSPATH variable tells Java where to find the top level of class files you're passing to it. For example, I have my CLASSPATH set to "C:\Java\docs". So if I put a source file in my C:\Java\docs folder, I type
javac Source.java
, and Java knows to look for the file in C:\Java\docs. Say I have another source file, Source2.java, that I've indicated in my program lives in package com.artmetzer. Then, I need to do the following:
1) Create a folder called "com" in the existing folder C:\Java\docs.
2) Create a folder called "artmetzer" in the just-created folder C:\Java\docs\com.
3) Save Source2.java in C:\Java\docs\com\artmetzer.
4) At the MS-DOS prompt, I change directories to my classpath directory, C:\Java\docs.
4) At the MS-DOS prompt, since my PATH and CLASSPATH variables are set, I type at the

C:\Java\docs>
prompt

javac com\artmetzer\Source2.java
to compile Source2.java. Then, after it compiles successfully, I type at the

C:\Java\docs>
prompt

java com.artmetzer.Source2
to run the code in Source2.
Hope this helps, Dhanashree, and good luck.
Art
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: path and class path
 
Similar Threads
Javac task and Javac path
filereader
Scrabble... it only takes a minute...
PATH
path of Log4j jar in pom.xml was unable to read in Windows Vista ?