File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "formal parameter on functions in java" Watch "formal parameter on functions in java" New topic

formal parameter on functions in java

joe garcia

Joined: Mar 01, 2010
Posts: 9

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

Joined: Sep 28, 2004
Posts: 20535

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.


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

Joined: Oct 13, 2005
Posts: 46410
Please tell the details; do you really get an Exception from "continue;" or a compiler error?
I agree. Here's the link:
subject: formal parameter on functions in java
It's not a secret anymore!