Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2008

Tip: Looking for answers? Try searching our database.

Question about the package directive

Thread view: 
I_Am_The_Walrus - 20 Apr 2008 01:16 GMT
I was reading a Java book tonight and it was talking about the
"package" directive.  I haven't seen it used anywhere.  Did it die
with one of the more recent versions or is it just obsolete but still
available?

Signature

* I am the walrus.                                                    *
* RLU 451587                                                          *
* Running Vista Ultimate SP1 and Ubuntu Gutsy Gibbon                  *
* Sea creatures unite and take back usenet http://improve-usenet.org/ *

Mark Space - 20 Apr 2008 02:32 GMT
> I was reading a Java book tonight and it was talking about the
> "package" directive.  I haven't seen it used anywhere.  Did it die
> with one of the more recent versions or is it just obsolete but still
> available?

<http://java.sun.com/javase/6/docs/api/overview-summary.html>

See all those things on the left hand side? Those are packages.

Why the heck would you think "package" isn't being used? It's used
everywhere.
Lew - 20 Apr 2008 04:04 GMT
>> I was reading a Java book tonight and it was talking about the
>> "package" directive.  I haven't seen it used anywhere.  Did it die
[quoted text clipped - 7 lines]
> Why the heck would you think "package" isn't being used? It's used
> everywhere.

'package' is one of the most fundamental keywords in the Java language.
Organization of classes into packages is at the heart of how Java organizes
libraries.

Signature

Lew

I_Am_The_Walrus - 20 Apr 2008 17:05 GMT
>> I was reading a Java book tonight and it was talking about the
>> "package" directive.  I haven't seen it used anywhere.  Did it die
[quoted text clipped - 7 lines]
> Why the heck would you think "package" isn't being used? It's used
> everywhere.

I was thinking about how stupid this question sounded last night after
I went to bed.  Of course "package" is still used, it's just that
the IDE's I use (i.e. Eclipse and Netbeans) tend to insert it
automatically for me, it doesn't make it in my view.

Sorry man...my bad.

Signature

* I am the walrus.                                                    *
* RLU 451587                                                          *
* Running Vista Ultimate SP1 and Ubuntu Gutsy Gibbon                  *
* Sea creatures unite and take back usenet http://improve-usenet.org/ *

Mark Space - 20 Apr 2008 19:59 GMT
> I was thinking about how stupid this question sounded last night after
> I went to bed.  Of course "package" is still used, it's just that
> the IDE's I use (i.e. Eclipse and Netbeans) tend to insert it
> automatically for me, it doesn't make it in my view.
>
> Sorry man...my bad.

No worries.  I think we've all made at least one post here that we
should have thought about a bit more.  I've made at least a couple
whoopers myself.  So you're in the same club now. Grab a chair, kick off
your shoes, grab a beer.  We're all human and we make mistakes.

