aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes javac and classpath doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "javac and classpath doubt" Watch "javac and classpath doubt" New topic
Author

javac and classpath doubt

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
javac only require .java files so where is classpath comes into picture with javac.

I have aways used Eclipse to test my java programs and hence i am finding it difficult to understand javac,classpath,java with packages.

Please provide few examples of these to understand them fully.

Thanks in advance.
Naveen Zed
Ranch Hand

Joined: Aug 11, 2006
Posts: 61
Here,
We have to understand one thing. While we are using objects they are all binded with respect to their package statement.If the objects(Which are said to be in .class files) outside the package also can be accessed by the current class which run by the JVM. So the compiler also not only see the objects in the current directory, but also verifies the loaded class which are required by the program. So, There should be a way to represent the classes which are not presently available in the visibile scope of Java compiler or even to JVM.For that java people provided a feature CLASSPATH. This is the main reason we wanted it.So while operaating with javac the compiler see the claaspath for .class files required for the current running program.
This is the main concept.But its very exhastive you have to go for java tutorials to find useful stuff you needed for CLASSPATH and related concepts.
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
Firstly objects comes into picture only @ runtime.
Secondly :

Under src directory :

Package temp : Temp.java and B.java
Package temp1 : Temp1.java

Temp.java :


Temp1.java :


B.java :


in order to compile Temp.java we will require Temp1.class file. Right?

1. C:\H(WORK~1\SCJP\SCJP_G~1\src>javac temp/Temp.java

2. C:\H(WORK~1\SCJP\SCJP_G~1\src>javac -classpath temp1 temp/Temp.java
temp/Temp.java:2: package temp1 does not exist
import temp1.Temp1;
^
temp/Temp.java:4: cannot find symbol
symbol: class Temp1
class Temp extends Temp1
^
temp/Temp.java:9: cannot find symbol
symbol : variable i
location: class temp.Temp
System.out.println("Hello World. i=" +i);
^
3 errors

What is wrong here ?
Naveen Zed
Ranch Hand

Joined: Aug 11, 2006
Posts: 61
Here a mistake coming at your import statement.otherwise you can even also give full path instead of giving barely as Temp1.
Naveen Zed
Ranch Hand

Joined: Aug 11, 2006
Posts: 61
Another thing here, your classpath statement erases the ccurrent classpath.So the current directly also you have to give in your classpath.
So try this statement

javac -classpath temp1;. temp\Temp.java

I think this will be OK.
 
Consider Paul's rocket mass heater.
 
subject: javac and classpath doubt