I have heard about technology AGPS that can work to provide GPS functionality in non-GPS devices.
Is there a code in j2me or API's given to support for j2me programming?
JSR-256 is the standard that allows you to retrieve the phone's location in J2ME code.
If it is available on your phone and if it supports location on your phone and if your phone doesn't have GPS hardware, then the implementation of JSR-256 on your phone probably uses AGPS.
As a J2ME developer, you are probably not supposed to know or have any control over whether your code will end up using GPS or AGPS. Using JSR-256 should just give you the result of the most accurate option available.
The specification is at http://jcp.org/en/jsr/detail?id=256
An existing stackoverflow answer that can be useful to you is at JSR 256 battery events