Solved

The Import

Posted on 2003-11-24
11
317 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

766 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