Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Definition of keys for key-pair values?

 
Ranch Hand
Posts: 75
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning,

I am fairly proficient in Java and now I would like to put it to the test by exploring Android Application Development.

My questions are, in the listing below (taken from the official online android tutorials):

* Why is the key EXTRA_MESSAGE defined as a final string ?
* And is there any significance in literal value "com.example.myfirstapp.MESSAGE" ?  Would any literal do? (I will test this)
*

Thanks for any replies.

 
Saloon Keeper
Posts: 5982
154
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good practice to declare variables that do not change as static and final. It allows the compiler and runtime to perform  optimizations as to how they treat this variable.

In this case, any value would do. But for standardized intents the names of additional data items are predefined. For example, if you want to send an email, you need to use Intent.EXTRA_EMAIL for the email address and Intent.EXTRA_SUBJECT for the subject.
 
Mohammed Azeem
Ranch Hand
Posts: 75
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

I vaguely recall hash numbers and I think there is a similarity between them and key-value pairs.

I've also watched a few youtube videos and this is my (imperfect) understanding:

* keys map a single label to a collection of related values (e.g bank account (label) to account name, balance etc)
* therefore the key must be unique
* so the key must not change - it must be declared as a final string.

I have tested my hypothesis as follows:

* I have assigned EXTRA_MESSAGE any old literal - the app still works
* I have declared EXTRA_MESSAGE but left it unassigned - the app still works as it should.
* Ihave declared EXTRA_MESSAGE as non-final - and the code still works (though I appreciated why it should be final).

 
Mohammed Azeem
Ranch Hand
Posts: 75
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim, you must have posted just as I was typing.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!