This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How do i compile B.java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How do i compile B.java? " Watch "How do i compile B.java? " New topic
Author

How do i compile B.java?

Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
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 ?


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Dec 10, 2009
Posts: 521
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

Raju Champaklal wrote:now i am in my xcom directory on the command prompt

Compile both fils from the parent directory of xcom directory...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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

Joined: Dec 10, 2009
Posts: 521
still no success
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

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


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Sridhar Gudipalli
Ranch Hand

Joined: Nov 02, 2005
Posts: 120
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

Sridhar Gudipalli|SCJP 6.0
SCWCD objectives
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

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 :


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
 
jQuery in Action, 2nd edition
 
subject: How do i compile B.java?
 
Similar Threads
using classpath with javac Problem
SCJP chapter 10 : Development Classpath problem
Classpath Related Question
Classpath - Question 1
question from Kathy Seirra book classpaths