Working With Objects In Java - searching with objects

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > Others

Working With Objects In Java - searching with objects

leiaah
our teacher assigned us to do an IS that uses object oriented programming language. i decided to use java but im having a few troubles linking objects with other objects when im searching... can anyone help me? tnx.

Reply

bjrn
QUOTE(leiaah @ Jan 23 2005, 09:38 AM)
our teacher assigned us to do an IS that uses object oriented programming language.  i decided to use java but im having a few troubles linking objects with other objects when im searching... can anyone help me? tnx.
*


If you could post the problem here that would be great. Like: What you want, what isn't working, relevant code (if any). smile.gif

Reply

leiaah
well i know how to write a file and to read a file but im having trouble searching for one particular object. I put an object ID on each object that I made and I was wondering how to search for it. Should I be using array? thanks.

Reply

bjrn
I hope I've understood it right that you have a number of Objects, and each Object has its own ID. And you have to make something that gets an Object when you search for its ID.

In that case I recommend HashTable.

Something like:
CODE

Hashtable objects = new Hashtable();
hashtable.put("Object#1", new MyObject());


And this to get an object
CODE

MyObject o = (MyObject)objects.get("Object#1");



You can think of a HasTable as a table with two columns. One column hold the identifiers/keys the other the Objects.

So if you have an Object you call "ob" and "ob" has a public method called "getID()" which returns the ID, and a HashTable you call "ht" then you can store the Object in the HashTable by:
ht.put(ob.getID(), ob);

Read more here: http://java.sun.com/j2se/1.4.2/docs/api/ja.../Hashtable.html

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : working, objects, java, searching, objects

  1. Flash - Streaming Flv With Interactible Objects
    Actionscript 3.0 - syncronising swf with flv (3)
  2. Ajax - A New Technology
    AJAX relies on Java Script (10)
    Recently i did one of my project using AJAX and i could experience the real advantage of this
    Language , What do you say about that ?....
  3. Java Vs .net: Speed
    (0)
    After researching on this topic on Google, I found no dependable page to which I come to a
    conclusion. So I want to ask you guys the question: Which is faster, JVM or the .NET I already know
    how slow it is to open up a Java program because of the JVM. I've used a .NET program (Visual
    Studio Express) and it was quite faster to load than the Java program (NetBeans). Right now I'm
    siding with Microsoft based on these two experiences, which I believe are naive to found my case on.
    So to those who are familiar with either one of these frameworks, please state your ar....
  4. Flash Vs. Java Applets
    (2)
    As I started to learn Java, I came across a tutorial for making Java applets. As I read on, I found
    some similarities between Java applets and Flash movies. Right when I saw the source code for a
    checkerboard picture made in Java, I said to myself, Flash beats Java applets big time! It also
    took a while to load such a small applet when in Flash it instantly loaded. In my opinion, I think
    flash beats Java applets when it comes to convenience, appearance, load time, animation, and more
    (except AJAX). Here are two articles, first supporting java applets and the other ....

    1. Looking for working, objects, java, searching, objects

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for working, objects, java, searching, objects

*MORE FROM TRAP17.COM*
advertisement



Working With Objects In Java - searching with objects



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE