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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![syed sharukh](https://secure.gravatar.com/avatar/55182e430bbdf3e45962d3789ff572fa?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
syed sharukh
226 Pointscolor.java
Tell how to set this
favoriteColor String equals "";
1 Answer
![Chase Marchione](https://secure.gravatar.com/avatar/2b3a4eb00836bc9ba2829e89937cf5f4?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Chase Marchione
155,055 PointsHi 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!
syed sharukh
226 Pointssyed sharukh
226 PointsThanks CJ