Java
  Home arrow Java arrow Page 5 - Working with Arrays of Objects with Java a...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Working with Arrays of Objects with Java and NetBeans IDE
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2006-07-10

    Table of Contents:
  • Working with Arrays of Objects with Java and NetBeans IDE
  • Overloading Methods in Java: Demo
  • Overloading Methods in Java: Explanation
  • How to Create Arrays of Objects in Java: Demo
  • How to Create Arrays of Objects in Java: Explanation
  • Passing Arrays of Objects to Methods in Java: Demo

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Working with Arrays of Objects with Java and NetBeans IDE - How to Create Arrays of Objects in Java: Explanation


    (Page 5 of 6 )

    There is nothing special in the class “MyCalc.” We need to focus only on the testing code. Let us go through the code step by step. 

            MyCalc[] ar = new MyCalc[10];

    The above statement will simply create ten locations to store objects of type “MyCalc.” The important issue is that it creates only the location, but not the objects. Each of those locations can hold an object of type “MyCalc.” Proceeding further, we have the following:

            for(int i=0;i<10;i++) {

    The above loop simply iterates from zero through nine.  Next, we have the following statement:

                ar[i] = new MyCalc();

    The above statement creates a new instance/object of the class “MyCalc” and stores that instance at the ‘i’th location in array “ar.” Proceeding further, we have the following:

                ar[i].setValues(i*10,i*10+1);

    Once the object is successfully created (at some location in the array), we need to set some values to its members. The same is achieved through the above statement. 

    Now it is time to display the sum of all values (in all objects) available in the array. Again, we need to iterate through all the objects in the array and sum up those values. The same is achieved through the following:

            int s=0;
            for(int i=0;i<10;i++) {
                s += ar[i].getSum();
            }

    We finally display the sum using the following:

            this.lblMsg.setText("Sum = " + String.valueOf(s));

    More Java Articles
    More By Jagadish Chaterjee


       · hello. this is my next contribution on working with arrays in java with netbeans...
     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway