aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "classpath" Watch "classpath" New topic
Author

classpath

James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

From K &B book, 799
Once a class is in a package, the package part of its fully qualified name is atomic—it can never be divided.
You can't split it up on the command line, and you can't split it up in an import statement.


what doe this quote mean???

This is my dir structure is ..
c:\prg\com10\test2.java
c:\prg\com11\test1.java

test2.java has the following statement,
package com10;

test1.java has the following statements..
package prg.com11;
import prg.com10.*;---------------------LINE 1

Does the above quote means that LINE 1 should be import com10.*;

:roll:


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
James Tharakan wrote:
Does the above quote means that LINE 1 should be import com10;


No, the quote means LINE 1 should be import com10.test2;

The class cannot be called just test2 or prg.com10.test2 since the package declaration is package com10;
It has to be called com10.test2


SCJP 6
How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

by mistake i wrote wrong in the post ONLY
I will update in the original post.
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
The above lines mean whenever you want to use any class that is in any package, you have to use its fully qualified name, means name with package.

You can do it in different styles:
1) Using import statement to import package, and use only class name in given class, as package name is available all over in given class.

2) If you run on command line, then you have to use fully qualified name as on command line there is no import statement for your relief.

suppose



Suppose I put this file in F:/ drive

//for compilation

F:\>javac -d . JamesTharakan.java

//for running
F:\>java javaranch.saloon.scjp.james.JamesTharakan
Hi I am James


I cannot use this :


F:\>cd javaranch/saloon/scjp/james


F:\javaranch\saloon\scjp\james>java JamesTharakan



I cannot do this also:
F:\>java -cp javaranch/saloon/scjp/james JamesTharakan


You understand what I am saying, you have to use fully qualified name of that class, that I used in first example.




SCJP 6
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

i have tried importing files couple of days back.i was sucessful that time. And what i understood that time is,
if class B want a class A which is in another package then...

the classpath+import statement should lead to the class A's package.
Correct me if wrong???
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
James Tharakan wrote:i have tried importing files couple of days back.i was sucessful that time. And what i understood that time is,
if class B want a class A which is in another package then...

the classpath+import statement should lead to the class A's package.
Correct me if wrong???


Yes you are right here. But bit change the classpath + import statement should lead to the class A, not its package.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

import prg.com10.*;

This would lead to class, right???
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
James Tharakan wrote:import prg.com10.*;

This would lead to class, right???


How did you define you class?

is it like this:



then only it will lead to class myclass.


James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

For some surprise reason ,everything is working fine now :!: :!:
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Ohh, it seems you are really confused here James.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

I guess the confusion wont continue... Thank you for your time.
:?
 
 
subject: classpath