Java
  Home arrow Java arrow More about methods in Java using NetBeans ...
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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

More about methods in Java using NetBeans IDE
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2006-07-03

    Table of Contents:
  • More about methods in Java using NetBeans IDE
  • Methods returning no value: explanation
  • Methods with parameters: demo
  • Methods accepting parameters: explanation
  • A method that accepts parameters and returns a value

  • 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


    More about methods in Java using NetBeans IDE


    (Page 1 of 5 )

    If you want to go past the basics of working with methods in Java, this article is for you. You will learn about methods returning no values, methods accepting parameters, and more.
    A downloadable file for this article is available here.

    This series introduces you to learning object oriented programming in Java visually using NetBeans IDE.  In this article, I try to go in-depth on working with “methods” in Java.  I mainly try to cover the following concepts:

    • Methods returning no values
    • Methods accepting parameters
    • Methods accepting parameters and returning values

    I already introduced NetBeans IDE in my first article “Developing Java Applications using NetBeans.”  Even though that article is fairly introductory, the next two articles concentrate on the basics of JFC. You can find the next two articles here and here.

    If you are new to NetBeans IDE, I strongly suggest you go through the existing articles first, before proceeding with this one. If you are new to OOP in Java using NetBeans IDE, I suggest you go through my first article in this same series.  If you are new to developing Microsoft SQL Server-based Java applications, I request you go through another article of mine (of course, this is part of a series as well) called "Developing SQL Server based Java Applications using NetBeans IDE."

    Methods returning no value: demo

    In my previous article (the first in this series), I introduced OOP in Java with a simple example. Now, I shall use the same application and extend it as much as possible.

    By now, I believe that you already know about “classes,” “instances/objects,” “members,” “fields/attributes,” “methods” and other buzz words. If not, go through my first article in this series. In this article, I shall go into detail about “methods” and their usage in Java. 

    Now, open your previous application (or download it from my previous article) and open “MyCalc.java.” Modify your code so that it looks something like the following:

    package MyPack;

    /**
     *
     * @author Administrator
     */
    public class MyCalc {   

        int x=0;
        int y=0;
        int z=0;   

        /** Creates a new instance of MyCalc */
        public MyCalc() {
        }   

        public void calcSum() {
            z = x + y;
        }   

    }

    Now, get back to the frame “test.java.” Double click on it to open and finally double click on the button to open source view. Within the source view, modify your “buttonActionPerformed” in such a way that it looks like the following:

    private void btnShowActionPerformed(java.awt.event.ActionEvent
    evt) {
    // TODO add your handling code here:
            MyCalc obj1 = new MyCalc();
            MyCalc obj2 = new MyCalc();       

            obj1.x = 10;
            obj1.y = 20;
            obj1.calcSum();       

            obj2.x = 100;
            obj2.y = 200;
            obj2.calcSum();       

            this.lblMsg.setText("Sum = " + String.valueOf(obj1.z));
            this.lblMsg2.setText("Sum = " + String.valueOf(obj2.z));
        }

    The next section will explain the above code.

    More Java Articles
    More By Jagadish Chaterjee


       · Hello guys. Another extension to the concept of "methods" in java. enjoy
     

    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 5 hosted by Hostway
    Stay green...Green IT