Compiling multiple java classes in the dame directory in Windows XP command line

I have two classes one that uses the oher. The first file compiles without any problem, the second gives a compiler error that it doesn't not recognize the object type which has been defined in the first file.

The two files are in the same folder/directory, what am I doing wrong?


something like this

file 1:
------
public class boo
{
   public boo(int x)
...

}

file 2:
------
class usesboo
{
    boo x;
    public usesboo(int y)
...

}
polkadotAsked:
Who is Participating?
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.

CEHJCommented:
usesboo needs to be public
0
polkadotAuthor Commented:
yes it is public, that was a typo
0
polkadotAuthor Commented:
** correction

file 2:
------
public class usesboo
{
    boo x;
    public usesboo(int y)
...

}
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

CEHJCommented:
Try

javac *.java
0
polkadotAuthor Commented:
still getting "cannot find symbol" ... I've checked and rechecked spelling of the classes and made sure everything is public
0
CEHJCommented:
Can you post your *actual* code?
0
objectsCommented:
> still getting "cannot find symbol" ... I've checked and rechecked spelling of the classes and made sure everything is public

which line are you getting that
and what is the compete error
0
polkadotAuthor Commented:
getting "cannot find symbol" in file 2 on  statement boo x;

Sorry, I was wrong it does comiple with javac *.java with no problems... but is there any way to get the files to compile independently?

Id like to compile file1 first, then file2 ..
0
CEHJCommented:
>>Id like to compile file1 first, then file2 ..

Why so? You'd have to calculate their dependencies yourself and compile them in order (more effort than it's worth ;-))
0
objectsCommented:
should work:

javac -classpath . boo.java
javac -classpath . usesboo.java

(shouldn't actuially need the classpath)
0
polkadotAuthor Commented:
Okay, everything compiled and I got classes from all my java files now. There is one class with a main method MainProg.java and I'm trying to run it with the command ...

c:\java MainProg

Exception in thread main ... no classdef found error : MainProg


MainProg.class is in the same directory as the other java files and classes ... does this need a classpath too?

0
CEHJCommented:
try

java -cp MainProg
0
CEHJCommented:
Sorry -typo there:


java -cp . MainProg
0
polkadotAuthor Commented:
Okay it worked, but I don't remeber ever having to do this before on another system, why is it so differnt now?
0
objectsCommented:
If you clear yuor classpath it will work without that
if you have no classpath then . it used by default
0

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
Manikandan ThiagarajanSenior consultantCommented:
>>If you clear yuor classpath it will work without that.

set classpath=

this command is used to unset the classpath

0
hoomanvCommented:
if YourClass is in a package for example package test and you are already in C:\test
you'll be able to compile your code with "javac YourClass"
but you'll get a NoClassDefFoundError if you try "C:\test>java YourClass" within test folder
you need to get out of test (you are then in C:\) and then "C:\>javac test.YourClass"
or if you a were in D:\ you would use "D:\>java -cp D:\ test.A"
0
hoomanvCommented:
typo last line should be "D:\>java -cp C:\ test.YourClass "
0
Mayank SAssociate Director - Product EngineeringCommented:
0
Mayank SAssociate Director - Product EngineeringCommented:
BTW, have you heard of Ant?
0
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
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.