Results 1 to 3 of 3
  1. #1
    ibanez270dx is offline Member
    Join Date
    Nov 2007
    Location
    Bay Area, CA
    Posts
    13
    Rep Power
    0

    Question Quick Question (Functions)

    Hi everyone,
    I just have a quick question... how do you create and call functions in Java? For example, I have a portion of an applet that takes a selected directory (stored as a string, like c:/test in a variable called "the_dir") and I want to make a function like postData(the_dir); to send the variable to the postData function. The whole concept of classes and all the restrictions in Java get me really confused... (I usually code PHP, only been dabbling in Java for the last few days). I guess the real question is, how do you define and call a function? Any help is appreciated.

    Thank you,
    - Jeff

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    class Pseudo {
        // member variables
        // declared in class scope - visible everywhere
        ...
    
        void inSomeMethod() {
            String the_dir = "c:/test";
            postData(the_dir);
        }
    
        private void postData(String filePath) {
            // This method has access to the local variables
            // passed in as arguments as well as the member
            // variables declared in this enclosing class.
            File folder = new File(filePath);
            File[] files = folder.listFiles();
            for(int j = 0; j < files.length; j++)
                System.out.printf("files[%d] = %s%n", j, files[j].getName());
        }
    }
    For more information see Defining Methods.

  3. #3
    ibanez270dx is offline Member
    Join Date
    Nov 2007
    Location
    Bay Area, CA
    Posts
    13
    Rep Power
    0

Similar Threads

  1. Functions in jsp
    By samson in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 03-25-2009, 11:04 PM
  2. Calculating trigonometric functions
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:56 PM
  3. Calculating hyperbolic functions
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:55 PM
  4. Quick Stupid Question
    By bluekswing in forum New To Java
    Replies: 7
    Last Post: 01-08-2008, 07:35 PM
  5. Replies: 1
    Last Post: 08-07-2007, 06:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •