Oracle had argued that Google had infringed its copyright and had sought nearly $9bn (£6bn) in damages.
The outcome was eagerly awaited by software developers who feared that a victory for Oracle might encourage more such legal actions.
The company says it will appeal against the decision.
Google uses Java in its Android smartphone operating system which powers about 80% of the world's mobile devices.
The company had argued that extending copyright protection to pieces of code called APIs (application programming interfaces) would threaten innovation.