File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Please Help Me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please Help Me" Watch "Please Help Me" New topic
Author

Please Help Me

Sean Magee
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
Hey Everyone!!!



I know this may be a bit too much to ask, but what do these exactly do? If there is a brief answer on this.

Also, if anyone has the time, can someone please tell me where and what this person is doing while using the util package in the following code.
Thanks in Advance!!






I just do not exactly understand how the util. package is being implemented here. Could the coder have used something else?? I know I can look in the java tutorial for such information, but sometimes the tutorial acan be a bit confusing to me at times. Thanks!

-Sean Magee

[ December 06, 2004: Message edited by: Sean Magee ]
[ December 06, 2004: Message edited by: Sean Magee ]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Sean:

Java Collections are a bit much to cover in a post on this bulletin board. I'm afraid you'll have to read that section in the tutorial. If you have any questions after reading it, be sure to get back to us.


Mike Gershman
SCJP 1.4, SCWCD in process
Sean Magee
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
I understand. Thank you. Is it too much to even briefly describe the relation of the package to this code posted above?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Are you just after the import and package syntax?

The package statement declares where this class resides in a name space. In most development setups the package structure equals the directory structure for the java files. Let's imagine the developers at Sun. Maybe they put all their source in a directory called "src", actually a fairly common practice. The util source code is then in a directory called "src/java/util". They also put the line "package java.util;" at the top of their source code.

Your class "Room" doesn't have a package statement. So if you're running your compiler in the "src" directory your "Room.java" is right there with you. That's perfectly legal, but not a great practice for anything but the smallest programs. If you organize your code in directories just make the package match the directory tree.

"import" tells the compiler where to find other classes, so when you use HashMap you have to add an import statement to help the compiler out. As an alternative, you could say "java.util.HashMap" every time instead of just "HashMap", but that's ugly extra typing.

The final part of the formula is classpath. If you go to "src" to compile and everything is in subdirectories from there then you don't have to worry about it. But if some of the source is in c:\my\src and some in c:\sun\src we need classpath. It's just a list of the root directories or jar or zip files to start searching in. You might set classpath c:\my\src;c:\sun\src to get files from either directory.

Was that the answer to the right question?
[ December 06, 2004: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Sean Magee
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
No, im sorry, it wasnt, but thank you.

For example what is


doing?

Also what is :

and at last

I just do not understand what EXACTLY is going on here, been looking at it for awhile trying to figure it out. If anyone can help, please, do.

FYI, I do understand the return statemnts and if statements etc.

What I do not understand is why .put nad .get are being used/
What is keys.iterator();iter.hasNext


[ December 06, 2004: Message edited by: Sean Magee ]
[ December 06, 2004: Message edited by: Sean Magee ]
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
Well a HashMap is a Map, which is to say that a 'key' has a corrosponding 'value', like a function. For instance, you could map football players' positions to names, so that Wide Reciever would map to Terrel Owens, and Quarterback would map to Donnovan McNabb. (E.A.G.L.E.S. EAGLES).

So:
When I say
HashMap players=new HashMap();, I create an empty hash map.

I can then say
players.put("Wide Reciever","Terrel Owens"); I have mapped "Wide Reciever" to "Terrel Owens"
players.put("Quarterback","Donnovan McNabb"); I have mapped "Quarterback" to "Donnovan McNabb".

I can now say:

String quarterback=map.get("Quarterback"); and quarterback will be set to "Donnovan McNabb".

Dig?

Note that any Object can be a key, and any Object can be a value, so you can map "D-line" to an ArrayList with the whole Defensive line.
(Picky people will point out that come java version 5, you don't even need these to be Objects. To them, I stick my tounge out and say, "5 ain't released yet!")

Maybe someone else will take up the topic of iterators now.
[ December 06, 2004: Message edited by: Nick George ]

I've heard it takes forever to grow a woman from the ground
Sean Magee
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
Thank You Nick. Ok got it.
So using a hash map is perfect for making a text based game like the one above. Every place is referencing the "exits" of other places. cool.

By doing is what enables something that is in another class like after a room has been declared of course. Again, cool. Now if only i knew what the iterator does. I know it correlates with the hash map somehow.

[ December 06, 2004: Message edited by: Sean Magee ]
[ December 06, 2004: Message edited by: Sean Magee ]
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
I want to do a little more riffing on the idea that a Map is like a function. More than one input can have the same output. For instance, say that instead of mapping position to player, we did player to position. Both Lito Sheppard and Sheldon Brown are Cornerbacks. So, we can map both of them to Cornerback.

//remember, key, then value.
players.put("Lito Sheppard","Cornerback");
players.put("Sheldon Brown","Cornerback");

This will never cause a problem, becuase the keys are all unique, so there's never a question as to what will come from

players.get("Lito Sheppard");

however, if we mapped "Terrel Owens" to both "Wide Reciever" and "Best in the league", there's a problem, because what comes of
players.get("Terrel Owens");

So, the second mapping will override the first.

Dig?
Sean Magee
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
I Dig.


[ December 07, 2004: Message edited by: Sean Magee ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help Me
 
Similar Threads
is it an array i need?
Locked door help
Constructor Issue
Please help me do what I'm doing...but better.
Program doesn't complete, but no errors?