• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Definition of keys for key-pair values?

 
Ranch Hand
Posts: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7591
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Tim, you must have posted just as I was typing.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic