Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Organizing Data Serialization

Julia Vasilieva
Julia Vasilieva
556 Points

Confused with mBreakIt variable. What is it for?

Why do we use this line of code (private boolean mBreakIt = true;) and why does it cause java.io.InvalidClassException before we enter serialVersionUID? What exactly is this variable important for? It seems that we're not using it anywhere..

2 Answers

Trevor Skelton
Trevor Skelton
1,101 Points

The variable itself doesn't do anything for the class. Craig simply uses it to demonstrate how serialization works. In a high level view of serialization, we could say that when a class is serialized it is put into a certain binary code. Now we send this class across the internet to Bob. He gets the class in its binary code format. When Craig changed his class ( by putting a random variable in there, although it could have been any change), he can serialize it and it won't be in the exact same binary code as Bob's version. When Bob receives the same class but with that new variable, it won't match the old one. So, we can give it a serialization unique identifier (UID) and the class will get serialized with this ID embedded in the binary code. Now we can send and recieve that binary code of that class and as long as the UIDs match, then everything is fine. Watch that last part with this in mind and listen to him carefully and it should make a little more sense. If it's still confusing, just search it in a search engine and read different ways to define it.

Julia Vasilieva
Julia Vasilieva
556 Points

Thank you! Now I understand how serialization works much better.

I realize it has been two years since this thread has been used. I just want to point out for anyone out there that it isn't the exact variable that was set that caused the problem. If you do anything to the method it will create the read error. I tested this by making an int variable with the value of 3.

private int mBreakIt = 3;

It has nothing to do with the variable name or type or value. It has to do with adding or removing from the method that serialized the data that you are trying to receive. I hope this is helpful.