Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Creating the MVP Storing Guesses

Aditya Puri
Aditya Puri
1,080 Points

What does the term "state" mean?

He uses the term "State" a lot in the video.

For eg. lets update the "state" now.

Can anyone explain what the term "State" means?

5 Answers

Ilya Dolgirev
Ilya Dolgirev
35,375 Points

Actually, it's very simple :) Just imagine light switch. It has 2 states - on and off. Updating the state means changing the state. When you turn light on you updating the state of that switch from off to on.

For boolean variables it means changing from true to false and vice versa. For int variables you update the state after some math operations.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 90,825 Points

So a program state is as simple as a the value of a variable including but not limited to booleans? :)

Aditya Puri
Aditya Puri
1,080 Points

For int variables you update the state after some math operations.. I don't understand this line.

Ilya Dolgirev
Ilya Dolgirev
35,375 Points

Program state( or object state) is little bit more complex that single variable state :) Just imagine central panel with light switches. Actual state of this panel is based on states of switches. If you changed one, the whole state for the panel is changed.

The same idea is for object or program. If you update state of one of your variable the program state also changes.

Ilya Dolgirev
Ilya Dolgirev
35,375 Points
int counter = 0; // Initial state
counter = counter + 1; // You've changed(updated) the state of counter
Aditya Puri
Aditya Puri
1,080 Points

oh, so thats all state means? Updating variables and changing boolean values for different parts of the program or based on user interactions?

Ilya Dolgirev
Ilya Dolgirev
35,375 Points

Yep, you've got the main idea! :) But managing complex program state is not so simple as a single variable. Sometimes you'll have to spend hours to get where the bug is :)