This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
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: 20133

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: 44433
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!