Being territorial is something that is in all dogs from birth. It is instictive for all dogs. However, through training and/or life experience, some dogs become "overly" territorial and others mellow out nicely and only become so when truly necessary.
At your pup's age, I suspect he's testing his emotions and feelings. He was unsure about the neighbor dog, so he growled and warned the dog to stay away. That may not necessarily be "territorial" behavior. It could be a fear based aggression as well.
You will need to guide your dog into the proper behavior by showing him what you expect of him, rewarding that behavior and ignoring or modifying the unwanted behavior AFTER you have guided the dog into the proper behavior and he understands what is expected of him.
I suggest training classes as soon as possible. Additionally, there is a host of information on "barking" and "territorial" which can be found by using the search engine here at Boxerworld. Please avail yourself to all of the good information readily available to you at the click of a mouse.
Good luck.