MOUNT HOLLY, N.J. (AP) _ A judge today upheld the ``Megan's Law'' requirements that sex offenders register with police and that communinities be notified when dangerous offenders leave prison.

Superior Court Judge Harold B. Wells said notification of where a sex offender lives does not constitute additional punishment. But he said each offender is entitled to a closed hearing before a judge to determine whether he or she is so dangerous that the community should be notified.

He ruled in a case dealing specifically with an offender who was released from prison before Megan's Law took effect.

The law was named for 7-year-old Megan Kanka, who was slain in July, allegedly by a convicted sex offender who lived across the street and kept his criminal past a secret.

The laws to toughen penalties and controls over sex offenders were signed by Gov. Christie Whitman Oct. 31. It required all ex-offenders to register with police but left it up to prosecutors to decide which ex-offenders were such a threat to the community that citizens had to be notified. Wells' ruling would turn that decision over to a judge instead.

The registration rule took effect immediately but it gave offenders previously released from prison 120 days, or until the end of February, to comply.

Wells, the presiding state judge for Burlington County, said the requirements imposed by Megan's Law are not punitive and are designed to promote public safety.

``No one could say Megan's Law does not impose a burden,'' Wells said, but that must be balanced against public safety concerns.

``The primary goal of this system is to prevent sex offenses,'' Wells said. ``The intent was to protect the public from otherwise unidentifiable dangers.''

The case was brought by a convicted sex offender known only as John Doe, who was convicted of molesting two teen-age boys in 1985. He was sent to a state treatment center for sex offenders at Avenel and released on parole in 1992.

Megan's Law requires Doe to register with local police by next week, but his attorney, John Furlong, said Doe has not done so out of fear he would lose his job and that his family might be harassed.

In another challenge to Megan's Law, U.S. District Judge John Bissell in Newark issued an order Jan. 3 blocking the Passaic County prosecutor from notifying a neighborhood in Passaic where a recently released rapist, Carlos Diaz, planned to live.

A hearing on the Diaz case is scheduled before Bissell on Monday.

The Diaz and Doe cases both raised the legal issue of whether Megan's Law can apply to offenders who were convicted before the law took effect.

But the Doe case went further because it involved an offender who completed his sentence at the treatment center, finished parole, ended all forms of state supervision and now is being asked years later to register with authorities.