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 Side effects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Side effects" Watch "Side effects" New topic

Side effects

Java Daisuki

Joined: Jul 30, 2005
Posts: 6
Hello everyone. I really appreciate of gaining access to this site and everyone's contributions. I am a REAL beginner with No IT, computing background starting learning Java 3 mths ago.

Please anyone explain to me in plain English, what is the side effects ? My book said that if a method modifies some outside value other than its implicit parameters, we call that modification a side effect.

What is the difference between implicit parameter and explicit parameter ?

Thank you.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

First the business side

"Java" -

I am assuming that Java is not your real first name.

Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it


Thanks! and welcome to the JavaRanch!


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Ok let's assume this code

Basically a side effect is where you are changing some value that is not scoped directly to just the method, but outside the method and you change some value to something outside the method. Therefore any other method, class, or variable cannot assume that that value outside the method scope is going to be the same, there is a side effect and it can cause problems outside the method.

Say you call some other method and it still expects that that instanceVariable.mySideEffectVariable is still equal to 10, not knowing that the changeOutsideValue method changed it to 20, and therefore that other method returns an incorrect value that what is expected.

Hope that helps.

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

i've alse seen the term used in relation to the short circuit boolean operators. say you have code like this

strange things can happen. sometime the i variable will be incremented, and sometimes not, depending on the value of myVar.

if you want i incremented, it should be outside of the if-condition entirely...

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Side effects
It's not a secret anymore!