Oracle's high-profile lawsuit against Google, in which it claimed that the search giant's Android mobile software infringed both copyrights and patents obtained from Sun Microsystems, is in tatters after the judge in the case ruled that key elements of Sun's software cannot be copyrighted, and so were not infringed.

Judge William Alsup ruled that the 37 application programming interfaces (APIs) for the Java programming language used in Android are not covered by copyright – meaning that Google's use of them in Android is not infringement. Oracle said it will appeal against Alsup's ruling.

His decision means that Oracle, which had gone into the case confident that it would win a multi-billion-dollar ruling that might lead to a levy on every future Android device sale, has effectively wound up with nothing.

"This is now effectively a total loss for Oracle, across the board," Brian Love, a Stanford Law School expert on technology and intellectual property law, told the San Jose Mercury News. "It's absolutely the best possible case for Google."

The outcome reinforces previous US cases which have declined to extend copyright law so that it would cover interfaces between programs or languages. Programming languages cannot be copyrighted.

"To accept Oracle's claim would be to allow anyone to copyright one version of code to carry out a system of commands and thereby bar all others from writing their own different versions to carry out all or part of the same commands," Alsup, who has programming expertise, wrote in his ruling. "No holding has ever endorsed such a sweeping proposition."

He did note tha:t "This order does not hold that Java API packages are free for all to use without license. Rather, it holds on the specific facts of this case, the particular elements replicated by Google were free for all to use under the Copyright Act."

Oracle can win damages for other copyright infringements that were found in the case, but those have a statutory ceiling of $150,000 in a case that has cost both sides millions.

For Oracle, it has also seen its high-stakes approach fall away. Before the trial, Google made an offer to settle which would have led to a very small share of the advertising and other revenues that it has received through Android's use. Oracle rejected it.

A jury in the long-running case had found on 7 May that Google infringed eight APIs, but couldn't agree on whether Google was covered under the "fair use" provisions of US copyright law, which allow limited uses of copyrighted works to create others.

Now Alsup's determination makes that moot. The APIs, said Alsup in his ruling, form "a system or method of operation under Section 102(b) of the Copyright Act and, therefore, cannot be copyrighted … the Act confers ownership only over the specific way in which the author wrote out his version. Others are free to write their own implementation to accomplish the identical function, for, importantly, ideas, concepts and functions cannot be monopolised by copyright."

To overturn the ruling, Oracle would have to reverse Alsup's determination in legal arguments, and then get a fresh jury to decide that Google's use of the APIs fell outside "fair use".

For Google, the ruling is a major triumph in the smartphone patent wars. Though there are still many ongoing skirmishes – and Google on Thursday night filed claims with the European Commission, the US Department of Justice and Federal Trade Commission complaining about Microsoft and Nokia's deployment of patents – it means that Oracle's claims, first filed in 2010, have been picked apart piece by piece.

Android now powers more than 300m smartphones and tablet computers. Those devices are the chief competitors to Apple's iPhones and iPads.

Google has driven the adoption of Android by giving the software away to manufacturers of phones and tablets. That would have been more difficult for Google to keep doing had the court found that Google needed to pay Oracle millions of dollars to license Java technology.

The jury in the case had been asked to rule on the infringement and fair use questions on the assumption that the APIs were copyrightable. Alsup deferred a ruling on the broader copyright question until after the trial, which ended on 23 May.

Alsup ruled on Thursday that Google didn't use Oracle's exact programming code in Android, but rather wrote its own code to produce the same functions. Although Google used some of the same phrases in the code, Alsup said it had to do so to maintain interoperability. Names, titles and short phrases aren't covered by copyright, and Google's use of those phrases amounted to that, he said.

"In sum, Google and the public were and remain free to write their own implementations to carry out exactly the same functions of all methods in question, using exactly the same method specifications and names," Alsup said.

In a statement, Google said: "The court's decision upholds the principle that open and interoperable computer languages form an essential basis for software development. It's a good day for collaboration and innovation."

Oracle countered that Alsup's ruling would make it far more difficult to defend intellectual property rights against companies anywhere in the world that simply takes them as their own.

Alsup's ruling does not affect the jury's determination that Android infringed on nine lines of Java coding, but the penalty for that violation is confined to statutory damages no higher than $150,000. Oracle had been seeking hundreds of millions of dollars from Google on the API questions.

The jury has also cleared Google of infringing two Oracle patents. Before the case began, Google had driven reexamination of a number of Sun patents that Oracle asserted against it and had them either withdrawn or invalidated.

(Corrected name of paper from San Francisco Mercury News.)