You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Randy Layman <ra...@aswethink.com> on 2002/01/10 21:08:28 UTC
RE: Vectors? Why does this not work?
First, you should take this question to another forum since this one
is about the Tomcat Servlet Container.
Second, you probably need to do some basic Java learning since this.
Third, you are using static variables to hold your names.
Randy
> -----Original Message-----
> From: Rick Roberts [mailto:techinfo@ait-web.com]
> Sent: Thursday, January 10, 2002 3:50 PM
> To: Tomcat Users List
> Subject: Vectors? Why does this not work?
>
>
> Why does this simple example not work?
> I am using Tomcat 3.3 and JDK 1.3.1_01 and Redhat Linux 7.2
>
> Thanks,
>
> ==============
>
> // SimpleClass.java
> // A Simple Class
> public class SimpleClass extends Object{
> private static String last_name;
> private static String first_name;
> private static String middle_name;
>
> // Constructor
> public SimpleClass() {
> this.last_name = null;
> this.first_name = null;
> this.middle_name = null;
> }
>
> public void setLastName( String val ) {
> this.last_name = val;
> }
>
> public String getLastName( ) {
> return this.last_name;
> }
>
> public void setFirstName( String val ) {
> this.first_name = val;
> }
>
> public String getFirstName( ) {
> return this.first_name;
> }
>
> public void setMiddleName( String val ) {
> this.middle_name = val;
> }
>
> public String getMiddleName( ) {
> return this.middle_name;
> }
>
> public String getFullName( ) {
> return this.last_name + (this.first_name == null ? ""
> : ", " +
> this.first_name) + (this.middle_name == null ? "" : " " +
> this.middle_name);
> }
>
> }// class SimpleClass
> ============
>
>
> // VectorTest.java
> // A Simple Vector Test
> import java.util.*;
>
> import SimpleClass;
>
> class VectorTest{
>
> public static void main( String args[] ){
> Vector v = new Vector();
>
> String firstNames[] = {
> "George",
> "John",
> "Thomas",
> "James",
> "James",
> "John",
> "Andrew",
> "Martin",
> "William",
> "John",
> "James",
> "Zachary",
> "Millard",
> "Franklin",
> "James"
> };
>
> String lastNames[] = {
> "Washington",
> "Adams",
> "Jefferson",
> "Madison",
> "Monroe",
> "Adams",
> "Jackson",
> "Buren",
> "Harrison",
> "Tyler",
> "Polk",
> "Taylor",
> "Filmore",
> "Pierce",
> "Buchanan"
> };
>
> System.out.println( "\nPut class in Vector." );
> for( int i=0; i<15; i++ ){
> SimpleClass inClass = new SimpleClass();
> inClass.setFirstName( firstNames[i] );
> inClass.setLastName( lastNames[i] );
> System.out.println( i + ": " + inClass.getFullName() );
> v.addElement( inClass );
> }
>
> System.out.println( "\n\nRetrieve class from Vector." );
> for( int i=0; i<15; i++ ){
> SimpleClass outClass = (SimpleClass)v.elementAt( i );
> System.out.println( i + ": " + outClass.getFullName() );
> }
>
> } //main()
>
> }//class VectorTest
> =============
>
> Here is my output:
>
> [projects]# java VectorTest
>
> Put class in Vector.
> 0: Washington, George
> 1: Adams, John
> 2: Jefferson, Thomas
> 3: Madison, James
> 4: Monroe, James
> 5: Adams, John
> 6: Jackson, Andrew
> 7: Buren, Martin
> 8: Harrison, William
> 9: Tyler, John
> 10: Polk, James
> 11: Taylor, Zachary
> 12: Filmore, Millard
> 13: Pierce, Franklin
> 14: Buchanan, James
>
>
> Retrieve class from Vector.
> 0: Buchanan, James
> 1: Buchanan, James
> 2: Buchanan, James
> 3: Buchanan, James
> 4: Buchanan, James
> 5: Buchanan, James
> 6: Buchanan, James
> 7: Buchanan, James
> 8: Buchanan, James
> 9: Buchanan, James
> 10: Buchanan, James
> 11: Buchanan, James
> 12: Buchanan, James
> 13: Buchanan, James
> 14: Buchanan, James
>
> --
> *******************************************
> * Rick Roberts *
> * Advanced Information Technologies, Inc. *
> *******************************************
>
>
>
> --
> To unsubscribe: <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>
Re: Vectors? Why does this not work?
Posted by Darrell Esau <Da...@Sun.COM>.
On Thursday 10 January 2002 01:14 pm, you wrote:
> Basically:
>
> 1. I'm an idiot.
> 2. And you quickly pointed that out.
> 3. I'm grateful.
Heheheheh.. don't be too hard on youself.. it wasn't all _that_ obvious.
:)
--
Darrell Esau
Software Engineer, Sun Microsystems
NetAdmin Development
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>
Re: Vectors? Why does this not work?
Posted by Rick Roberts <te...@ait-web.com>.
>>First, you should take this question to another forum since this one
is about the Tomcat >>Servlet Container.
I'm actually building a bean for a Tomcat JSP app that I am working on.
I presented the code this way to simplify my description of the problem.
>>Second, you probably need to do some basic Java learning since this.
I feel like an idiot.
>>Third, you are using static variables to hold your names.
That is it!!!!
I looked at this for hours and never noticed "static".
Basically:
1. I'm an idiot.
2. And you quickly pointed that out.
3. I'm grateful.
Thanks,
Rick
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>