Judges should not be "accountable to the media" for controversial decisions, the head of Northern Ireland's judiciary has said.

The Lord Chief Justice Sir Declan Morgan said it is important to secure public confidence in the courts but he said that "does not make judges accountable to anyone" and he strongly defended the need for judges to remain independent.

The senior legal figure, giving the fifth annual Chancellor's Lecture at the University of Ulster's Belfast campus, said judges are bound by the law and have to strike difficult balances.

During his speech he said he is committed to the judiciary playing its part in boosting public confidence but he also addressed how some court decisions can spark public outcry.

"Sometimes, of course, it can be difficult to secure public confidence because the right decision is not necessarily the popular decision," he said.

He endorsed the need for an independent media, and added: "The media are plainly entitled to criticise any judicial decision with which they do not agree and where appropriate to campaign for changes in the law, if deemed necessary.

"In doing all of this the media have, of course, a responsibility to present an accurate and comprehensive account of the material facts. None of this, however, can ever render the judiciary accountable to the media."

The Lord Chief Justice said there is often a lack of understanding of why judges have to remain independent. He said the rule of law is a key building block of democracy.

"The obligation which the law imposes on the courts is to strike a balance between the rights and freedoms of the individual and the protection of the rights and freedoms of the community," he said.

"Where they arise these are often difficult balances to strike but the duty of the judiciary is to ensure that the balance is struck in accordance with law without fear or favour, affection or ill will. Every party before the court is entitled to a fair and impartial resolution of the dispute."