Queuing my own classes

Hey, folks. Still new to java, but I'm getting the hang of it.
Quick question:
I'm writing a program that will search a db for records that meet a specific criteria. I'm thinking that I'd like for it to wrap each record into an instance of a javabean-like class. Then it would queue those instances so that I can move through them one at a time and modify them. Once modified, it would pump them all back into the db.
1. Does this sound like a good java-like way to go about this task?
2. I was looking at the Queue API. That looks like it might be a good way to go? But, I'm not clear on if I can queue my own home-spun class instances into it. I'm also not sure exactly what the queued object would look like once I pull it from the queue. How would I access the static variables of the queued item to retrieve my data?

thomasaaron wrote:
I do know what a List is, and I'm competent in working with them.
I think Hunter9000 was right though. I was mistaking a cache for a queue.
So, will this work?
1. Retrieve relevant records from DB (There will always be a fairly small number of records. i.e. < 50.)
2. Store the contents of each record in a home-spun JavaBean instance
3. Cache the JavaBeans instances into a list so that I can navigate back and forth through them and make modifications.
4. Pump the modified data from all of my individual JavaBean instances back into the db.That sounds good to me.
If this is the smart way to do it, then my questions become:
1. Will a List hold JavaBean instances?List (and all the Collection classes) hold Objects, so any object type can be stored in it. With generics, you can define the List to hold your specific class: List<TomsDbBean> theBeanList;
2. When I retrieve a JavaBean instance from my List, how will I refer to it in order to call it's methods? I'm having difficulty visualizing the code for this task.If you use generics, the get() method will return the type you defined it to hold. Otherwise, it will return an Object, which you can cast to the specific type.
TomsDbBean aBean = theBeanList.get(0);or
TomsDbBean aBean = (Object)(theBeanList.get(0));

Similar Messages

  • Problem with creating my own class...

    Hi all,
    Purpose with this program:
    I want to create my own class StringThing which take a string parameter and transform the content toUpperCase().
    I have created a simple class StringThing which look like this:
    class StringThing {
    public String upperize (String u) {
    u.toUpperCase();
    return u;
    }And my class where I use the StringThing looks like this:
    import java.io.*;
    class UseStringThing{
    public static void main (String arg[]) throws Exception {
    BufferedReader keyboard = new BufferedReader(
    new InputStreamReader(System.in));
    String s,p;
    System.out.prinln("write a sentence!");
    s=keyboard.readLine();
    StringThing thing = new StringThing();
    p=thing.upperize(s);
    System.out.println(p);
    }Am I not supposed to transform my string parameter in my class by using for instance toUpperCase()? Or is there some fundamental rule or piece of code which I forgot?
    Thanks in advance,
    /Beginner-T-who-ripps-his-hear-over-this-small-problem

    Strings cannot be modified. What this line does:
    u.toUpperCase();
    is to create a new String object. toUpperCase() returns the newly created string and you are ignoring the returned value. What you want to do is:
    return u.toUpperCase();
    or
    u = u.toUpperCase();

  • How can I create a new own class in WebDynpro?

    I test the Web Dynpro for a while and found all the java classes were generated automatically. I've tried to create an own class. But after I rebuild the project, all of my own classes were cleared.

    Hi
    You can create your own class as mentioned in above replies or one more way,
    1. first you create your java project seperately,  there you can write all your business needs and then, make a jar or that then, you can include that project into your WDproject by
    rightclick on WDproject>properties>libraries>addexternaljars>ok
    2. create seperate java project
    rightclick on WDproject>properties>Projects>selectYourjavaProject>ok
    Regards
    Abhijith YS

  • How to get context information in your own class

    Hi,
    I'm new to Java and I'm trying to create my own class which stores some constants like for example mailServerHost. The class would look something like this:
    public class AppSettings {
    private static String mailServerHost="localhost";
    static{
    if(###online-server###)
    mailServerHost="another mail server";
    My problem is the if(###online-server###). I don't know how could I find informations about the underlying server.
    Is there any way to find out informations about the context(server)?
    Thanks,
    IMIA

    Do you still need ?n this case 2 different
    property-files (one for dev and one for
    online-servers).Yes, but they would have the same name. ;-)
    After all when you need to load one
    of them you'd still need in your AppSettings class on
    which server your application is running. So I'd
    still need that information.No, you use a fixed name, e.g. server.properties, for the config file.
    You might find class java.util.ResourceBundle interesting.

  • HELP: Import my own class in JSP ???

    Hi, all!
    I read many previous topics in this forum but no one works for me!
    Please someone help me!
    I'm using Tomcat 4.1.12 and my JSP scripts work just fine, but I need to import my own .class file. I just don't know where to put it so Tomcat can find it!?
    I have this environment variable:
    JAVA_HOME=.;c:\jdk1.3.1
    And in my code I'want to place something like this:
    <%@ page import="myClass" %>
    But I get a "can not resolve symbol" exception.
    Thanks for readind this, and please help if you can!
    Bye.
    adriano

    Within the Tomcat directory, under your application directory place the class file/s into the WEB-INF/classes directory. If your classes are part of a package place the entire directory structure of the package under the WEB-INF/classes directory.
    The import in the JSP is the same as for any Java class.
    Hope this solves your problem.

  • How to create an object of our own class by using Class.forName()??

    how to create an object of our own class by using Class.forName()??
    plzz anser my qustion soon..

    Class.forName does not create an object. It returns a reference to the Class object that describes the metadata for the class in question--what methods and fields it has, etc.
    To create an object--regardless of whether it's your class or some other class--you could call newInstance on the Class object returned from Class.forName, BUT only if that class has a no-arg constructor that you want to call.
    Class<MyClass> clazz = Class.forName("com.mycompany.MyClass");
    MyClass mine = clazz.newInstance();If you want to use a constructor that takes parameters, you'll have to use java.lang.reflect.Constructor.
    Google for java reflection tutorial for more details.
    BUT reflection is often abused, and often employe when not needed. Why is it that you think you need this?

  • Problem to Import my own classes

    I try to import own classes to unother class
    I have all classes in the same map
    import StockTablePanel;
    when I tried to compile the code it says
    �.� expected
    StockTablePanel;
    What is wrong?

    I try to import own classes to unother class
    I have all classes in the same mapAlso if by the same map you mean the same folder then you don't even have to import the class.

  • (updated)UIScrollBar and my own class. Can they works together?

    Hi Eone,
    i'm implementing a uiscrollbar in a class of mine that extends textfield. Unluckly it gives to me  a lot of 1120 error, undefined property, in each row i use a property of this component (except the constructor).
    I read somewhere that As2 not allow to use uisbar in other type of class that extends movieclip or textfiled or you know what...
    It's the same in As3?
    EDIT:
    I found a solution. Some method an properties of UISB can be used in the cvlass (like, contructor, update, target). Some otherelse not. So the other can be used only when i do an instance of my own class, like properties of the instance. Ex:
    textfield.UISB.x = 100;
    textfield: instance of my class
    UISB: scrollbar declared within my class
    x= properties defined only instancing my class

    You need to read the basics about Swing events.
    For starters, you do not implement listeners in your Applet class. Instead, you add new listeners to specific components that you want to listen on. For example, if you need to perform certain actions when a JComboBox's selection changes, you would do something like:
    my_combo.addActionListener(  new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("selection changed to: " + my_combo.getSelectedItem());
    });And for buttons:
    my_button.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You clicked " + ((JButton) e.getSource()).getText() " button);
    }MoustListener and other listeners can be similarily added. See JDK Documentation or Tutorials

  • No intelli sense on my own classes

    I don't get a drag-down intelli-sense menue when i
    type the name of one of my own classes and press ctrl+space.
    Anyone who has had the simular problem, and know the answer?
    The classes are all in the same package.

    Through the tools menue for the folder and "update parser database..."?
    In that case I have to do it for each folder/project?
    I'd like to have it done automaticly. On some other
    computers I have programmed on, the drop-down-menu
    appears without me updating the parser database.
    Has it something to do with the setup?

  • Can Access Outside Dll's Friend Functions On Own Class

    Can Access Outside Dll's Friend Functions On Own Class?
    For Example:
    System.Web.Util's SecUtility ?SecUtility is : internal static class SecUtility

    See the answer by nobugz to this
    thread.

  • Interfaces for your own classes - do you bother?

    Hi All,
    before anyone gets upset, I did post a shorter version this to the Java Prog forum a couple of days ago. I'm reposting here because the thread was pushed down the list just as comments were getting interesting, and I was tossing up which forum was most appropriate anyway...
    OK, I'd like to pose a general question on the use of interfaces with your own classes. I am totally behind the concept of using appropriate interfaces for declaration of vars, parameters etc (i.e. use "List" rather than "Vector"), but what about your own classes?
    If I have a class in my application that doesn't fit into any kind of framework or class hierarchy, subclass of object basically, should I write an interface with all the same method sigs and use that rather than the class for my vars, params etc? This would make things more flexible in future, enabling you to swap classes in and out of your app more easily.
    Taking it a step further, how's this for a design methodology: For every class you write (once again classes that don't fit into your own or somebody else�s hierarchy or framework) do the following
    1. Create an interface (MyInterface) that maps 1 to 1 to that class (MyClass), with all the same method sigs.
    2. Make the constructor private and manage all the creation of instances of MyClass through a factory that returns objects of type MyInterface.
    If you do this there will be no mention of any of your concrete classes anywhere in your app except the factories, making it easier to refactor etc. Do this for all your classes.
    A little sketchy but I hope you get idea. Is this complete overkill? Is there a down side to this? Does anyone do anything like this?
    Cheers
    Matt

    Although the pattern you describes adds flexibility, it also adds complexety.
    Imagine somebody is looking at your code and from what he sees he deducts that the next thing to look at is the concrete class which is used at a given place.
    If you used an interface, he must find out which implementing class is actually used at this place. It's not a big thing, but if every single class has its seperate interface and factory I would consider it overkill ... after all you have to write all the boring code for this.
    In the case of doubt I'd agree it's better to throw in an interface and a factory instead of refactoring thousand lines of codes afterwards. But if nothing hints toward a second implementation of the interface, or another reason for using an interface don't bother to write one.
    As a general rule I use something like: Don't use a general rule. ;-)
    Spieler

  • Loading a library in my own class...

    Hello,
    I'm having some problems with loading my own library into a different class then the main, but I'm keep getting this error message:
    run:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: cembedjava.CFunctions.nativePrint()V
            at cembedjava.CFunctions.nativePrint(Native Method)
            at cembedjava.Main.main(Main.java:17)
    Java Result: 1The project is based around the tutorial for including some C code in a Java application. I'm working with an Ubuntu 8.10 distro, Netbeans IDE 6.1 and JDK 6 update 11. I'm new to Java programming, but I have experience with C, Delphi and Basic in different flavours.
    The C code is working as it supposed to be (at least, I think, I had it running under the main class). The code implements a timer in C with an interval period of 1,5 seconds, which returns a message every time to the screen (or app). What's going wrong in the following code?
    package cembedjava;
    public class CFunctions
         public native void nativePrint(); 
         static {
           System.load("/home/richard/NetBeansProjects/HelloWorldNative/dist/libHelloWorldNative.so");
          // System.loadLibrary("libHelloWorldNative");
    package cembedjava;
    import java.lang.Thread;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    public class Main {
        public static void main(String[] args) {
            // TODO code application logic here
           CFunctions obj = new CFunctions();
           obj.nativePrint();
    }Or do I need a new thread to keep my timer running?
    Thanks

    Thanks guys,
    I got it working... I had a problem with the declaration of the function in my .h and .c file. In the .h file everything was okay, but I had the wrong classname in the .c file. For some reason this still compiled but gave me the exception during runtime.
    Is there also a possibility not to have to put in the class name in the function declaration, right now the function are declared as this:
    JNIEXPORT void JNICALL Java_cembedjava_CFunctions_nativePrint
          (JNIEnv *env, jobject obj)
    With the CFunctions as class name en cembedjava as project name of the Java project. Is it possible to call my functions in a project and class that don't have the above stated names?

  • Importing my own classes

    I have 2 simple classes in the same directory and I'd like to test the use of import to import one class into the other. Upon compilation of the class thats doing the import, I get a compilation error. Herewith the details, where could I be getting it wrong.
    ****code for class to be imported****
    import java.util.Date;
    public class printer
    public void print()
    System.out.println(new Date());
    System.out.println("Hello World");
    --The above code compiles with no problems.
    ***Code for the main class that imports the above*****
    import printer;
    public class myapp
    public static void main(String[] args)
    (new printer()).print();
    -upon compiling the second class above, myapp.java, I get the following errors:
    C:\java\source>javac myapp.java
    myapp.java:1: '.' expected
    import printer;
    ^
    myapp.java:1: ';' expected
    import printer;
    ^
    2 errors

    Moreover, classes do not need to import any class which is in the same package as their own, and since your printer class is in the default package (if you call that a package) you shouldn't need to import it into myapp anyway

  • Can't import own classes...

    I'm very new to java. I rented a book called Java 2 Grand Cru to learn it on my own. It is based on Java 1.3 but I have 1.4 installed. Now I wanted to write a simple program with a class in an other directory. I added that directory to CLASSPATH so my compiler could find it. These are the 2 programs
    import printer;
    public class test
         public static void main(String[] args)
              (new printer()).print();
    }and
    public class printer
         public void print()
              System.out.println("test");
    }So I want the first class to use the second to print "test"!
    Now I can compile public class printer without any problems but when I compile the first one, I get this:
    test.java:1: '.' expected
    import Printer;
                   ^
    1 error
    Process Exit Code: 1
    Time Taken: 00:00
    i don't get it. Is there anything changed with the import instruction in the new version of Java2?
    regards

    It is the error of my code but probably I did something bad with the copy paste thing :-)... The 'P' should be a 'p'
    Anyhow, I don't understand your first comment. 'printer.class' isn't a default package. I made it myself...
    regards

  • Implementing evetns in my own classes

    I am currently developing a class that I want to enable with events so that consumers of my class can get feedback of class activity.
    So consumers should be able to add listeners (containing callback methods) to instances of the class. Although my current class is GUI related (I am writing my own tablemodel) my issue is not limited to GUI development I think (therefore posted here and not in Swing forum).
    So far I am a little familiar with Listener and Adapter classes but now the point:
    Do I have to implement my own addBlaBlaListener and removeBlaBlaListener methods implementing my own methods to handle the list of current listeners (e.g. choosing the appropriate array, list, stack or whatever classes to store the references) or is there some ready-made-classes from the libraries that should/can be used?

    tjacobs01 wrote:
    Why do you need to create UI-style events?I am building my own Table model as the simple table model is too basic for my common needs. In that table model I need to provide events being fired when table cells change.
    I highly recommend using the Observable/Observer pattern where possible. Otherwise, see an example for custom events in my InfoFetcher.FetcherListener interface
    http://forums.sun.com/thread.jspa?threadID=759854&tstart=62264
    I heard/read about the Observer and Observerable but when I searched for event handling I always found the methods I am currently trying. That's the only reason why I use that here - because this is what I found how others recommend to do it. If there is a better option - I am open and flexible - yet (in a year when everything was implemented probably not ;-) ).

Maybe you are looking for

  • Best External hardrive for video for MacBook Pro?

    I have a MacBook Pro - 2009.  I have put a lot of video on my computer and it's getting full so I need to clear content off to make some room.  What is the best and easiest external drive for holding video?  Also, I want it to be super easy to access

  • IWeb Web Widget Power

    Alright so I searched and didn't really find a direct answer to my question so I figured I would add it myself as my first post. I am creating my first webpage with iWeb and want to place a web widget like the ones I make out of safari. For example I

  • Illustrator CS6 - Adding dimensional information to a drawing

    How can I add actual dimensions to an object.  I'ver created the drawing, but now want to add the dimension informaiton of a few objects into the drawing, without having to manually add the line and arrow and text.

  • Iphoto from Europe

    I am in Europe and I recently upgraded my Macbook Air to 10.10.3. Now I cannot access iPhoto. I need to upload to iCloud but I like access to my photos on my hard drive. How can I upgrade my iPhoto in Europe and access my photos?

  • Problem in claiming Mountain Lion System

    I wanted to upgrade my Macbookpro system to Mountain Lion by claiming process. But I wrongly go to the iTunes and purchase the software. I have submitted my claim to apple and they have approved it. Can I cancel the itunes's bill in my credit or get