Computer Science Canada

New Object names

Author:  Hackmaster [ Mon Jul 09, 2007 11:26 am ]
Post subject:  New Object names

hey all, this is probably a noobish question... but, I'm new to java, and also just remembering how OOP works, not having programmed for a while...

I'm wondering, when you are making a new object, how much flexibility do you have with a name? like for example. this is legal:

code:


anyClass foo = new anyClass(42);



but what about something like this?

code:


int num = 7;

anyClass foo(num) = new anyClass(42);



I guess what my question really is is how to make unique objects in a loop. if I have a program that, for example, takes any number that a user puts in and makes a new object to house it (stupid reason to use an object, but...). if it's the same number, just say it's already got a home. if it's new, though, how would you make a new one? presumably to get this kind of thing done, you would use this type of construct... (pseudocode...)

code:


     public class storeHouse {
               
                private long foo = 0;
               
                public storeHouse (long f) {
                       
                        foo = f;
       
                }
     }
     
     //get input somehow, whatever

    // some sort of loop construct that I'm having problems with.




I'm not really sure what to do with this situation... bad example, I know, but, I think you get the idea. could someone give me a hand here? in easy terms/steps? thanks.

Author:  wtd [ Mon Jul 09, 2007 11:46 am ]
Post subject:  RE:New Object names

Methinks you are looking for a Map.

Author:  Hackmaster [ Mon Jul 09, 2007 12:39 pm ]
Post subject:  Re: New Object names

that would be great... if I knew what exactly that was.... Embarassed


could you elaborate please?

Author:  wtd [ Mon Jul 09, 2007 1:19 pm ]
Post subject:  RE:New Object names

Perhaps you should run your mouse cursor over my previous sentence.

Author:  Hackmaster [ Mon Jul 09, 2007 1:44 pm ]
Post subject:  Re: New Object names

ya... oops.

so.. that sounds good, but, since these things are always in the tech jargon that is so unfriendly to the noobish, would it be possible for you to explain this to me? (and yes, I read the page.)

Author:  Aziz [ Mon Jul 09, 2007 2:28 pm ]
Post subject:  RE:New Object names

Read the Java Tutorial trail on Collections:

http://java.sun.com/docs/books/tutorial/collections/index.html

Also, it is considered widely accepted standard for all class to be named in the CapatilizedCase.

Collections is a bit advanced of a subject, however. Perhaps learn a bit more before tackling the Map data structure.

BTW, wtd, you were linking to 1.4 API. Unless he's using Ready To Program, 1.4 is heavily outdated (though, perhaps he is, I have come to expect much from your duck wisdom)

Author:  wtd [ Mon Jul 09, 2007 3:38 pm ]
Post subject:  RE:New Object names

I was assuming RTP. I probably should not have.


: