• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do i compile B.java?

 
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
still no success
 
Ranch Hand
Posts: 400
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic