Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-16-2007, 02:28 AM
Member
 
Join Date: Nov 2007
Location: Bay Area, CA
Posts: 13
ibanez270dx is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-16-2007, 03:39 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-16-2007, 03:42 AM
Member
 
Join Date: Nov 2007
Location: Bay Area, CA
Posts: 13
ibanez270dx is on a distinguished road
thank you very much! very helpful!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating trigonometric functions Java Tip java.lang 0 04-17-2008 12:56 AM
Calculating hyperbolic functions Java Tip java.lang 0 04-17-2008 12:55 AM
Quick Stupid Question bluekswing New To Java 7 01-08-2008 08:35 PM
I need to be able to deal with functions like matlab romina New To Java 1 08-07-2007 07:37 AM
Functions in jsp samson JavaServer Pages (JSP) and JSTL 1 04-02-2007 05:29 PM


All times are GMT +3. The time now is 09:37 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org