Newbie question on using an Interface

I am something of an advanced beginner, one of those guys who can write simple stuff and maintain code but always have a bunch of questions.
I am able to use an interface in a simple example shown below:
import java.util.*;
import java.text.*;
public class ClassTest
public static void main(String args[])
new ClassTest();
ClassTest()
IfcPrintClass dao=null;
try{ dao = (IfcPrintClass)Class.forName("ThatPrintClass").newInstance();
}catch (Exception e) {};
System.out.println(dao.PrintTheClass());
try{ dao = (IfcPrintClass)Class.forName("ThisPrintClass").newInstance();
}catch (Exception e) {};
System.out.println(dao.PrintTheClass());
} //end ClassTest
What I am wondering is how do I instantiate (hope that's the right terminology) a class via an interface when the class has parameters? The API and other examples, at least ones I've seen, don't spell this out.
I have to maintain a piece of code (ie, I didn't write it) with a class defined below. We need to create an interface for this class to implement so we can re-use this and similarly named classes for other projects. For example, the below listed class is to handle our SQL I/O, but naturally the db handling will varying from project to project. I want to be able to dynamically load a class within my code and pass the class name and directory into the package via ARGS (again, hope I'm using terminology correctly). I am trying to figure out how to adapt my above example to the below class instantiation, but cannot figure out how to pass the parameter along with it. I do know how to create an interface. In the below example "errorModule" is another class that handles our error and information logging, but is abstract enough that it will not change project to project. The "insertLoader" method is a sample method that the DAOLoader class will do, as is "isConnected".
dao = new DAOLoader(errorModule);
if(dao == null || !dao.isConnected()) //connection failed
// handle this error
else
dbAlreadyFailed = false;
if(firstDatabaseConnection)
dao.insertLoader();
thanks in advance, and hope you can help.

As requested, here is the code I posted using code tags,and I'll do this in the future:
ClassTest.java:
import java.util.*;
import java.text.*;
public class ClassTest
public static void main(String args[])
new ClassTest();
ClassTest()
IfcPrintClass dao=null;
try{ dao = (IfcPrintClass)Class.forName("ThatPrintClass").newInstance();
}catch (Exception e) {};
System.out.println(dao.PrintTheClass());
try{ dao = (IfcPrintClass)Class.forName("ThisPrintClass").newInstance();
}catch (Exception e) {};
System.out.println(dao.PrintTheClass());
} //end ClassTestMy actual code:
dao = new DAOLoader(errorModule);
if(dao == null || !dao.isConnected()) //connection failed
// handle this error
else
dbAlreadyFailed = false;
if(firstDatabaseConnection)
dao.insertLoader();
}IfcPrintClass.java:
public interface IfcPrintClass
String PrintTheClass();
}ThatPrintClass.java:
public class ThatPrintClass implements IfcPrintClass
public String PrintTheClass()
return "That";
}Then I have a class ThisPrintClass:
public class ThisPrintClass implements IfcPrintClass
public String PrintTheClass()
return "This";
}

Similar Messages

  • Complete newbie questions: need the Mac interface explained!

    Warning: this post conains some sper dumb questions
    I've got a Macbook - old, but seems super fast
    I'm a newbie to Mac
    I'm really confused!!
    What's the bottom line with the icons for?
    Doh! Sounds like a dumb question!
    Is it meant to be my most commonly used programs??
    Should I start adding and removing?
    Where are my apps?? I open something and minimise it
    How am I supposed to get back to it??
    I can alt tab to it - but really annoying if I have looads of apps opened as I have to cycle through all windows
    Where is it minmised to??
    Answer: to the bottom line. Where is it? I get really confused about this - is it on the far right hand side?
    What if I have several browser windows open? How do I browse between the windows?
    I press X on the top left, but this doesnt close the application, it just seems to be minimised??
    I've discovered that if I hit 'Apple Key + Q' that closes properly - is there no way to close via the mouse?
    Thanks  
    Omar

    Mac 101: Desktop
    http://support.apple.com/kb/HT3737   <<< click here.
    The Grand Tour: Introduction
    http://www.apple.com/support/mac101/tour/   <<, click here.
    http://www.apple.com/support/mac101/   <<< click here.

  • A Question regarding use of Interfaces.

    I have read about interfaces,but I havent got the real grasp or point
    of it.
    1). How is an interface an improvement over classes?
    If I define a class which has several important methods in it,and this class is extended by several other classes,and all these sub classes then call the super class's methods.
    How does an interface be more beneficial?
    2) What is the exact use of creating class intances thru interface references?
    Java talks about multiple inheritance using interfaces.
    If an interface does not have any constructive methods,but just
    empty methods,how does this become more constructive?
    Eventually a class will implement the this interface to give it some
    value? So why dont I write a class straight away rather than creating an interface,implement it and then code the required methods defined.
    I tend to avoid using interfaces becos I find them of no value.
    Rather I wud prefer to define class with some constructive methods
    and extend this class.
    Am I right in my analysis?

    Interface is also a "contract" that the class implementing a particular interface will provide certain functionality to the users of the class. For E.g Serializable interface in Java. All the classes that implement this interface indicate that the objects of these classes are serializable. Similar thing with Cloneable interface, all objects of classes that implement this interface are Cloneable....
    Hope thinking in these terms will help your understanding. Just look at Java interfaces to understand instead of some custom code.

  • Newbie question about using more than one Ipod on same computer

    Hi everyone,
    I finally got into the Apple world this year with a new (16 GB) iPhone. Love it. I've now ordered a Nano as well. My question is: though I know that my iTunes will recognize the Nano as a different iPod, will I be able to transfer the music I purchased from iTunes store with my iPhone and iTunes to the Nano? If so, how?
    Thanks

    will I be able to transfer the music I purchased from iTunes store with my iPhone and iTunes to the Nano?
    Music currently in iTunes can be transferred to the iPod nano the same way it was transferred to the iPhone. Content on the iPhone needs to be transferred to iTunes first.
    (43837)

  • Quick (newbie) question about using Pacman

    So I was wondering what the syntax would be in order to have pacman install packages listed in a file. I was thinking of using the output of
    pacman -Qqe
    passed to some arbitrary file (say, paclist for example) by way of
    pacman -Qqe > paclist
    What would I have to do to have pacman take paclist as an input for say, setting up a new system?
    It just seems there would be some really obvious thing I have to do in order for this to work. Thank you for your patience!

    https://wiki.archlinux.org/index.php/Pa … d_packages
    EDIT: wrong anchor, this is what I meant to post: https://wiki.archlinux.org/index.php/Pa … d_packages
    Last edited by WorMzy (2013-05-31 00:28:09)

  • Newbie question about using vectors and arrays

    I'm fairly new to JME development and java in general. I need some help in regards to Vectors and 1 dimensional arrays. I'm developing a blackberry midlet and am saving the queried info i pull back from my server side application with each record saved into the array and subsequently each array saved as an element in the vector, thereby creating a 2D "array".
    However I'm having a problem accessing the elements in the array. Here is a sample of what I mean and where I get stuck:
    Vector _dataTable = new Vector(1, 1);
    String[] r1 = {"a", "b", "c", "d"};
    String[] r2 = {"1", "2", "3", "4"};
    _dataTable.addElement(r1);
    _dataTable.addElement(r2);
    Object temp = _dataTable.elementAt(0); //Save the element as an new object for useNow how do I access the particular indexes of the element of the temp object? Do i need to caste it to an array? Is there another more efficient/easier way I should be storing my data? Any help would be great!
    Edited by: Sotnem2k1 on Apr 1, 2008 7:50 AM
    Edited by: Sotnem2k1 on Apr 1, 2008 7:51 AM

    Thanks for the feedback newark. I have this scenario below:
    // Class for my 1D array
    public class OneRecord {
        private String[] elementData = new String[4];
        public OneRecord() {   
            elementData[0] = null;
            elementData[1] = null;
            elementData[2] = null;
            elementData[3] = null;
        public OneRecord(String v1, String v2, String v3, String v4) {   
            elementData[0] = v1;
            elementData[1] = v2;
            elementData[2] = v3;
            elementData[3] = v4;
        public void setElement(int index, String Data) {
            elementData[index] = Data;
        public String getElement(int index) {
            return elementData[index];
    } Then in my main app I have:
    Vector _dataTable = new Vector(1, 1);
    OneRecord currRecord = new OneRecord("a", "b", "c", "d");
    _dataTable.addElement(currRecord);
    OneRecord temp = (OneRecord)_dataTable.elementAt(1);
    System.out.println(temp.getElement(0)); Are there more efficient data structures out there to save queried data from a server side app? Like I said, i'm still trying to learn the most efficient techniques of coding...esp for the Blackberry. Any suggestions would be great!

  • Question on use of multi-mappings in interface mappings

    We have the following scenario :
    1. XI receives a orders05 idoc - xml and does a first message map - splitting this xml into two - a lookup key msg type and a copy of orders05 msg type ( 1:n )
    2. These two messages from the first mapping are used in a second message mapping ( of type multi-mapping too ) ( n:1) to create the final orders05 message.
    3. These two message maps are put sequentially in the interface mapping.
    orders05 -> MessageMapping1 -> MessageMapping2 -> orders05 . Please note that our objective is to send one single ORDERS05 idoc into the end R3 system - using the idoc adapter. The use of multi-mapping is in the interim - and not in the idoc adapter.
    Issues:
    a. the "ns0:Messages" and "ns:Message[n]" tags are not being created automatically.
    b. In the interface determination we do not see the interface mapping when we select the 'enhanced' option.
    Any ideas, pointers as to what I am missing here ? I am on a critical timeline to implement this and can't understand whats going wrong ?

    Michal,
               In your suggestion - to use two interface mappings - how I can configure the two interface mappings as a part of a single interface determination so that they execute one after the other .  Or is it two interface determinations - one for each interface mapping - how do I relate these two ?
    Also, I assume that since the message mappings in the interface mappings are multimappings , I need to use enhanced interface determination .
    Could you share one of the scenarios wherein you had two interface mappings execute in a series - ? Thanks for your time.

  • Newbie Question:  How much computer do I need?

    Newbie Question:
    I would like to use MainStage 3 in a live performance environment to play bars, parties, etc.  I'm not looping, using it to playback recordings, processing outboard equipment or vocal processing.  I want to stop carrying Rolands, Nords, Korgs, etc and get to a controller and a rack with a Mac Mini in it.
    I tested a download of Mainstage 3 on my home Mac Mini (late 2012, 3.5 Ghz i5, 4GB RAM, 500GB drive) and it seemed to run fairly well.  $30 well invested so I trekked forward... I purchased a Mac Mini (late 2009,  2.52GHz Core 2 Duo, 6GB RAM, 128GB SSD) for $200.  I started to do more elaborate keyboard setups to see how the CPU would hold up.  It typically runs from 30% to 50% of capacity (CPU and Memory)  It actually boots and runs better than the i5.  I hear the occasion gitch, but it actually seems to be getting better in time (or I'm rock and roll deaf.
    I got a rack, an Airport Express, a Radial USB interface and a Nektar Panorama P6.  It's starting to get expensive, but I'm emboldened by the actual quality for the sound and the flexibility of arranging for live performance.  What used to take me two and three keyboards to play, I can now fit on one performance patch.
    OK, now the question... am I at the limits of this little Core 2 Duo?  Should I upgrade the i5 with more RAM and a bigger SSD and use that?  Should I get a new(er) i7 and bite the $1,500 bullet for the additional RAM and SSD?
    I see that most of you are running pretty nice Macbook Pros with i7 and lots of everything.  My needs are modest; am I OK? 
    BTW, I want to run a Mac Mini in a box because I don't want to carry a laptop out in the open.  If I was doing bigger shows I wouldn't care but I play some rowdy bars and constantly have folks hanging off me while I'm playing.  It's fun, but hard on gear.  If you can't drop it or dip it in beer, it won't last long where I work.
    Matt Donnelly

    Rule of thumb: newer and faster is better. But, depending the complexity of your needs you may be OK with an older Mac. Some glitches that happen in a live performance are due to loss of communication with USB or Firewire inputs, so make sure they're secure. I recently upgraded from a 2010 Mac Mini 2.6 dual core with 16 GB RAM, which was used live for nearly four years, to the latest Mac Mini 3.0 i7 with 16 GB RAM and a 500 GB SSD. I was getting an occasional stuck note with the older one. The new one is rock solid. Some of my patches may have up to a dozen channel strips mapped to three keyboards. The Mini is mounted in a rack next to a MOTU Ultralite Hybrid. It is a good idea to map a panic button on your keyboard to controller # 123(all notes off). Also, you might want to invest in a battery backup power supply(APC, Cyberpower, etc.-$40-$60) to protect your Mac against power loss, which can damage you hard drive.

  • Questions on using classes inside BSP pages

    Hi Group,
    I have a few questions on how to use classes,interfaces,parameters in classes,
    and etc., relating to OOPs concepts that can be implemented in BSPs.
    Pls send me some link wherein I can explore things and use it in BSPs.
    Thanks & Regards,
    Vishnu.

    Hi Raja,
    I am facing issues like this:
    1) When I use the code in my BSP as under:
    <%
    class ZCL_MODEL_03 definition load.
    data ref1 type ref to ZCL_MODEL_03.
    data cust_id type c value "1000".
    data c_id type c.
    create object ref1.
    c_id = cust_id.
    call method ref1->CHECK_CUSTOMER changing cid = cust_id.
    %>
    Cannot we define variables in the Scriptlet?? or we need to do only in the attributes sections only?? or in both??
    2)I am not able to use both exporting & importing things in my method call.
    eg.,call method ref1->GET_CUSTOMER
                      exporting cid = cust_id
                      importing c_id = eid.
    In the method definition, I am only using simply logic like, I was trying to send a value into the "cid" defined in the method and putting that value into "eid" which was defined exporting, but, still I could not get the value into "c_id" that I have defined in the BSP page.
    Note: in both the things(in BSP and class definition as well, I am using the same
            type for defining the attributes.
    3)When can we define a "Returning" option in the Class method's parameter    
       Definition? and how can I use it with an example?
    Thanks in advance.
    Regards,
    Vishnu.

  • Using empty interface -- is there a better way to do this?

    Hi,
    I have a set of classes in different projects that I'd like to be referenced together, although they have different methods depending on which project they're from. To do so, I've created an empty interface for each of these classes to implement, so I can return a similar type and then cast it however I need to based on which project I'm using.
    However, I feel the approach of creating an empty interface just isn't the best way to do this. I've looked into annotations, but I don't think they can solve my problem. I don't think I'm being too clear here, so let me give a brief example:
    Here is one of the interfaces I use:
    public interface IceClient {
         public IceOperations operations();
    }Here is the empty interface:
    public interface IceOperations {
    }I have a method which will return a type of IceOperations:
         public static synchronized IceOperations getOperations(String clientName) {
              if (clientMap.containsKey(clientName)) {
                   IceClient client = clientMap.get(clientName);
                   return client.operations();
              } else {
                   System.out.println("No client of that name is currently running.");
                   return null;
         }This is all fine and dandy. I need to instantiate a new IceOperations object in my client code as such, where operations is of type IceOperations:
    operations = new DiagOperations();And finally return it like this, where client.operations() returns a type of IceOperations:
         public DiagOperations operations() {
              return (DiagOperations)client.operations();
         }Anyway I hope that wasn't too confusing. I cannot think of a different way to do this. Is there some way I can do this with annotations? The only other thing I can think of is just returning Object, but that seems ... icky.
    If I need to be clearer, please let me know.
    Thanks

    JoachimSauer wrote:
    I didn't understand them to be trick questions, but rather serious invitations to question and verify your assumptions.
    It might be the fact that every current implementation implements Runnable for some reason (possibly because it starts a Thread on its own). But it's entirely possible that you can produce a completely different implementation that doesn't need the Runnable interface and still be conformant.
    If every implementation of X needs to implement Runnable, then it could be a sign of a slight design smell. Could you give an example where you think it's necessary?Every implementation of my "X" interface is basically a class that acts as a communicator/listener of sorts until it's stopped by the user, similar to a server socket. Sometimes, it has to sit there and wait for events, in which case it obviously must be in its own Thread. Other times it doesn't have to do this; however if I do not start it in its own Thread, I will have to continually stop and restart the communication to invoke operations on the server, which is inefficient.

  • Using an interface as a parm in a methods

    Greetings I have an interface class that has a bunch of get methods. Then in another class I call the interface as a parameters. But what information do I put in it as I use it? the gets?
    [code
    //interface class
    public interface FillData {
              public String getTrader();
              public String getAccount();
    //Reg class
    public boolean insertData(FillData data){
    return true
    //Where I set the methods
    setTrader((String)table.getValueAt(i,0));
    importit.setAccount((String)table.getValueAt(i,1));
    insertData (//what goes in here???){
    Any more information needed lemme know? Thanks for any help!

    I have an interface public interface FillData {
    public String getTrader();
    public String getAccount();
    }I have a class with the interface as a parameter of a method
    public boolean insertData(FillData data){
    //do stuff
    return true
    }When I call the method what do I put in the parameter part of the method when I implement it?
    insertData(//what information do I put in here?)I guess my question is how do you use an interface??? I read the tutorial about implementing it in a class and all but how about when u use it as a method?
    Message was edited by:
    h2opologirly69

  • Newbie Question about FM 8 and Acrobat Pro 9

    Hello:
    I have some dcouments that I've written in FM v8.0p277. I print them to PDF so that I can have a copy to include on a CD and I also print some hard copies.
    My newbie question is whether there is a way to create a  PDF for hard copy where I mainitain the colors in photos and figures but that the text that is hyperlinked doesn't appear as blue. I want to keep the links live within the soft copy. Is there something I can change within Frame or with Acrobat?
    TIA,
    Kimberly

    Kimberly,
    How comes the text is blue in the first place? I guess the cross-reference formats use some character format which makes them blue? There are many options:
    Temporarily change the color definition for the color used in the cross-reference format to black.
    Temporarily change the character format to not use that color.
    Temporarily change the cross-reference definition to not used that character format.
    Whichever method you choose, I would create a separate document with the changed format setting and import those format into your book, create the PDF and then import the same format from the official template.
    - Michael

  • Using local interfaces for EJB (session bean)

    Hi,
    I�ve a question regarding when to use the Local interfaces(EJBLocal and EJBLocalHome) of a enterprise bean. I understand that calls to enterprise bean can be made locally if the client which is invoking is in the same JVM as that of EJB. I�ve written a web client (servlet) which is packaged in a EAR and this servlet is trying to invoke a session bean which is in a �different� EAR using local interfaces. Both the EARs have been deployed in a single server (websphere 6.0 server). It didn�t work for me this way�..If I package the servlet in the same EAR of session bean then it works fine.
    So is this to say that both EARs are not running on the same JVM? Or should it work even if the client and the session bean are in different EARs but in same server?
    Can anyone explain me the fundamentals behind this.
    Thanks in advance

    Local access is only portable within the same .ear. For example, the Java EE SDK and SUN's
    application servers have never supported local EJB access from a web/EJB component in a different
    .ear. One issue is that local access requires that both the caller and target EJB have the same
    classloader. By definition, different Java EE applications have distinct classloaders. In addition,
    in Java EE 5 persistence context propagation does not span applications, so it wouldn't work in the
    local case.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • No performance gain when using local interfaces

    Hello,
    I'm doing some tests to compare performances between remote ejb interfaces and local ejb interfaces.
    I have two stateless session beans EJB1 and EJB2, EJB1 calls a method on EJB2, this method receives one object as the only parameter and returns it immediately. The parameter is a big object (~700ko). My test consists simply of making 1000 calls from EJB1 to EJB2, one time with remote interfaces, one time with local interface. For both tests, the EJBs run in the same container, same VM.
    The results show absolutely no differences between the remote and the local interface !
    As I found these results a bit surprising, I changed the serialization method of my parameter object this way:
    private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    System.out.println("writeObject(MyBigObject)");
    out.defaultWriteObject();
    just to check if my object is serialized when using remote interface. And the response is no.
    So question is: is there an "undocumented optimization" of the stub/skel generated by weblogic which make local calls when calling a remote method inside the same VM ?
    Some precisions:
    - I'am using weblogic 8.1sp2
    - When calling remotely my EJB2 from an external batch (running in a separate VM), I see the message "writeObject(MyBigObject)" so the serialization is done in this case.

    <Fr?d?ric Chopard> wrote in message news:[email protected]..
    So question is: is there an "undocumented optimization" of the stub/skel generated by weblogic which make local calls when callinga remote method inside the same VM ?
    >
    Some precisions:
    - I'am using weblogic 8.1sp2
    - When calling remotely my EJB2 from an external batch (running in a separate VM), I see the message "writeObject(MyBigObject)" sothe serialization is done in this case.
    WebLogic 5.x, 6.x and 7.x do call by reference for co-located EJBs by default. 8.1 has this behavior turned off by default. You may
    experience call-by-reference optimization in 8.1 only if it has been turned on explicitly in the deployment descriptor.
    Hope this helps.
    Regards,
    Slava Imeshev

  • EE 5 newb question

    My question revolves around remote interfaces and using the persistence API. An example might give more insight into my question�
    I have 3 tables Customer, Order, LineItem with the corresponding object associations:
    class Customer {
    long id;
    List<Order> orders;
    public long getId() {};
    public List<Order> getOrders(){};
    class Order {
    long id;
    List<LineItem> lineItems;
    public long getId() {};
    public List<LineItem> getLineItems() {};
    public Customer getCustomer() {};
    Class LineItem {
    long id;
    public long getId() {};
    public Order getOrder() {};
    When using a session bean that implements a remote interface I make a call similar to the following�
    @Stateless
    class OrderBean implements RemoteOrder {
    public List<Order> getOrders(long custId) {
    return em.createNamedQuery(�order.findByCustomerId�).setParmater(�custId�, custId);
    Now this would work great in a Servlet/JSP that was running in the same JVM, but I am accessing this from a web service. I am wondering what is the �standard� way to return the persistent data to the web service client?
    Is it off load every thing into a value object? Something has to be done otherwise I will always get exceptions when trying to access the lazy children of Customer. Even if I do a FETCH JOIN for Customer.lineItems then the problem nest down
    to Order.lineItems, should I FETCH JOIN this to? What about the cyclic call during marhsalling from Customer.getOrders() -> Orders.getCustomers()? I have yet to find documentation �anywhere� ;) that defines a standard way
    to handle this or should we still develop the J2EE way and use Transfer Objects, but I thought the persistence layer and POJOs was supposed to remove this extra layer from the enterprise application.
    Thanks for any help
    J

    The tape device /dev/rmt/0 can be accessed through a number of "names". The exact name used indicates a exactly how the hardware should access the device.
    /dev/rmt/0n is the no rewind version. If you don't add the n then the tape will be automatically rewound on close.
    You have to use that version if you want to dump multiple things onto the tape one after the other.

Maybe you are looking for

  • PO pricing conditions

    We have following scenario: On Import POs say article cost is $100 Import duty is $5 Freight cost is $10 Commission cost is $2 Brokerage Fee is $ 2 Some of these are payable to different vendors and on PO only estimated cposts are identified. Questio

  • Adding element in a List box

    How do we add an element to an existing List box in swings?

  • Error 0x610000f6 on my HP310 Series printer.

    Error 0x610000f6 on my HP310 Series printer. All colours and photo black print. But black cartridge is showing blank even when replaced and black text is not printing.

  • Partial import

    I have an issue in that FCE is only importing 21 minutes of my 24 minute clip. My original clip was shot as an h.264, so I converted it using quicktime pro 7. The converted file plays (in its entirety) on all my computers, however its only when impor

  • Transportable tablespaces requirment

    Hello All, This is what I am running on. BANNER Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio NLSRTL