Is it possible to know the city name based on IP address in java?
You have to use a service such as hostip.info that maps an IP to its physical location, and offer an API to developers to simplify the task.
There are many other services, paid and for free, that you can find at Google.