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 Objects Creating the MVP Remaining Characters

Borislav Milev
Borislav Milev
1,218 Points

Ensure you've created a new public int field following the constant naming convention of MAX_CHARS

Can someone tell me what I am doing wrong and a quick and simple explanation on what a field is. Thank you!

Tweet.java
public class Tweet {
  private String text;

  public Tweet(String text) {
    this.text = text;
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

  public final static int MAX_CHARTS = 140;
}
William Schultz
William Schultz
2,926 Points

I don't know Java, but you have a Syntax error. The challenge is asking for MAX_CHARS not MAX_CHARTS. I tested it and it works fine spelled right. I also would declare this right below the declaration of text at the top instead of below your methods.

3 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you spelled chars wrong. additionally, and these won't throw an error, but typically this would be put at the top before any methods, and static goes before final.

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

a field is just a variable in a class, so max_chars is a field and so is text. text is private so it can only be accessed by code in this class. max_chars is public so it can be accessed from any class in the application. text is not static, so it belongs to the instances of the class. each instance has its own value for text, which makes sense, each instance of a tweet is different. to access the non-static field text you need an object (instance) of the class. max_chars is static, so it belongs to the class. this makes sense here because all tweets have a max length of 140 chars. that value stays constant no matter how many tweets we make or if we make any at all. since this value is not going to change and exists irrespective of instances of the class, we make it public static final.

Borislav Milev
Borislav Milev
1,218 Points

Thank you guys! I learned a bit more :)