• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javac "an incomplete discussion"

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I lost the thread where this discussion was going on, but meanwhile left
without any final conclusion.

javac finds the needed source file and complies them as well with the main
source file.

I disagreed with that.

"javac -cp only finds class files. If the needed class file does not exist,
it gives compiler error."

What I know:
"Suppose Source A.java is using B's (public class) instance and methods so when you complile A.java, B.class must be present in order to compile A.java."

Is that right? Yes(OK)/No(Why?)

Thanks,
cmbhatt
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Follow through this:

Where did B.class come from?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Barry but I couldn't completely understand the code
provided by you!





Please elaborate!

Waiting...
cmbhatt
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which step is giving you difficulties? Were you able to do them all yourself?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright Barry! I got exactly what you did there!

My question is if B.class does not exist in the "two" directory,
and we try to compile A.java that is in the "one" directory,
would it also compile B.java that is in the "two" directory.
I know it is senseless question.


We must compile B.java before we can compile A.java, because
javac will search for B.class and not B.java.


We can do it in one line two like:

top>javac one/A.java two/B.java

italics is my doubt and bold is what it should be!

Guide me!!

Thanks,
cmbhatt
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would it also compile B.java that is in the "two" directory?


Well, that's what it did! I certainly did not compile it.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great Barry,

I did the same, and it worked. B.class automatically created in
"two" directory.

But if we give classpath (-cp) with javac, then what happens.


Thanks,
cmbhatt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic