Java – Side effect–what’s this

java, jsp

Could someone tell me the meaning of "side effect" in the following line?

If you're calling an EL function that doesn't return anything, then you're calling it just for its side effects.

Best Solution

A side effect is anything a method does besides computing and returning a value. Any change of instance or class field values is a side effect, as is drawing something on the screen, writing to a file or a network connection.

Strictly speaking, a "function" is defined as not having side effects - which is why Java uses the word "method" instead. A real function with no return value would be pointless.

Obviously, a method that does not have a return value must have some sort of side effect that justifies its existence. Set methods are an example - the side effect is changing the object's internal state.