Quick question on exercise 12/13 "Iterating over a hashmap"


#1



12/13 Iterating over a hashmap


in the example CA uses System.out.println( name + "is age"...

I am instructed to use System.out.println ( "A" + item + "costs" ...

How does it understand that **Name** is a certain piece of information while **Item** is basically the same information?

I'm just not understanding where either item or name is defined to the computer.

This is probably a simple answer for someone who isn't a novice, thank you for any feedback.


#2

Hi @wowitsmicahh :smiley:
I totally understand how you would be a little perplexed by this idea. However, the bytecode compiler, JVM (Java Virtual Machine) understands this because both 'name' and 'item' are variables.
You defined them earlier in your source code. So at runtime, it remembers the values stored in those variables and uses them whenever you CALL the variable.
Like: "System.out.println(name + "is age " ...) && System.out.println("A" + item + "costs" ...)

I really hope this helps you understand!! We all were novices at some point. :slight_smile:


#3

Thanks a lot for the response infinitycoder!

You are very much appreciated!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.