You can drink coffee on the street in Japan although it's considered rude to walk and drink coffee or other beverages in Japan.
It's not illegal to drink coffee or other beverages while walking in Japan, but it's simply seen as rude so it's best to avoid it.
The custom in Japan when drinking coffee and other beverages, is to finish the coffee or other drinks when standing near where you purchased the coffee or other beverage.
Then you can dispose of the empty cup or trash where you're located.
The main reason for not drinking your coffee or other beverage while walking in Japan is because of a lack of public trash cans, which means that you would have to carry your trash with you.
Although I've seen some people dispose of their cups and cans and other trash around trees etc, when I visited Japan but it's not what you should do.
Drink your coffee or beverage near the vending machine or convenience store where you bought it and then dispose of the trash properly and use the bins that are provided at the store or the vending machine to dispose of the trash.