Solved

The Import

Posted on 2003-11-24
11
314 Views
Last Modified: 2010-04-01
I have observed the following

import  com.bruceeckel.simpletest.*;

I would like to know why is the above statement so structured? Would like as much details as possible.

Thanks and Regards,


ananda
0
Comment
Question by:a_tirtha
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9809582
http://mindprod.com/jgloss/import.html#IMPORT

Though that's java... in a JSP, it is:

<%@ page import="com.bruceeckel.simpletest.*" %>

Basically, it's telling the compiler you use classes in the com.bruceeckel.simpletest package...

Tim
0
 

Author Comment

by:a_tirtha
ID: 9809734
why this paggern "com.bruceeckel.simpletest" ?
0
 

Author Comment

by:a_tirtha
ID: 9809736
Correction
why this pattern "com.bruceeckel.simpletest" ?

Excuse for typographical mistake
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9809748
that's packages...

import java.awt.* ;

means "I'm going to be using classes inside the java.awt package"

import  com.bruceeckel.simpletest.* ;

means "I'm going to be using classes inside the com.bruceeckel.simpletest package"

This package is part of the book "Thinking in Java", by Bruce Eckel;

http://www.mindview.net/Books/TIJ/
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9809752
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:deepak_a
ID: 9815874
Simply put,
 "com.bruceeckel.simpletest " means
com is a folder inside which there is another folder called bruceeckel. Inside bruceeckel folder is ur java class called simpletest.
 So it is like u r telling ur compiler to go into the directory com then the subdirectory bruceeckel where the compiler will find the class simpletest.
 If instead of simpletest u specify *, u r telling the compiler to use all the files in com.bruceeckel.
0
 

Author Comment

by:a_tirtha
ID: 9815945
The comments so give me an idea that the statement is defined to access a package. It is really clear upto this poing.

Now!.  Simpletest is package that is a part of www.bruceeckel.com. Right!!!

Now someone please tell me the purpose/logic behind defining the statement as

import com.bruceeckel.simpletest.*;  

why is the web url referred with the "com" in the begining , followed by the "." and "Bruceeckle.packagename...."?  

0
 
LVL 1

Expert Comment

by:deepak_a
ID: 9816042
The package name import has got nothing to do with the web url. They are 2 totally different things and not related to each other at all.
The package name can be sumething like.
deepak.acharya.analyst.*;
Totally legal.
Generally in real life projects they do mention packages like com. this.that;
com stands for commerical/commerce.

But note. the package
com.bruceeckel.simpletest.*;   is in no way related to www.bruceeckel.com

www.bruceeckel.com is a website
and com.bruceeckel.simpletest.*; is a folder. The two are totally unrelated.
0
 
LVL 15

Accepted Solution

by:
jimmack earned 25 total points
ID: 9819148
I think the explanation you are looking for is as follows:

When packaging your Java code, you want to avoid having the same package names as anyone else (ie. your own package names should be unique).

The standard, easiest (and usually most reliable) way to achieve this is to use your own domain name, since no-one else should be using the same text in their package names.  Generally, the domain name is reversed because the importance of the domain elements reads from right to left (.com is the most significant part, bruceeckel is the next most significant etc., but you don't need to go all the way to "www" ;-)).


Some corrections/clarifications:

>> But note. the package
>> com.bruceeckel.simpletest.*;   is in no way related to www.bruceeckel.com

This isn't strictly speaking correct.  The two *are* related by the fact that Bruce Eckel (a very good author ;-)) relies on the fact that no-one else is going to be using his domain name for their package names.

>> and com.bruceeckel.simpletest.*; is a folder. The two are totally unrelated.
This is not a folder.  It is a package reference.  It just so happens that when you compile the code (with the -d option), the folders will be created to "mirror" the package reference.  Ideally, your source code tree (your .java files) should also mirror the target tree (where your .class files go), but this isn't *required*, just easier to maintain and understand ;-)
0
 

Author Comment

by:a_tirtha
ID: 9829491
Hello Jimmack,

Thanks a lot for you comments. It is of immence help and clarity.

Thanks again,

Ananda
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9830536
;-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now