How to write firebase cloud functions in java

GCP Cloud Functions now has a Java Runtime.

At this time it is currently in alpha, but I would expect it to release to Beta rather quickly.

  • Java Runtime Alpha Sign-up (available on Cloud Functions
  • Google Next 19 announcement video

EDIT: May 30, 2020

There is now support for Java/JVM in Cloud Functions. Please see the release blog and documentation for information.

Original answer

For Cloud Functions, there is currently no support for Java or any other languages or environments other than JavaScript in a node.js environment.