Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

path and class path

 
dhanashree ghaskadbi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a path and classpath?
 
Art Metzer
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic