Vector Use as a container

Hi guys,
I have to use a Vector object to store a growable array of objects,but
I have an implementative question :
I have to create the Vector only the first time the class cointaining
it will be extecuted , then I have to add elements ,
without deleting old entries , and creating new instances of the
class :
Here is my actual simple code , that I think will delete all my
entries every time the class is executed.
Another question : after deserializing a class , I need to
instanciate it?
Thanks a lot guys!!! bytebye
(please note that I'm obliged to use Vector..)
public class AgentMessage implements Serializable{
private static final long serialVersionUID = 1L;
transient private StaticPart sp;//per metodo get
transient private DynElement de;
private Vector dynvector;
public AgentMessage(String agent,byte[] code,String
mainclass,Certificate signerId,PrivateKey priv,String
configuration,Serializable dclear,byte[] dsecret,PathEl[] dpath,byte[]
c){
sp=new
StaticPart(agent,code,mainclass,signerId,priv,configuration);
de=new DynElement(dclear,dsecret,c,dpath);//deve diventare vector
dynvector=new Vector();/
dynvector.add(de);
}

Hi guys,
I have to use a Vector object to store a growable
array of objects,but
I have an implementative question :
I have to create the Vector only the first time the
class cointaining
it will be extecuted , then I have to add elements ,
without deleting old entries , and creating new
instances of the
class :
Here is my actual simple code , that I think will
delete all my
entries every time the class is executed.You're looking for your Vector to be declared static. This would create your Vector object only once, and facilitates growing it subsequently per instance of your class.
Another question : after deserializing a class , I
need to
instanciate it?
Thanks a lot guys!!! bytebye
(please note that I'm obliged to use Vector..)
Serialization is applicable per instance of your class. Hence, "deserializing a class" holds no water.
public class AgentMessage implements Serializable{
private static final long serialVersionUID =
1L;
transient private StaticPart sp;//per metodo
get
transient private DynElement de;
private Vector dynvector;
public AgentMessage(String agent,byte[]
code,String
ainclass,Certificate signerId,PrivateKey priv,String
configuration,Serializable dclear,byte[]
dsecret,PathEl[] dpath,byte[]
c){
sp=new
t,code,mainclass,signerId,priv,configuration);
de=new
DynElement(dclear,dsecret,c,dpath);//deve diventare
vector
dynvector=new Vector();/
dynvector.add(de);
}Please embed your code in  the next time for better readability.

Similar Messages

  • How to use embeddable EJB container (Java EE 6 / EJB 3.1) on Mac OS?

    To my understanding, the intent of the embeddable EJB 3.1 container is - among others - to support out-of-container testing. I've created a JUnit test case that uses glassfish embeddable for integration testing of ejb 3.1 Light ejbs. I run the tests using Maven.
    I have one general problem and one problem specific to Mac OS (I'm not able to use the embeddable container at all on Mac OS).
    1. First the general problem: the ejb container does not inject or publish classes that are on the test class-path only:
    src>main>java>MyEjb.class
    src>test>java>MyTestEjb.class
    The test case looks like this:
    public class TestCase1b {
         static EJBContainer container;
         @BeforeClass
         public static void initEjbContainer() {
              container = EJBContainer.createEJBContainer();
              for ( Object property : System.getProperties().keySet() ) {
              System.out.print(property + " : ");
              System.out.println(System.getProperty((String)property));
         @Test
         public void canTestWithTransaction() throws NamingException, NotSupportedException, SystemException {
              Context ctx = container.getContext();
              OrderServiceTesterEjb orderServiceTester = (OrderServiceTesterEjb) ctx
                        .lookup("java:global/classes/OrderServiceTesterEjb");
              Assert.assertNotNull(orderServiceTester.testCreateOrderWithTransaction());
         @AfterClass
         public static void closeEjbContainer() {
              container.close();
    The idea with a test-ejb is to mimic the way I typically perform junit integration testing with Spring: the test database i preloaded with test data. Each test-method of the junit test case starts a transaction, invokes the service, evaluates the state of the database and finally performs a rollback. My idea was to mimic that by creating a test ejb (Stateless, REQUIRES_NEW), that injects the EJB to test, calls the method to test, evaluates the result or db state and finally sets rollbackonly before returning. The problem is that the test case can lookup ejbs in src/main/java, but not the "test" ejbs in src/test/java. My workaround is to include the test-EJBs in src/main/java which I think is not acceptable.
    2. Next the Mac-problem:
    The Mac OS JDK 1.6 contains version 1.0 of javax.annotation (jsr 250). EJBs developed with Java EE 6 depends on version 1.1 of javax.annotation. Specifically, one typically need @Resource(lookup=... and @DataSourceDefinition of javax.annotation.sql which are both missing in the JDK. I can compile my EJBs by adding the javaee-api-6.0.jar library to my classpath. But when running unit tests with maven (as described above), a runtime error is reported, stating that the lookup-property of the @Resource annotation is undefined. This is logical, since the boot classpath should have precedence. So I added javaee-api-6.0.jar to the lib/endorsed directory of the jre. Unfortunetely, this triggers a segmentation fault of the Mac OS JVM when running the test. I have no other workaround than switching to windows. Any help / hints are much appreciated.
    /Johan

    Just as an update, we're soon to release the WLS 11g R1 PS2 update, which will contain WLS 10.3.3 just to confuse things.
    As part of that, we're distributing for the first time, an additional .zip version of WLS to make it easier for developers.
    The zip file distribution has no GUI installer -- it's a simple case of unzip, run a script it provides, then start the server.
    The zip file distribution has been specifically tested on Mac OS X and the WLS config/domain scripts automatically adjust as necessary for the Mac OS X java environment.
    Once the zip file distribution is available, we hope that developing against WLS on Mac OS X (and Windows/Linux) will be an easier task.
    -steve-

  • GroupLayout can only be used with one Container at a time

    Dear all,
    I am a beginner so please don't throw rocks at me...
    I have created two frames with NetBeans. One is the main frame (extends from JPanel) and the other frame I put it to be started when pressing a button from the main frame (the second frame extends from JFrame). Both frames are created using the designer in NetBeans, so the code for creating the GUI is automatically generated by NetBeans, so both frames use the same layout (GroupLayout).
    Here is the code of the button from the main frame to start the second one:
    private void manageCustomersActionPerformed(java.awt.event.ActionEvent evt) {                                                
            // TODO add your handling code here:
            CustomerGUI custGUI1=new CustomerGUI();//CustomerGUI is the second frame
            custGUI1.setVisible(true);
    }When I press this button from the main frame I get this runtime exception: Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: GroupLayout can only be used with one Container at a time. The second frame is not opened.
    How should I handle this?
    What I want to do: I want to have a main frame, from which I can start additional ones (the main frame must be always opened, while the additional ones can be closed after performing certain actions). I read a little about internal frames and I think this can be a solution, but I must edit the existing design...
    Thank you
    With respect,
    Don
    Edited by: don1983p on Dec 16, 2008 2:21 AM

    AndrewThompson64 wrote:
    There are those that maintain that JFrame should never be extended. I am not convinced, but most cases where a JFrame is extended would be better coded as simply configuring the JFrame within the main(). GUI builders such as found in NetBeans seem to extend JFrame as a matter of course.I too am not rigorous or religious about this either, but try to adhere to this as a matter of practicality and convenience, I find that if I don't extend a JComponent but rather use composition rather than inheritance, it's much easier to use objects of my class when programming in Eclipse. For instance in Eclipse (and in most IDEs), if I type my object name and then a period, it will show all of the method's available for me to use on this object. If I subclass JPanel or JFrame, I'll see a gazillion methods most I don't want to see, and thus most are clutter. On the other hand if I use composition, I'll only see a small number of methods and these will be only the methods that I want to see and need to use.

  • Error while integrating OBIEE report with EBS using Rich Content Container

    I am trying to integrate OBIEE report with EBS using Rich Content Container OAF functionality. I have followed the steps mentioned in oracle Note - Embedding Analytics in Oracle E-Business Suite [ID 974422.1]. When i run my page, the container region comes up with the error message - The requested URL /pls/ghrfpkd2/OracleSSWA.Execute was not found on this server. Can someone please help me with some documents on the steps to integrate OBIEE with EBS using Rich Content Container.

    I'm getting the same error on WebSphere 6.1.5. Is there any solution for this?

  • Error: The Java Runtime in use does not contain a suitable JAXP feature

    Hi,
    I'm trying to get Eclipse TPTP to work. One of the steps I need to execute is to run a setConfig.bat file. When I ran it, I got the following error:
    ERROR: The Java Runtime in use does not contain a suitable JAXP feature
    RESOLUTION: Use a JRE which supports the JAXP featureI use Eclipse Europa, and it is using my JDK (actually JRE) 1.6.0_05. That should mean I have JAXP in my JRE (which is confirmed when I search on JAXP from the directory C:\Program Files\Java containing jdk1.6.5_05 and jre1.6.5_05 directories).
    Is there something extra I need to do to let Eclipse and TPTP find my JAXP classes?
    TIA,
    Abel

    Hi,
    Even i am getting the same error but i use JRE 1.5.0_14. please let me know if you happen to resolve this.
    Thanks in Advance,
    Sai

  • How do you use the "Item Containing Start/End Date" in a Calendar?

    Hi
    I want to do a calendar where the days shown will be conditional to a certain interval. Now I though I could achieve that using the Item Containing Start Date of a calendar. But it doesn't seem to work. In the help it says :
    Enter an item in the application which holds the start date of the calendar. The format of the date in this item must be YYYYMMDD.
    This is what I did here
    http://apex.oracle.com/pls/otn/f?p=34530:1::::::
    I have 3 fields. 2 for the Start Date and End Date and 1 for the "Date Item" parameter. Only the latter has an effect on the calendar display, the calendar only displays the month of the "Date Item" (in monthly mode).
    Wether or not I check "Begin at Start of Interval", it doesn't affect the way those fields are affecting the Calendar.
    So, how do we use that "Item Containing Start/End Date" parameter?

    Hello,
    does yout Script work when you begin with ?:
    Start-Process powershell -Verb runAs
    Best regards,
    Stefan
    German Orchestrator Portal ,
    My blog in English

  • This domain name can't be used because it contains a protected word or inappropriate language.

    Dear
    Creating a Microsoft services experience for my domain (fazlic.ba), is showing an error message as below:
    "This domain name can't be used because it contains a protected word or inappropriate language. Please contact support if you feel this is not the case."
    Can somone help in resolving this issue as i need this bit urgent and i am trying for same since last 2 days but with no success
    My domain name is fazlic.ba, which needs to be added as custom domain in domain.live.com
    Thanks

    Hi,
    we cannot provide any solution here because the domain validation is the second step of the process and is automated.
    My advice wouldbe to follow the message guideline and contact the support, they may identify why this domain is refused.
    Hope this helps,
    Fabrice DI GIULIO, http://blog.digiulio.fr
    Technical Solutions Professional, EMEA at AvePoint

  • This domain name can't be used because it contains a protected word or inappropriate language. Please contact support if you feel this is not the case.

    we are unable to domain smippl.com it gives error
    This domain name can't be used because it contains a protected word or inappropriate language. Please contact support if you feel this is not the case.
    It is a real estate company :
    SARLA MADAN INFRASTRUCTURE PROJECTS PRIVATE LIMITED
          Address : "SWAYANG TOWER" (STILT FLOOR),
          Plot No. M-73, Madhusudan Nagar, Unit-IV, Bhubaneswar-751001, Odisha,
          India
    current email : [email protected]
    Domain to setup email in Windows Live outlook express  - smippl.com
    waiting for solution

    Hi,
    I wonder if you are registering domain name here:
    https://domains.live.com/Signup/SignupDomain.aspx?dn=&ss=0&ctkn=&et=0
    If so contact with windows live support:
    https://support.live.com/default.aspx?scrx=1
    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.

  • Using databases and container events?

    I'm having trouble finding documents show how one should use databases and listen for container events? I'm using Berkley Java DB. I'll need all my remote object to have access to the database. How do I pass that in? Custom adapters? Also, when Tomcat shuts down I need to close the database, how would this be down? Custom adapters? So I may be answering my own question, but I'm asking cause I really don't see anything in the documentation that points this out. It really looks like I'd be using singletons and factories for this. I could register a Servlet or Servlet Context to listen for Tomcat events, but I figured it couldn't hurt to ask others using Blaze, as I'm very new to it. Thanks.

    So how would you tell Blaze to use this? Is there something you put into the config file? My thoughts on all this is to use PicoContainer to manage all services then create an adapter to inject all resources when creating remote objects. But this seems a little heavy if Blaze can do all this for me. The adapter seems like the injection point to me. Is that not what it's used for? Or is using it like that bad practice under Blaze? I've read all I can find on Blaze, so either it's missing docs, or I'm not finding them all. If I'm missing them, by all means let me know where to go. I don't want to ask questions that are already answered in documents else where.
    On Tue, May 20, 2008 at 10:51 AM, Mete Atamel <
    [email protected]> wrote:
    A new message was posted by Mete Atamel in
    General Discussion --
      Using databases and container events?
    I think it's mainly in JavaDocs but here's a sample I have where I check to make sure the HSQLDB is running as the BlazeDS starts up:
    import java.sql.Connection;
    import java.sql.SQLException;
    import flex.messaging.config.ConfigMap;
    import flex.messaging.services.AbstractBootstrapService;
    public class DatabaseCheckService extends AbstractBootstrapService
        // This is called right before server starts up.
        public void initialize(String id, ConfigMap properties)
            Connection c = null;
            try
                // Check that the database is running...
                c = ConnectionHelper.getConnection();
                // ... if yes return
                return;
            catch (SQLException e)
                System.out.println("DB is not running!");
            finally
                ConnectionHelper.close(c);
    // This is called as server is starting.
        public void start()
            // No-op
    // This is called as server is stopping.
        public void stop()
            // No-op
    View/reply at
    Using databases and container events?
    Replies by email are OK.
    Use the
    unsubscribe form to cancel your email subscription.
    "All that is necessary for the triumph of evil is that good men do nothing." - Edmund Burke

  • Send Vector class to JSP and print this Vector using JSTL

    Hello All!
    I need your help to solve my question.
    I developed a Servlet + jsp application.
    I tested it in local with Apache Tomcat/6.0.20 and it works correctly.
    I write and use these classes:
    class for execute query, and including data page:
    package MySQL;
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.util.*;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    * @author initmax
    public class MySQLQuery {
        private Connection CurrentConnect; //obj for connect to databae
        private Vector VectorPageObj = new Vector(); //save array object page, after execute query
    public MySQLQuery() {}
    //constructor accept current conection database
    public MySQLQuery(Connection CurrentConnectBase)
        CurrentConnect = CurrentConnectBase;
    //method accept name table and return all info on this table
    public void SelectAllField(String NameTable)
           try
             Statement st = CurrentConnect.createStatement();
             String query = ("select * from "+NameTable);
             ResultSet resultQuery = null;
             resultQuery = st.executeQuery(query);
    //step in cycle after execution query, and create Vector object
               while (resultQuery.next())
                  GenPageMySQL PageObj = new GenPageMySQL();
                  PageObj.setId(resultQuery.getInt("id"));
                  PageObj.setTheme(resultQuery.getString("theme"));
                  PageObj.setPage(resultQuery.getString("page"));
                  VectorPageObj.add(PageObj); //add obj in tail vector
           catch (SQLException e) {
             e.printStackTrace();
        *@set the CurrentConnect
        public void setConnection(Connection CurrentConnectBase) {
             CurrentConnect = CurrentConnectBase;
        *@get Vector object "Vector created after execute query"
         public Vector getVectorPageObj(Connection CurrentConnectBase) {
             return VectorPageObj;
    }start Servlet class:
    import java.util.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import MySQL.*;
    public class indexServlet extends HttpServlet {
        private  String getpage;
        //Connected MySQL
        private MySQLConnect MySQLConnectObj = new MySQLConnect();
        private MySQLQuery MySQLQueryObj = new MySQLQuery();
        public void init(){
              MySQLConnectObj.DownloadDriver();
              MySQLConnectObj.Connected();
              //Use current connection, for execution query
              MySQLQueryObj.setConnection(MySQLConnectObj.GetConnection());
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException, NullPointerException  {
      //      init();
            PrintWriter out = response.getWriter();
    //GET case useer
          getpage = request.getParameter("page");
          out.print("MySQLConnectObj.GetConnection() = "+MySQLConnectObj.GetConnection()); 
    //Check curent connect to database
          if(MySQLConnectObj.GetConnection() != null)
               MySQLQueryObj.SelectAllField("up_menu");//execution query
               MySQLConnectObj.DisConnected();
                request.setAttribute("up_menu_theme",MySQLQueryObj.getVectorPageObj(null));
                RequestDispatcher Dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/jsp/index.jsp");
                Dispatcher.forward(request, response);
          else if(MySQLConnectObj.GetConnection() == null){
                init() ;
            out.print("MySQLConnectObj.GetConnection() = "+MySQLConnectObj.GetConnection());
    //        MySQLConnectObj.DisConnected();
    }I forward Vector "MySQLQueryObj.getVectorPageObj(null)" to JSP, how I can print data vector using JSTL?

    your right, I learn Java however this very Interesting!
    I change code, change Vector on List
    class MySQLQyery:
    package MySQL;
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.util.*;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    * @author initmax
    public class MySQLQuery {
        private Connection CurrentConnect; //obj for connect to databae
    public MySQLQuery() {}
    //constructor accept current conection database
    public MySQLQuery(Connection CurrentConnectBase) {
        CurrentConnect = CurrentConnectBase;
    //method accept name table and link on List, after work return all info on this table inside List
    public List<GenPageMySQL> selectAllField(String NameTable, List<GenPageMySQL> ListPageObj) {
           try {
             Statement st = CurrentConnect.createStatement();
             String query = ("select * from "+NameTable);
             ResultSet resultQuery = null;
             resultQuery = st.executeQuery(query);
    //step in cycle after execution query, and create Vector object
               while (resultQuery.next()) {
                  GenPageMySQL PageObj = new GenPageMySQL();
                  PageObj.setId(resultQuery.getInt("id"));
                  PageObj.setTheme(resultQuery.getString("theme"));
                  PageObj.setPage(resultQuery.getString("page"));
                  ListPageObj.add(PageObj); //add obj in tail vector
           catch (SQLException e) {
             e.printStackTrace();
           return ListPageObj;
        *@set the CurrentConnect
        public void setConnection(Connection CurrentConnectBase) {
             CurrentConnect = CurrentConnectBase;
      List<GenPageMySQL> ListPageObj;
                //get List<RowObject>
                ListPageObj = MySQLQueryObj.getListPageObj();
      out.print("Size Page objects = "+ListPageObj.size());
                request.setAttribute("upMenu",ListPageObj);
                RequestDispatcher Dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/jsp/index.jsp");
                Dispatcher.forward(request, response);string out.print("Size Page objects = "+ListPageObj.size()); == worked, I get count objects correct
    How I can output fields Object GenPageMySQL in JSTL?
    writing so:
             <c:out value="hello, Max" />
             <c:out value="${10+20/2}" />
             <c:forEach items="${upMenu}" var="Object" >     
                   <c:out value="${Object.getId}"> </c:out>
             </c:forEach>
        </body>
    </html>but get error:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/index.jsp at line 36
    33:          <c:forEach items="${upMenu}" var="Object" >
    34:         
    35:                 
    36:                <c:out value="${Object.getId}"> </c:out>
    37:
    38:    
    39:          </c:forEach>
    Stacktrace:
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         indexServlet.doGet(indexServlet.java:49)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)How I can in output print fields my Object?
    Thank you for your help.

  • What is the exact use of Sequence container

    Hi all,
       I am intermediate in SSIS package,i am not understanding what is the exact use of Sequence container ?
      I am preparing for interview(3 years exp), if experts dont mind can you pls share some tips and questions to clear the interview ?
     pls
    thanks

    Hi SelvakumarSubramaniam,
    This blog delivers a good summary of the benefits we can get by using Sequence Container:
    Easier debugging by allowing you to disable groups of tasks to focus package debugging on one subset of the package control flow.
    Managing multiple tasks in one location by setting properties on a Sequence Container instead of setting properties on the individual tasks.
    Provides scope for variables that a group of related tasks and containers use.
    Create a transaction around all the components inside the container.
    Here are some other good resources:
    http://www.phpring.com/sequence-container-in-ssis/ 
    http://sql-developers.blogspot.com/2010/06/sequence-container-in-ssis.html 
    Regards,
    Mike Yin
    TechNet Community Support

  • How to display ArrayList of Vectors using Expression Language in a JSP

    I have added all my values in a vector and this vector is then added to a List. How can I loop through this List, Vector and values in Vector using EL on JSP side. If you have any idea, pl. help with sample code.

    Hi Kavita,
    Well to display each employee information on jsp, you can use following code sceanarion.
    <%
    Iterator it= list.iterator();
    while(it.hasnext()){
       Employee emp=(Employee) it.next();
    %>
    <tr>
    <td><%= emp.getName()%></td>// In the similar fashion you can display other attributes of employee in other td's.
    </tr>
    <%
    }%>Hope this would be helpful to you.
    Regards,
    Gaurav Daga

  • Freeze header row using over overflow container

    hi All,
    I have an issue with my header in the gridlayout element, we are using the overflowcontainer element.
    When there is a scroll bar and user scrolls, the header also scrolls, we want to just scroll the line items and the header should be frozen,
    any suggestion please ?

    Hi Friend,
    You can achieve your requirement by using xhtmlb overflow container.Check the below link.
    [link|Freeze header in BSP page which is using Grid Layout]
    With Regards,
    SHARMILA BRINDHA.M

  • Sorting a vector using the selection sort method

    I have to write a program that sorts a Vector using the selection sort algorithm. Unfortunately the textbook only has about 2 pages on vectors so needless to say I'm pretty clueless on how to manipulate vectors. However I think I'm on the right path, however I'm stuck on one part as shown in the code below.     
    private static void  selectionSort(Vector parts)
          int index;
            int smallestIndex;
            int minIndex;
            int temp = 0;
            for (index = 0; index < parts.size() - 1; index++)
              smallestIndex = index;
              for (minIndex = index + 1; minIndex < parts.size(); minIndex++)
               if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))  // this is where I'm having trouble
                  smallestIndex = minIndex;
                parts.setElementAt(temp, smallestIndex);
                parts.setElementAt(smallestIndex, index);
                parts.setElementAt(index, temp); if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))
    is returning "ProcessParts3.java:51: operator < cannot be applied to java.lang.Object,java.lang.Object"
    Here is the full program:
    import java.util.*;
    import java.io.*;
    public class ProcessParts3
         static Vector parts;
         public static void main(String[] args)
              loadVector();
         private static void loadVector()
         try
              Scanner fileIn = new Scanner(new File("productionParts.txt"));
              parts = new Vector();
              String partIn;
              while (fileIn.hasNext())
                   partIn = fileIn.nextLine();
                        parts.addElement(partIn.trim());
              selectionSort(parts);
                   for (int i = 0; i < parts.size(); i ++)
                   System.out.println(parts.elementAt(i));
         catch(Exception e)
              e.printStackTrace();
         private static void  selectionSort(Vector parts) //from this part down I'm responsible for the coding, everything
                                                               // everything above this was written by the teacher
                 int index;
            int smallestIndex;
            int minIndex;
            int temp = 0;
            for (index = 0; index < parts.size() - 1; index++)
                smallestIndex = index;
                for (minIndex = index + 1; minIndex < parts.size(); minIndex++)
                    if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))
                        smallestIndex = minIndex;
                parts.setElementAt(temp, smallestIndex);
                parts.setElementAt(smallestIndex, index);
                parts.setElementAt(index, temp);
    }Edited by: SammyP on Nov 27, 2009 11:43 AM

    SammyP wrote:
    I have to write a program that sorts a Vector using the selection sort algorithm...Hmmm.... Your teacher is, in my humble opinion, a bit of a tard.
    1. Vector is basically deprecated in favor of newer implementations of the List interface which where introduced in [the collections framework|http://java.sun.com/docs/books/tutorial/collections/index.html] with Java 1.5 (which became generally available back in May 2004, and went end-of-support Oct 2009). ArrayList is very nearly a "drop in" replacement for Vector, and it is much better designed, and is marginally more efficient, mainly because it is not syncronised, which imposes a small but fundamentally pointless overhead when the collection is not being accessed across multiple threads (as is the case in your program).
    2. Use generics. That "raw" Vector (a list of Objects) should be a genericised List<String> (a list of Strings)... because it's compile-time-type-safe... mind you that definately complicates the definition of your static sort method, but there's an example in the link... Tip: temp should be of type T (not int).
    Note that String implements [Comparable<String>|http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html], so two String's can safely be compared using the compareTo method... In Java the mathematical operators (<, >, &#43;, -, /, &#42;, etc) are only applicable to the primitive types (byte char, int, float, etc)... The Java Gods just chose to muddy the waters (especially for noobs) by "overloading" the &#43; operator for String (and String only) to enable succinct, convenient string-concatenation... which I personally now see as "a little bit of a mistake" on there part.
         private static void  selectionSort(Vector parts)  {
    int index, smallestIndex, minIndex, temp = 0;
    for (index = 0; index < parts.size() - 1; index++) {
    smallestIndex = index;
    for (minIndex = index + 1; minIndex < parts.size(); minIndex++) {
    if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex)) {
    smallestIndex = minIndex;
    parts.setElementAt(temp, smallestIndex);
    parts.setElementAt(smallestIndex, index);
    parts.setElementAt(index, temp);
    }3. ALLWAYS use {curly braces}, even when not strictly necessary for correctness, because (a) they help make your code more readable to humans, and also (b) if you leave them out, you will eventually stuff it up when you insert a line in the expectation that it will be part of the if statement (for example) but you forgot to also add the now mandatory curly-braces... This is far-too-common source of bugs in noob-code. Almost all professionals, nearly allways allways use curly braces, most of the time ;-)
    4. Variable names should be meaningful, except (IMHO) for loop counters... Ergo: I'd rename index plain old i, and minIndex to plain old j
        for ( int i=0; i<list.size()-1; ++i) {
          int wee = i; // wee is the index of the smallest-known-item in list.
          for ( int j=i+1; j<list.size(); ++j ) {Cheers. Keith.
    Edited by: corlettk on 28/11/2009 09:49 ~~ This here fraggin forum markup friggin sucks!

  • Create another object using the same container generated by a split...

    Hi SapGears!
    I'm facing a problem about creating an object using a splited container.
    I split the container A in containers A1 and A2 and create alv in A1 and html in A1.
    After that, i need to create a toolbar buttons using the class cl_gui_toolbar in A2 without need to recreate all again.
    I Try to call method free( ) and recreate the object, but the container A2 appears in blank.
    any help will be very nice!!!

    I would try different solution. Split A2 into two new rows B1 and B2. In B1 set your toolbar, in B2 your alv. By default set B1 cell hidden
    "suppress splitter bar
    CALL METHOD gr_splitter_cont->set_row_sash
        EXPORTING
          id    = 1
          type  = gr_splitter_cont->type_movable
          value = gr_splitter_cont->false.
    "show only alv in entire cell
      CALL METHOD gr_splitter_cont->set_row_height( id = 1 height = 1000 ).
    Now when you request for toolbar display only that cell
        CALL METHOD gr_splitter_cont->set_row_height( id = 1 height = 0 ).
    A kind of workaround but you will avoid much troubles.
    Regards
    Marcin

Maybe you are looking for

  • Can't find most of my songs on my iPhone 5. They only show up on the computer. How do I fix it?

    I just updated my software and now I can't seem to locate most of my songs on my iPhone 5. When I'm in the "on this iphone" tab, I can see all of the music I've added to the iphone library. However, when I look on my actual phone none of them are the

  • Get back to previously submitted job in OEM

    Hi all, From Advisor Central I clicked "implement" button to shrink a table segment. I strayed away to look for something else but I don't know how to get back to the job to check the job status. I searched in the Jobs tab and Reports tab based on th

  • 7210 will no longer print.

    My 7210 All-in-one no longer prints (after 3 years of service). It will still scan and copy, but the printer is no longer recognized. I have an HP computer with Windows Vista, 64-bit. The default , printer is Microsoft XPS Document writer, but the 72

  • Downloading Adobe Reader for Windows should be simple and it's not.  I'm surprised and frustrated!

    Can someone tell me which link on the download site I should use?  All I want is the free reader for Windows 8.1. Can't you do a better job on this? Here are the choices I am given: PDF iFilter 64 11.0.01 19.6 MB 1/8/2013 Updates/Programs All version

  • How do you set/find the directory path for /i/

    Searching the forum, I found one note that indicated this was set in MARVEL.CONF (since I'm running 2.0, presumably DADS.CONF). However, looking at the DADS file for my install, I don't see anything resembling a directory mapping. What would the synt