(Well, except I think that robot spammer guys isn't human.  I hate him.)
I_Am_The_Walrus - 21 Apr 2008 01:33 GMT
>> I was thinking about how stupid this question sounded last night after
>> I went to bed.  Of course "package" is still used, it's just that
[quoted text clipped - 9 lines]
>
> (Well, except I think that robot spammer guys isn't human.  I hate him.)

Me thinks that my confuddling was compounded by the fact that the book
I was reading was written in the 1990's so that's why I figured what I
dun figured.  

We now return you to your regularly scheduled feeding at the zoo.

Signature

* I am the walrus.                                                    *
* RLU 451587                                                          *
* Running Vista Ultimate SP1 and Ubuntu Gutsy Gibbon                  *
* Sea creatures unite and take back usenet http://improve-usenet.org/ *

Mark Space - 21 Apr 2008 04:29 GMT
> Me thinks that my confuddling was compounded by the fact that the book
> I was reading was written in the 1990's so that's why I figured what I
> dun figured.  

Ah, well definitely get a newer book.  Java has evolved a lot.

Sun's online tutorials are good.  There's web site, www.javapassion.com 
which is excellent.  I recommend the latest edition of O'Reilly's
Learning Java.  Excellent beginning book.
I_Am_The_Walrus - 22 Apr 2008 00:53 GMT
>> Me thinks that my confuddling was compounded by the fact that the book
>> I was reading was written in the 1990's so that's why I figured what I
[quoted text clipped - 5 lines]
> which is excellent.  I recommend the latest edition of O'Reilly's
> Learning Java.  Excellent beginning book.

I have most of the more popular books, including the GOF book and Joshua Bloch's
excellent book.  But I like to vary my reading from time to time,
trying to see how each author(s) approaches the subject of learning
Java.  So far, Head First Java along with the aforementioned Sun
tutorial has proven to be the best for me.

Signature

* I am the walrus.                                                    *
* RLU 451587                                                          *
* Running Vista Ultimate SP1 and Ubuntu Gutsy Gibbon                  *
* Sea creatures unite and take back usenet http://improve-usenet.org/ *

Roedy Green - 24 Apr 2008 10:55 GMT
On 21 Apr 2008 23:53:03 GMT, I_Am_The_Walrus
<I_Am_The_Walrus@will_f_uup.invalid> wrote, quoted or indirectly
quoted someone who said :

>I have most of the more popular books, including the GOF book and Joshua Bloch's
>excellent book.  But I like to vary my reading from time to time,
>trying to see how each author(s) approaches the subject of learning
>Java.  So far, Head First Java along with the aforementioned Sun
>tutorial has proven to be the best for me.

I have heard several other people ethusiastically recommend that
series.

Ideally you skim the book before purchasing to make sure it has
examples that interest you, and are complete.  The book should have
the Goldilocks property of difficulty.  Picking one too easy or too
hard FOR YOU is a waste of money.

I have seen so many programmers with shelves of expensive books that
look completely unread.  An author like Peter van der Linden helps
keep you entertained -- a spoonful of whimsy to help the medicine go
down.

A good measure of the value of a book would be how wrinkled the spine
is. Check in a friend's house to see which ones they are.

There is now so much good material available free on the net, I have
much less reliance on textbooks.  I think however, you need at least
one decent text to get you started to make sure ALL the basics are
covered.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Patricia Shanahan - 24 Apr 2008 14:58 GMT
...
> Ideally you skim the book before purchasing to make sure it has
> examples that interest you, and are complete.  The book should have
> the Goldilocks property of difficulty.  Picking one too easy or too
> hard FOR YOU is a waste of money.
...

I do two checks when picking a book for self-education:

1. Read some pages near the start of the book. Reject, at least
temporarily, if I don't understand them. I may reconsider after reading
a more basic book on the same subject.

2. Dip into later chapters. Reject if they only cover material I already
understand.

The idea is that my knowledge of the subject should increase in the
process of reading the book.

Patricia
Stefan Ram - 24 Apr 2008 14:54 GMT
>Java.  So far, Head First Java along with the aforementioned Sun
>tutorial has proven to be the best for me.

 I have just looked at a single box on a page of »Head First
 Java«, which seems to contain significant errors.

 It claims »Statements end in a semicolon ;« and
 »A while loop runs everything within its block«
 in chapter 1 in »Bullet Points« near »Example of a while loop«.
Roedy Green - 27 Apr 2008 11:47 GMT
>  It claims »Statements end in a semicolon ;« and
>  »A while loop runs everything within its block«
>  in chapter 1 in »Bullet Points« near »Example of a while loop«.

Consider the audience.  That is perfectly adequate for a beginning
book.

You can't explain everything all at once (unless you are writing in
German).

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Lew - 27 Apr 2008 13:50 GMT
>>  It claims »Statements end in a semicolon ;« and
>>  »A while loop runs everything within its block«
[quoted text clipped - 5 lines]
> You can't explain everything all at once (unless you are writing in
> German).

So they have to lie?  All they had to do was pop the word "usually" in there.

Signature

Lew

Stefan Ram - 27 Apr 2008 14:07 GMT
>>It claims »Statements end in a semicolon ;« and
>>»A while loop runs everything within its block«
>>in chapter 1 in »Bullet Points« near »Example of a while loop«.
>Consider the audience. That is perfectly adequate for a
>beginning book.
>You can't explain everything all at once

 Using correct assertions here isn't more difficult:

     »Simple statements end in a semicolon.
     The block is a compound statement.
     A while loop might execute its statement several times.«

 The while loop already is a more complex statement. If the
 audience consists of absolute beginners in programming, it
 might appear too early in the book.

 In my classes, I take some time to introduce simple statements
 (expression statements) and blocks and then do several
 exercises related to them, so that everyone gets a firm grip
 of these concepts. So there is no need to make false claims.
 I even discuss the false belief that »all statements end in
 a semicolon« in an exercise, where the pupils are asked to
 review this statement.

 I often do not treat loops at all, or only when asked about
 them. For the audience I encounter when I am giving adult
 evening classes about Java, this book already is too fast and
 thus too difficult.
