javac and java -classpath concepts

1)Is there a way to set the classpath variable in both javac and java so that I do not need to convey it explicitly in the command line via navigating to the directory or as an arguement? For example, in Control Panel/System/Advanced/Environment Variables--User or System)

2)Is it true:  You only need to specify the entire package name after it has been compiled. (When running it) One only needs to provide the name of the when compiling if the are in the corresponding directory.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1) yes
set this environment variable
set CLASSPATH=you classpath
may be helpful
kellyputtyAuthor Commented:
The following is what I have set but javac and java don't "see" it:

What could I be doing incorrectly such that javac and java aren't "seeing" the environment variable CLASSPATH?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

type the command you use to run the class
1) Yes.

a)My Computer->Proprties->Advanced->Environment Variables

Add a system variable called CLASSPATH. Put the directories that you want there as the value of the variable.

b) As hoomanv said, set CLASSPATH=%CLASSPATH%;Your Classpath here.

2) Yes it is true.
2) If you have a class

javac is like


java is like

home>java a.b.c.D

cmd>set CLASSPATH=%CLASSPAHT%;C:\java\code

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sorry, a typo

cmd>set CLASSPATH=%CLASSPATH%;C:\java\code
kellyputtyAuthor Commented:
mrigank said:
My Computer->Proprties->Advanced->Environment Variables

Add a system variable called CLASSPATH

>>CLASSPATH=C:\java\code;C:\java\oreilly\examples;  (I have source code in both)
hoomany asked:
 type the command you use to run the class
But even the the CLASSPATH system variable is set, javac doesn't "see" it.
kellyputtyAuthor Commented:
mrigank, thank you that worked---
cmd>set CLASSPATH=%CLASSPATH%;C:\java\code

no worries.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.