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) Creating the Screen Layout Adding a Button

Sky Lu
Sky Lu
419 Points

When you Change the ID, Can the first letters to be capital letter?

When we change the IDs using the design tab, I saw the video change "textView" to "factTextView" I am very curious, why the first letter can't be capital? Can I change to"FactTextView" ? Or if i type all capital letters ,is that ok? is this a rule of ID changing?

Van Sanders
Van Sanders
16,087 Points

I'm not sure that you aren't allowed to use a capital "F" in "FactTextView", but I do know that using "camel case" in Android and Java projects is a generally accepted convention.

"Camel cased" titles always begin with lower case and only capitalize the first letter of each subsequent word that is appended to the title - which is why in "factTextView" the "T" is capitalized (because "text" is now the second word in the title).

I admit, I haven't done much with Android and Java, and I even tried to open my old install of Android Studio, only to find that I need to reinstall it because of some errors while updating... So, I can't check to see if it actually won't allow you to use a different naming convention.

Still, its good practice to "camel case" when the rest of your coding community does.

I hope this rambling answer helps at least a bit! I'm sure someone out there knows if Android Studio allows different naming conventions.

2 Answers

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

Of course, it is technically possible to mix and match capital letters any way you want. The app will always run. However, this is greatly frowned upon, as it causes confusion. The standard that is set is made to make the code clear. Capital letters are generally reserved for class names. If you're working with a team of people, they'll be very confused if you use capital letters for things like ID:s. Similarly, method names and variables in Java start with lowercase letters too.

Sky Lu
Sky Lu
419 Points

Thank you very much.

Sky Lu
Sky Lu
419 Points

Hi Van Sanders , Thanks you very much for your answers and efforts. First I want to share with you. I tried "FactTextView" and "FACTTEXTVIEW" and ran it. worked very well.

About "Camel cased", Is this the rule when you coding Java, it always follows example as below: When we want to coding words applejuiceview It is better type " appleJuiceView", the first letter is small, then the second word-Juice , first letter should be a capital letter

Van Sanders
Van Sanders
16,087 Points

Exactly. I can't think of instances where camel casing is necessary, its just how Java coders tend to name things. It is a good habit to get into if other people will be reading your code :)