I thought I understood the difference between local and global variables in java until I saw an example today. In this code one tries to add elements to a link list in a met

newElement is just a reference to an object created in memory.
firstElement then holds a reference to the same object.
The reference newElement is indeed a local variable, but the object referred to by the reference is then also referred to by another reference, i.e. firstElement. So after the addDataPacket() method completes, the newElement reference no longer exists, but the object that it referred to still exists in memory and that object is referred to by firstElement.