If your puppy is barking to express anxiety at being left alone it may help to leave a radio on when you go out. Puppies are companion animals and aren't meant to be left alone for long periods. Music can be soothing, and the music may block out street noises that set off barking. Your puppy may also associate the sound of the radio with you, and leaving it on when you leave may comfort him. Leaving toys out to keep your puppy busy when he's alone may distract him and prevent barking. Some puppies station themselves near a window when left alone and bark at every car or person that passes. If this describes your puppy then leaving the blinds drawn may prevent his barking.
If your puppy barks and you jump to get him food, play with him, or take him for a walk he is learning that he should bark when he wants anything. To stop this behavior ignore the barking. Don't scold your puppy. Any attention will reinforce his behavior, even if it is a verbal scolding. Don't look at your puppy or touch him when he is barking. When he stops barking reward him with a treat, gradually building up the time necessary for him to be quiet before getting a treat.
It's important to recognize the difference between puppies who bark because they've learned it gets them what they want and puppies who bark for other reasons. Puppies who see their owners for only brief moments as they enter or leave the home, and are otherwise left alone, will be very unhappy. They need attention and companionship, and their barking is very different from that of puppies who have learned that barking gets them an extra treat or attention. To prevent barking by puppies who are suffering from acute loneliness it's necessary to give them the attention and care they need.
It's natural for some puppies to bark to give their owners a warning about an approaching stranger. However, if they continue to bark for a long period after the warning has been given it may be necessary to train them to stop the prolonged barking. Decide on a command cue word such as "enough!" and use it consistently. When you want your puppy to stop barking use the command, and reward him when he is quiet. It may take awhile, but eventually he will understand what to do when he hears the command. Enlist a friend to help you train your puppy. Your puppy should not be familiar with the friend. Have the friend approach you and the puppy and when your puppy begins to bark you should say "good boy," or something similar. This tells your puppy that his warning to you has been received, and his job is done. If he continues to bark then you should use the command you have decided on to communicate to your puppy that you want him to stop barking. After giving your puppy the "enough!" command you shouldn't do anything else in an attempt to get him to stop barking. Wait patiently for him to quiet down, and when he is quiet he should be rewarded with a treat and a lot of praise. After doing this a number of times you should increase the amount of time it is necessary for your puppy to remain quiet before he is rewarded with a treat.