• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do i compile B.java?

 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose i have a directory xcom and inside i have a file called A.java class A{}
and in the xcom dir i also have B.java which is


now i am in my xcom directory on the command prompt

i compile A.java using javac A.java which compiles...but when i use javac B.java it doesnt? why ?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raju Champaklal wrote:but when i use javac B.java it doesnt? why ?


It wont help you to get the answare . tell us the exception or error that what you are getting.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot find symbol class A
public class B extends A

even though B.java and A.class are in the same directory then why cant B.java find A.class?
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raju Champaklal wrote:now i am in my xcom directory on the command prompt

Compile both fils from the parent directory of xcom directory...
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could not understood you....how can B.java compile from the parent dir when the source file is in the xcom dir

again

now do i compile both of them from xcom dir on the command...or the test dir? iam getting A class symbol not found error
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since class A is not in a package, then why have you put A.java in xcom directory?? Put A.java in test directory and compile both A.java and B.java from test directory...
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still no success
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raju Champaklal wrote:could not understood you....how can B.java compile from the parent dir when the source file is in the xcom dir

again

now do i compile both of them from xcom dir on the command...or the test dir? iam getting A class symbol not found error





try
C:\javaankur\foo\test>javac xcom/B.java
 
Sridhar Gudipalli
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

//save this file at C:\SCJPProj\com\sri\ASuperClass.java
package com.sri;
public class ASuperClass
{
ASuperClass(){
}
}

//save this file at C:\SCJPProj\com\sri\BSubClass.java
package com.sri;
public class BSubClass extends ASuperClass
{BSubClass(){
}
}

1) To compile all the files at once.
Open command prompt and navigate to C:\SCJPProj
javac -d . \com\sri\*.java

2) To compile BSubClass file
Open command prompt and navigate to C:\SCJPProj
javac -classpath C:\SCJPProj com\sri\BSubClass.java

Refer: http://java.sun.com/j2se/1.3/docs/tooldocs/win32/javac.html
 
Leonardo Carreira
Ranch Hand
Posts: 489
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you followed Sridhar's code, you could do as follow also to compile all java classes :
Assume that java files saved in this directory : C:\SCJPProj\com\sri\*.java

1.) Open command prompt //if you use Windows
2.) Navigate to root directory //assume that the root directory is C:/>
3.) in the command prompt type this :
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic