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

Android Build a Simple Android App (2014) Getting Started with Android Troubleshooting Java

color.java

Tell how to set this

Color.java
favoriteColor String equals "";

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi syed,

In a common Java statement that both declares and initializes a variable:

  • The data type goes first (in this case, it's String.)
  • The name of the variable goes second (in this case, it's favoriteColor.)
  • The assignment operator (an equals sign), which indicates to the compiler that the value that we want to store in the variable is coming next, goes third.
  • The actual value that will be set to the variable goes fourth. In this case, since it's a String, the value needs to be enclosed in quotes or double quotes.
  • Finally, the statement ends in a semicolon (a ';'), which tells the Java compiler that the statement is done.
String favoriteColor = "magenta";

Hope this helps!

Thanks CJ