File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes formal parameter on functions in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "formal parameter on functions in java" Watch "formal parameter on functions in java" New topic
Author

formal parameter on functions in java

joe garcia
Greenhorn

Joined: Mar 01, 2010
Posts: 9
questions

the function is like this


if we call the functionName("stringvalue"); it is fine

but if we were to call functionName() with no paramater , i still get an exception even though I have if(param1 == null) continue;

in this case i thought we are passing nothing ( which we are passing null ) and i want that to be OK because I might not really need String to be passed in in parameter

similar code in php would be


which say that param1 is optional.

i want the same thing on java .


thanks for the help
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Java doesn't support default arguments (unless you want to count var-arg as such, but I digress). You will need to overload the method with a no-arg version, that calls the original version with null.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Please tell the details; do you really get an Exception from "continue;" or a compiler error?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: formal parameter on functions in java