Puzzle about declare List object

Why we declare a object using "List list=new ArrayList();" other than "ArrayList list=new ArrayList();"?I have seen in Java API that:"Source source=new StreamSource();" other than "StreamSource souce=new StreamSource();".Is there any advantages to do this?

just gives you more flexibility when you may possibly change the instance of the object being created.... more like the Factory patteren....
hmmm.... i dont think im making much sence here.... :O)) let me explain with an example....
the return type of Calendar.getInstance() is Calendar while internally it actually returns an instance of GregorianCalendar which is a sub-class of the Calendar class... the reason to that all the methods that you want are available in the Calendar class, & if a couple of version down the road if the API changes to return an instance of some other sub-class of Calendar, anyone using it would not be effected....
BUT if in your case you are using specific methods that are only available in the ArrayList and not in the List class.... then you would be better off using ArrayList list=new ArrayList()....
hope this explains to some extent
regards
omer

Similar Messages

  • Call Transaction from Excel VBA macro and download ALV list object results

    I have a situation that must be very common u2013 but I canu2019t find any clear information on how to get it done! 
    We frequently run SAP transactions, download the results (orders or inventory) into Excel, do some calculations and create a spreadsheet report. 
    I would like to automate this process using Excel VBA so that a macro will perform these steps:
    1. Run our custom SAP report "YSD033" that summarizes orders using the previous day as the [From Date] parameter.  (The user already has an active ECC 6 R3 session running.)   If possible, can the TC be run using a specific variant "G111BIZ" ?
    2. Download the list object that appears in an ALV grid as a table to an empty spreadsheet in the active workbook (export XXL list object)
    3. Save the resulting workbook and close Excel.
    Should the solution use u201Ccall transactionu201D or a GuiXT script?
    Any help would be much appreciated, and some sample VBA code would be great!
    Thanks.
    Glenn

    Good suggestion, but
    I get "permission denied" for   SapGuiAuto.GetScriptingEngine
    I also tried the method below, but received this RFC error message:
    User PPPPPPP  has no RFC authorization for function group SYST.
    Sub LoginCheck()
    If login = False Then
        ' Setting the necessary variables for R/3 connection
        Set objBAPICortrol = CreateObject("SAP.Functions")
        Set objConnection = objBAPICortrol.Connection
        ' Establish a connection
    If objConnection.Logon(0, False) Then
        login = True
        MsgBox "Connection Established"
        CommandButton1.Caption = "Disconnect"
    End If
    Else
        CommandButton1.Caption = "Connect 2 SAP"
        login = False
        objConnection.Logoff
        Set objConnection = Nothing
        Set objBAPICortrol = Nothing
    End If
    End Sub
    I was told that these kinds of authority open up too big of a window that can't be monitored adequately...
    I'm considering an approach like what is below if I can't convince security to grant me permissions...
        Application.Wait Now + TimeValue("00:00:01")
        SendKeys EnterKey, False
    Since blocked RFC security settings are preventing the solution from being installed, I am markgin this question as answered. 
    I will post different questions about 1. how to convince the security team that it will be safe to allow the use of RFC calls, and /or 2. how use some windows-level scripting code to run the SAP jobs.
    Thanks.
    Edited by: GlennWebster on Mar 1, 2010 4:34 PM

  • List Object or Just List which is better ?

    Hi Guys,
    List<Object> list1 = new ArrayList<Object>();
    List list2 = new ArrayList();Logically speaking, both looks similiar. But which one is better to use ?
    I can do something like
    list1 = list2; OR
    list2 = list1; but if List<String> list3 = new ArrayList<String>();Why I can not do this list1 = list3; // throws compilation error Thanks,
    javaCrazy

    javaCrazy wrote:
    List<Object> list1 = new ArrayList<Object>(); This is senseless. Inside the braces an appropriate Interface should be used.
    but if List<String> list3 = new ArrayList<String>(); Why I can not do this list1 = list3; // throws compilation error
    If you declare <tt>List<String> list3 = new ArrayList<String>();</tt> you explicity state that the List will only contain Strings (or types that inherit from the declared type, but String cannot be subclassed), list1 is declared to contain objects of a different kind. Usually the interface of the type list1 is declare will not match with the interface declared for the elements in list3. Since Object is the root of all classes this is a weird exception... Thats why the compiler prohibits this assignment. If you really need such assignment look for the use of wildcards.
    bye
    TPD

  • Question about declaring type as interface

    Hi
    I am trying to get my head around declaring an object as the interface type (I think this is right correct me if I am wrong). Ok so I understand if I declare my object reference as the interface I will only get the methods of the interface defined in the objects class..? ie
    List myList = new ArrayList();I think any method particular to ArrayList will not be there. But I dont actually understand wha is happening here, I have a ref to a List but the object is actually an ArrayList?
    So if I passed ths list to a session object and got it out I could cast it back to the interface. I dont understand why or what is happening here.
    I hope someone understands my question enough that they can help me out, this has been nugging me for a while.
    Thanks

    I am trying to get my head around declaring an object
    as the interface type (I think this is right correct
    me if I am wrong). Ok so I understand if I declare my
    object reference as the interface I will only get the
    methods of the interface defined in the objects
    class..? ie
    List myList = new ArrayList();I think any method particular to ArrayList will not
    be there. If you use myList without casting, then, yes, only List's methods will be available, because all the compiler knows is that it's a reference to a List. It doesn't know that at runtime it will point to an ArrayList object.
    You could cast myList to ArrayList to get ArrayList-specific things (if there are any), but a) if you're not careful, you can end up with a ClassCastException at runtime (you won't here, but in general you can) and b) if you're going to do that, you have to question why you declared it as a List in the first place. There are cases where casting is appropriate, but you have to be careful.
    But I dont actually understand wha is
    happening here, I have a ref to a List but the object
    is actually an ArrayList?Yes.
    So if I passed ths list to a session object and got
    it out I could cast it back to the interface. I dont
    understand why or what is happening here.You could cast it to anything that the object actually is, that is, any of its superclasses and superinterfaces. If it's an ArrayList, you could cast it to any of the following: ArrayList, AbstractList, AbstractCollection, Object, Serializable, Cloneable, Iterable, Collection, List, RandomAccess.

  • How to bind bar chart(columns) to array list object in c# win form

    how to bind bar chart(columns) to array list  object in c#win form

    Hi Ramesh,
    Did you want to bind list object to bar chart? I made a simple code to achieve binding list to bar chart.
    public partial class Form0210 : Form
    public Form0210()
    InitializeComponent();
    private void Form0210_Load(object sender, EventArgs e)
    BindData();
    public void BindData()
    List<int> yValues = new List<int>(new int[] { 20, 30, 10, 90, 50 });
    List<string> xValues = new List<string>(new string[] { "1:00", "2:00", "3:00", "4:00", "5:00" });
    chart1.Series[0].Points.DataBindXY(xValues, yValues);
    The links below might be useful to you:
    # Data Binding Microsoft Chart Control
    http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx
    # Series and Data Points (Chart Controls)
    https://msdn.microsoft.com/en-us/library/vstudio/dd456769(v=vs.100).aspx
    In addition, if I misunderstood you, please share us more information about your issue.
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • Doubt about Tunning View Objects

    Hi !. I have the following doubt about tunning View Objects:
    If I have the following configuration on a VO:
    All Rows
    In Batches Of: 11
    As Needed
    Access Mode: Scrollable
    Range Size: 10
    Total Records On The Table: More than 100
    What would happen is that while the initial render, the view cache is fetch with 11 rows from the table and the ui table shows 10. In subsequent scroll events, more queries again will be done but not when the user scrolls back. My doubt is this one: Why, while the initial render If I put a breakpoint in this overrided method executeQueryForCollection, the execution reachs there but in subsequent scroll events (forward) the execution doesn't reach there ?. I understand thast this should happen as the required rows are not yet in the cache. I would like to know a way to test this access mode and what method is executed in every roundtrip to the DB. Thankx !.

    I don't think ADF needs to execute the query again - it just needs to fetch the next set of records.
    So if the cursor is already open, no need to issue another query.
    You can use the HTTP Analyzer to watch network traffic
    Monitoring ADF Pages Round-Trips with the HTTP Analyzer
    And you can use the logging features of ADF to see the queries being executed.
    Declarative View Objects (VOs) for better ADF performance

  • Query builder how to list objects, description for universe

    need query to list objects, object type, object description, object hidden property for selected universe

    All information about Universes available using Query Builder can be queried like this:
    SELECT * FROM CI_APPOBJECTS WHERE SI_KIND = 'Universe'
    Information such as objects used, etc, needs to be retrieved through the SDK:
    A sample for this exists in the developer library:
    [Direct Link to Sample|http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/en/BO_SDK/unv_info_vb/data/dessdk_com_unvInfo_sample_115_en.zip]
    "This is a Visual Basic 6.0 application which traverses the Universe Designer SDK object model and outputs the universe details to a HTML file."
    http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/devsuite.htm

  • X-post: Puzzled about RMI

    Folks, yes I am cross posting this so try to keep the flames down :) I've also placed it on the RMI forum but no one there seems to want to help and I know everyone in the "Advanced" forum are very helpful (do you like the flattery???).
    Anyway, I'm just playing with RMI now and have followed the tutorial but I am a little puzzled about some behaviour I'm observing. This may be that I am missing a piece of information about RMI or how it works so if anyone can fill in the blanks then I would be most appreciative!!!
    So I've got the following Remote interface definition:import java.rmi.*;
    public interface RMIInterface extends Remote
        public int getValue () throws RemoteException;
        public void setValue (int val) throws RemoteException;
    }And I have some code that implements that interface. This code also contains a main method that performs some stuff with the RMI object. It is given below:import java.rmi.*;
    import java.io.*;
    public class RMIObject implements Remote, RMIInterface, Serializable
        private int value = 0;
        public int getValue ()
                             throws RemoteException
         return this.value;
        public void setValue (int    val)
                              throws RemoteException
         this.value = val;
        static public void main (String argv[])
         try
                 // Create the object.
             RMIObject o = new RMIObject ();
                 // Bind it in.
             Naming.rebind ("//localhost/RMIObject", o);
                 // Now get a reference to the object from the name server.
             o = (RMIObject) Naming.lookup ("//localhost/RMIObject");
                 // Set the value to 100.
                 o.setValue (100);
                 // Print out the value.
             System.out.println (o.getValue ());
                 // Get ANOTHER reference to the object.
             o = (RMIObject) Naming.lookup ("//localhost/RMIObject");          
                 // See what the value is.
             System.out.println (o.getValue ());
         } catch (Exception e) {
             e.printStackTrace ();
    }As you can see, I bind the object, then get a new reference to the object, set a value then get the reference again and see what the value is.
    The output I get from this code is:
    100
    0
    Which indicates that setValue is working when the reference is local but it's not updating the remote object. Now the question is, is this the way that RMI is supposed to work? i.e. should you NOT use RMI objects for holding state? If so what's the point because effectively the object would be isolated...can anyone shed any light on this?
    BTW, I am NOT a student and this is NOT related to any exam/coursework question!!!

    Easy folks...my reference to my potential student status was supposed to be "tongue-in-cheek", tis been a LONG time since I could get up when I want and pretend that I was really overworked and complain that I had too many assignments...
    Now of course I am overworked and have too many assignments...least I get paid now...
    Thanks for the help on this, I like to understand the mechanisms behind things, RMI from the outside has an appearance of "magic" that annoys me, I wasn't able to find out any description of how it actually works behind the scenes. I had to infer that it acts as a "broker", I presume that the RemoteObject object stores some information about where the JVM that actually holds the object is and then the Client uses this information (again behind the scenes) to get a connection.
    This tends to worry me a bit though, the implication is that each object that is exported also contains a ServerSocket on a particular port that listens for incoming requests. Now I would presume that when it gets the request it then creates a new thread to handle it to prevent IO blocking. Now in a highly utilized system this means a lot of threads and a lot of port access, which is o.k. but that's a big use of resources. Also, if I have 2 objects listening on the same port, how does the JVM distinguish between the 2 objects when the incoming connection is received. The OS will wake up the JVM and inform it of a new connection (at least that's how Unix does it), but does the JVM have some "magic" that allows it to send it to the correct ServerSocket? I suppose that you also need to take into account Thread concurrency issues as well since you are (by definition) creating objects that will be multi-threaded...
    Can anyone enlighten me on some of the above? Are there any books around that describe how RMI actually works...

  • Puzzled about RMI

    Folks,
    I'm just playing with RMI now and have followed the tutorial but I am a little puzzled about some behaviour I'm observing. This may be that I am missing a piece of information about RMI or how it works so if anyone can fill in the blanks then I would be most appreciative!!!
    So I've got the following Remote interface definition:
    import java.rmi.*;
    public interface RMIInterface extends Remote
        public int getValue () throws RemoteException;
        public void setValue (int val) throws RemoteException;
    }And I have some code that implements that interface. This code also contains a main method that performs some stuff with the RMI object. It is given below:
    import java.rmi.*;
    import java.io.*;
    public class RMIObject implements Remote, RMIInterface, Serializable
        private int value = 0;
        public int getValue ()
                             throws RemoteException
         return this.value;
        public void setValue (int    val)
                              throws RemoteException
         this.value = val;
        static public void main (String argv[])
         try
             RMIObject o = new RMIObject ();
             Naming.rebind ("//localhost/RMIObject", o);
             o = (RMIObject) Naming.lookup ("//localhost/RMIObject");
             o.setValue (100);
             System.out.println (o.getValue ());
             o = (RMIObject) Naming.lookup ("//localhost/RMIObject");
             System.out.println (o.getValue ());
         } catch (Exception e) {
             e.printStackTrace ();
    }As you can see, I bind the object, then get a new reference to the object, set a value then get the reference again and see what the value is.
    The output I get from this code is:
    100
    0
    Which indicates that setValue is working when the reference is local but it's not updating the remote object. Now the question is, is this the way that RMI is supposed to work? i.e. should you NOT use RMI objects for holding state? If so what's the point because effectively the object would be isolated...can anyone shed any light on this?
    BTW, I am NOT a student and this is NOT related to any exam/coursework question!!!

    Hi!
    Naming.lookup(..) actually returns a local reference to the server's stub object (which is locally present in the RMI client's machine). This stub takes care of the remote method invocations. Actually I don't understand how could you do the typecasting to the RMIObject but this is not really important right now!
    Let's see what happened in your example:
    First you registered your RMIObject in the registry.
    Then you retrieved a remote reference to it (a local stub, which implements the remote interface of the server object) and you set some variables of it.
    Then you retrieved again that stub (the java system probably instantiated an other stub object) and its variables were initialized also.
    This is not the way as the RMI should be used!
    The Naming.lookup(..) method always returns a Remote interface (if it can, or throws a RemoteException). This return value must be typecasted to the server object's Remote interface (in your example it's RMIInterface).
    Then you can use this object's (interface's) methods as you want to. (actually you use the stub object's methods which converts your calls to remote calls...)
    I hope it's clear now,
    Sany

  • Large Database read into a List Object Memory Problem

    Hi,
    Im building a new database, ive just imported over 50,000 rows into the database across a number of tables from existing csv files.
    I want to extract these rows into a List object. Once extracted i want to process them in a specific way. However when i try to read in over 20,000 rows i get an error which indicates the buffer is full
    java.lang.OutOfMemoryError: Java heap space
            at java.nio.ByteBuffer.wrap(ByteBuffer.java:350)Im currently using the DAO design pattern to read in the values. Could anyone provide me with some advise how i might read in so many rows without running out of memory. The current process is not only failing but is also extreamly slow.
    Thanks in advance

    h1400046 wrote:
    Hi,
    Thanks for your reply,
    This database is fully normalised. Five tables, no relations between them at all.
    The DAO design pattern was chosen so that each table may be selected individually. DAO usually means objects to me. What you're describing sounds more like Table Gateway.
    This means that i get the values from each table in turn. (there isnt a single query). No possibility to JOIN? None whatsoever?
    Five tables must be read for each select. Ouch.
    Therefore i am selecting 5 times for each of the 50,000 rows and some of the rows will bring back more than one record for each table. So it's one object that has references to five others.
    This OO object is tread back into a List object. Once i have this i want to then process this list as a whole. However this obejct gets to big and just kills the memoryYes, that's been clear all along.
    I have been told that jdbc supports a cursor type mechanism which enables you to read from a result set in manageable chunks which can then be processed chunk by chunk without killing the memory. But i dont know how to do that or even if that is advisable.Yes, you can process chunk by chunk with JDBC. Check setFetchSize(), or manage the chunk size yourself.
    I currently have primary keys in each table. I have indexs on both the primary and forigen keysSo there are relationships. I'll ask again - why not JOIN?
    Can the database do any of the processing? What about calling a stored proc to create a cursor and iterate through the data on the server? Just bring the result over via JDBC.
    %

  • Find some examples about pthread by objective-c

    hello,
    Now I am studying pthread. But I can't find some examples about pthread by objective-c. The example is pass to bulid and run. Example is twoThread which can communicate each other. I will still find. If you know some useful infomation,would you support some?
    Thank you very much!

    Hi qzxin-
    Several examples of DAQ programming install with Measurement Studio for Visual Studio .NET. DAQmx examples can be found in this folder of your hard drive: C:\Program Files\National Instruments\MeasurementStudioVS2003\VCNET\Examples\DAQmx . For analog measurements, the syntax for adding multiple physical channels to the operation is "DexX/ai0:n" where X is the device number and n is the last channel in the list.
    Can you let us know more about which DAQ device and which version of Measurement Studio you're using? It would make it easier to suggest an example.
    Thanks,
    Tom W
    National Instruments

  • Concatination of 2 linked list objects of characters

    Pleas help me to solve the following problem by using Java.
    Problem: Write a program that concatenates two linked list objects of characters. The program should include method concatenate, which takes references to both list objects as arguments and concatenates the second list to the first list.
    Thanking u,
    Ripon

    This assumes that your class is 'ListConcatenate' and that you have set up your two link-lists.
         public void concatenate( ListConcatenate l1, ListConcatenate l2)
              if ( l1.isEmpty1() || l2.isEmpty2() )
                   System.out.printf( "Empty %s or Empty %s\n", name1,name2 );
                   return;
              System.out.printf( "%s concatenated with %s is: ", name1,name2 );
              NodeOne current1 = l1.firstNode1;
              NodeTwo current2 = l2.firstNode2;
              while (current1 != null )
                   System.out.printf( "%s ", current1.data1.toString() + current2.data2.toString() );
                   current1 = current1.nextNode1;
                   current2 = current2.nextNode2;
              }

  • LINQ sorting on List Object - Various Object Type

    I try to sort a List<Object> where the Object are different classes but all share the same Property Name for instance.
    I got a Base Class where Class A and Class B inherit from the Base Class.
    So during the Linq query I cannot specify with object type this is.
    Problem here "from ?????Entry_Global?????? list in Entries"
    Thanks for helping.
    ////Entries is a List<Object> which consist of class object as following\\\\\
    public abstract class EntryBase<T>
    private string _Name;
    public string Name
    get { return this._Name; }
    set { this.SetProperty(ref this._Name, value); }
    public class Entry_Global : EntryBase<Entry_Global>
    public class Entry_CC : EntryBase<Entry_CC>
    private string _url; //Web url
    public string Url
    get { return this._url; }
    set { this.SetProperty(ref this._url, value.Contains("http") ? value : "http://" + value); }
    public List<Object> SortBy()
    IEnumerable<KeyedList<string, object>> groupedEntryList = null;
    //The proble reside in the fact that list is not only one type
    //so when comes in the orderby "Name" it doesn't know Name
    //or any other properties which are all common to all those class
    //It does not want to convert Entry_CC or Entry_Global to EntryBase
    groupedEntryList =
    from ?????Entry_Global?????? list in Entries
    orderby list.Name
    orderby list.CategoryRef.Name
    group list by list.CategoryRef.Name into listByGroup
    select new KeyedList<string, object>(listByGroup);
    return groupedEntryList.ToList<object>();

    Entry_Global and Entry_CC don't share the same base class since EntryBase<Entry_Global> and EntryBase<Entry_CC> are two totally different types so you cannot cast the objects in the List<object> to a common base class in this case.
    You could cast from object to dynamic though:
    public List<Object> SortBy()
    List<object> objects = new List<object>();
    objects.Add(new Entry_Global { Name = "K" });
    objects.Add(new Entry_CC { Name = "A" });
    objects.Add(new Entry_Global { Name = "I" });
    objects.Add(new Entry_CC { Name = "C" });
    var sortedObjectsByName = (from o in objects
    let t = (dynamic)o
    orderby t.Name
    select o).ToList();
    return sortedObjectsByName;
    The dynamic keyword makes a type bypass static type checking at compile-time:
    https://msdn.microsoft.com/en-us/library/dd264736.aspx. This basically means that a dynamic type is considered to have any property of any name at compile time. Of course you will get an exception at runtime if the type doesn't have a Name property but
    providied that all objects in the List<T> to be sorted are of type EntryBase<T> you will be safe as long as the EntryBase<T> type defines the Name property that you sort by.
    Please remember to close your threads by marking helpful posts as answer and please start a new thread if you have a new question.

  • Can't print because I have no "print.print_printer" entry in my about:config list?

    I haven't been able to print anything from Firefox for about a month now. My printer works just fine, as I can print from Internet Explorer and Iron browsers without issue. This ONLY happens when I'm using the Firefox browser. Please do not refer me to the article about printer issues - I have already exhausted everything on that list, without resolve.
    I still sometimes use my older computer (same OS - Windows 7 Home Premium) and I checked the about:config list to see what it has that my current computer does not. I found MANY entries for my Canon MX340 computer! Why doesn't my current computer have ANY of these? The printer works perfectly fine with the older computer and Firefox, so I am completely at a loss here. Any suggestions?

    Firefox 6.0 and later use '''print_printer''' for the last used printer.
    In Firefox 5.0 and earlier versions '''''print.print_printer''''' was that preference name.
    As explained here - https://support.mozilla.org/en-US/kb/fix-printing-problems-firefox#w_reset-firefox-printer-setting
    My recommendation is to '''reset all Firefox printer settings''' as explained on that support page..

  • So how do you declare an object?

    Okay I have a program I'm trying to build that lets me navigate between menus...
    Main Menu starts up:
    (Unimportant)
    Then it takes me to another Menu.
    When this is over I want to go back:
       System.out.println("Select: ");
            System.out.println("1: to Return to the main menu");
            System.out.println("or");
            System.out.println("0 to Exit");
         if(input.nextInt()==1){
             main(); // <-- error here
         else if(input.nextInt()==0){
             System.exit(0);
            }   It doesnt find the main method because I didn't declare it as an object at the top...
    How do I do that?
    Edited by: tark_theshark on Mar 30, 2008 5:24 AM

    Nah, this has nothing to do with declaring an object, and you really don't want to do this. What you really want to do is to have a loop of some kind, say a while loop and have the loop repeat until the user presses "0". Something like so:
        public static void main(String[] args)
            boolean done = false;
            while (!done)
                if(input.nextInt() == 0)
                    done = true;
        }Edited by: Encephalopathic on Mar 30, 2008 6:27 AM

Maybe you are looking for

  • HELP! FOR LOOP TO SCROLL THROUGH TABLE AND CREATE DATABASE LINK

    Hi, Here's the scenario, not much of a PL programmer, just basic SQL so really need some help people! I have 2 tables. 1 contains list of DB's and the other contains rules to follow. I need to create a loop that goes through the table containing the

  • Can I open a .pub file in iworks?

    I have been sent some files created in publisher with a .pub extension. Can I open thses in iWorks09?

  • Folio builder

    Folio builder has stopped logging in, says a software update is required but software is right up to date. Worked fine yesterday. Any ideas Ian

  • Firewire to usb2

    I am looking to buy a camcorder that has a usb2 interface. In the interest of speed, is there an adapter that I can buy that I can plug this usb2 device into my firewire port on my iMac G4 flat panel? Mark

  • Automatic assignments of accounts were missed(ao90)

    Hi All, Can you please guide me how to assign automatic assignment of accounts which are configured in AO90.. the error is 700 assets were desposed in one invoice where customer is debited and 700 assets were credited with same GL account as a machin