Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of reserved words in Android

I'm currently in the interface design process of developing another Android app and once again I seem to be trying to use reserved words for the resources (be it drawables and layouts). To my knowledge there are a set of rules you need to know:

  • No uppercase is allowed.
  • No symbols apart from underscore.
  • No numbers

Appart from those (please correct me if I'm wrong) I think you can't use any of the reserver words from JAVA which after a little googling appear to be the following:

enter image description here

So my question would be if there is somewhere in the docs that I've failed to locate, that explains in detail what we can and can not use for resource names. This is right after reading the page about resources so its possible that I'm simply worthless in reading.

Source for the reserved words

like image 353
Juan Cortés Avatar asked Aug 11 '12 07:08

Juan Cortés


People also ask

What are the 53 reserved words in Java?

abstract , if , private , this , double , implements , throw , boolean , else , import , public , throws , break , return , byte , extends , int , short , true , false , case , interface , static , try , catch , final , long , void .

How many reserved words are there?

A reserved word is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a reserved word may have no meaning. There are a total of 95 reserved words in C++.

What are reserved words examples?

1. Often found in programming languages and macros, reserved words are terms or phrases appropriated for special use that may not be utilized in the creation of variable names. For example, "print" is a reserved word because it is a function in many languages to show text on the screen.

How many reserve words are there in Java?

In the Java programming language, a keyword is any one of 67 reserved words that have a predefined meaning in the language.


2 Answers

To my knowledge there are a set of rules you need to know:

No uppercase is allowed.

AFAIK, that is not a rule. A convention is to use all lowercase, but mixed case has worked.

NOTE: In layouts you can ONLY use lowercase letters (a-z), numbers (0-9) and underscore (_).

No symbols apart from underscore

Correct. More accurately, the name has to be a valid Java data member name, which limits you to letters, numbers, and underscores, and it cannot start with a number.

No numbers

That is not a rule, though your name cannot start with a number, as noted above.

Appart from those (please correct me if I'm wrong) I think you can't use any of the reserver words from JAVA which after a little googling appear to be the following:

That is because reserved words are not valid Java data member names.

So my question would be if there is somewhere in the docs that I've failed to locate, that explains in detail what we can and can not use for resource names

Apparently not.

like image 126
CommonsWare Avatar answered Sep 18 '22 07:09

CommonsWare


Well my answer would be a mix of some pages where you can find what you need.

1.- First i would recommend you to read the Conventions that Oracle recommends for java

NOTE: especially the section of "Naming Conventions" (this is something that most of the other answers have), after that i would suggest you to read the "Java Languages Keywords" cause you can not use any of those words, BUT remember that JAVA is CASE-SENSITIVE, so if you write "Abstract" instead of "abstract" then is OK, but of course that may confuse someone later one (maybe yourself).

2.- Last but not least you can read the "Code Style Guidelines", this are the conventions that contributors to the android source code need to apply to their code to be accepted.

If you follow this rules, your code not only will be valid (Of course this is important), is going to be more readable for you and others, and if another person needs to make some modification later on, that would be a easier task than if you just start typing random names like "x1, x2, X1, _x1, etc..."

OTHER USEFUL ARTICLE:

If you are starting your app, then this article is going to be very useful for you, it explains why the use of setters and getters in a exaggerated way is a very bad practice, they need to be ONLY if is needed not just for setting and getting every variable in your object.

like image 25
Jorge Aguilar Avatar answered Sep 22 '22 07:09

Jorge Aguilar