Roedy Green - 20 Apr 2008 11:06 GMT
On 20 Apr 2008 00:16:35 GMT, I_Am_The_Walrus
<I_Am_The_Walrus@will_f_uup.invalid> wrote, quoted or indirectly
quoted someone who said :

>I was reading a Java book tonight and it was talking about the
>"package" directive.  I haven't seen it used anywhere.  Did it die
>with one of the more recent versions or is it just obsolete but still
>available?

see http://mindprod.com/jgloss/package.html
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 20 Apr 2008 11:07 GMT
On 20 Apr 2008 00:16:35 GMT, I_Am_The_Walrus
<I_Am_The_Walrus@will_f_uup.invalid> wrote, quoted or indirectly
quoted someone who said :

>I was reading a Java book tonight and it was talking about the
>"package" directive.  I haven't seen it used anywhere.  Did it die
>with one of the more recent versions or is it just obsolete but still
>available?

In toy programs, the class is often not assigned a package. That is
why you may have seen import (of packages)  but not the package
keyword itself.

Look at any of Sun's code in the JDK. They will nearly always be
assigned to packages to help organise the code.

look in src.zip
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

xinxin - 20 Apr 2008 12:15 GMT
On 4月20日, 上午8时16分, I_Am_The_Walrus
> I was reading a Java book tonight and it was talking about the
> "package" directive.  I haven't seen it used anywhere.  Did it die
[quoted text clipped - 6 lines]
> * Running Vista Ultimate SP1 and Ubuntu Gutsy Gibbon                  *
> * Sea creatures unite and take back usenethttp://improve-usenet.org/*

learn java is  mainly to lerarn how  to  use package.the more you
learned,the more important the package is. you will fell so soon
rossum - 20 Apr 2008 13:10 GMT
>I was reading a Java book tonight and it was talking about the
>"package" directive.  I haven't seen it used anywhere.  Did it die
>with one of the more recent versions or is it just obsolete but still
>available?
The package directive appears at the start of most real world Java
source files, it indicates which package each source file belongs to.
When you are just starting Java you will see it rarely because the
small example programs in the books do not usually bother - each small
program concentrates on just one aspect of the language to make the
example easier to understand.

The package directive is the other side of the import statement.  When
you say "import java.util" that implies that somewhere there is a
group of source files that start "package java.util".  The import
statement will import all the classes in the files that are marked for
that package, i.e. all those files that start "package java.util".

It is far from obsolete and is very important when organising a large
project.

HTH

rossum
John W Kennedy - 22 Apr 2008 19:22 GMT
> I was reading a Java book tonight and it was talking about the
> "package" directive.  I haven't seen it used anywhere.  Did it die
> with one of the more recent versions or is it just obsolete but still
> available?

Sample programs normally exist in their own tiny little worlds, where
using the package statement only creates clutter. Real programs use
packages.

Signature

John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
  -- Charles Williams.  "Taliessin through Logres: Prelude"

Lew - 23 Apr 2008 02:57 GMT
>> I was reading a Java book tonight and it was talking about the
>> "package" directive.  I haven't seen it used anywhere.  Did it die
[quoted text clipped - 4 lines]
> using the package statement only creates clutter. Real programs use
> packages.

In fact, there are certain things that cannot be done if you stay within the
default (i.e., unnamed) package.  The JLS itself admonishes:
> For small programs and casual development, a package can be unnamed (§7.4.2)
> or have a simple name, but if code is to be widely distributed, unique package
> names should be chosen (§7.7).
<http://java.sun.com/docs/books/jls/third_edition/html/packages.html>

and

> Unnamed packages are provided by the Java platform principally for convenience
> when developing small or temporary applications or when just beginning
> development.
<http://java.sun.com/docs/books/jls/third_edition/html/packages.html#7.4.2>

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.