• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

classpath

 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by mistake i wrote wrong in the post ONLY
I will update in the original post.
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import prg.com10.*;

This would lead to class, right???
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For some surprise reason ,everything is working fine now :!: :!:
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohh, it seems you are really confused here James.
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the confusion wont continue... Thank you for your time.
:?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic