When you invoke javac, you need to provide a Java source file to be compiled. So from DirA, you can use...
javac DirB/B.java
It does not work when you try...
javac -cp DirB B.java
...because this is telling javac to compile B.java from the current directory (DirA), which fails because that's not where B.java is. The classpath flag only tells Java to find any additionalclasses it needs under DirB.
So from DirA, if you wanted to specify a classpath of DirB and compile B.java, you could use...
javac -cp DirB DirB/B.java
(PS: Are you sure you want to put your own subdirectories under a "bin" directory?)
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
here does it mean it will look for class file under DirB, if so what are the class file it will look for. Then it will compile B.java which is under DirB.
C:/DirA>java -cp DirB/B why cant we give like this, even this means look for B class file under DirB directory right???
Sorry if I am disturbing you asking the same question.
Sorry if I was confusing. I was just trying to show the difference between specifying a classpath and providing a path to the file you want to compile. So if you needed to do both, it could be done like this...
But in your case, you probably don't need a classpath, so you can just use...
C:/DirA>javac DirB/B.java
As for the second part of your question, C:/DirA>java -cp DirB/B will not work because you are not telling Java what class to run. All you are doing is providing a classpath of "DirB/B", where "B" would be interpreted as another directory.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org