# The Java Runtime

## Overview

Your Cloud Run function runs in an environment consisting of an operating
system version plus add-on packages, language support, and
the Functions Framework library that supports and invokes your function.
This environment is identified by the language version, and is known as the
runtime.

For information about runtimes in general, and to learn which Ubuntu version
each Java runtime uses, see the [Cloud Run functions execution
environment](https://docs.cloud.google.com/functions/1stgendocs/concepts/execution-environment#java).

## Select your runtime

Cloud Run functions supports several versions of Java, listed on the
[Runtime support](https://docs.cloud.google.com/functions/1stgendocs/runtime-support.md.txt#java) page. You can
select the preferred Ruby Java for your function during deployment.

If you're using the Google Cloud CLI, specify the runtime
by using the `--runtime` parameter. The `--entry-point` flag specifies the
fully qualified class name (FQN). For example:

```bash
gcloud functions deploy NAME --no-gen2 --entry-point FQN --no-gen2 --runtime java17 --trigger-http
```

For more deployment parameters, see [Deploy a Cloud Run function](https://docs.cloud.google.com/functions/1stgendocs/deploy.md.txt#basics).

## Function preparation

You can write a function on your local machine and upload it.
To prepare your local machine for Java
development, see [Setting Up a Java Development Environment](https://docs.cloud.google.com/java/docs/setup.md.txt).
The library that invokes your function is the [Java Functions
Framework](https://docs.cloud.google.com/functions/1stgendocs/functions-framework).

To get started with Java on Cloud Run functions, see the
[Quickstart](https://docs.cloud.google.com/functions/1stgendocs/create-deploy-gcloud-1st-gen).

## Source code structure

For Cloud Run functions to find your function's definition, your
source code must follow a specific structure. See
[Writing Cloud Run functions](https://docs.cloud.google.com/functions/1stgendocs/writing.md.txt#structuring_source_code)
for more information.

## Specifying dependencies

You can specify dependencies for your function using [Maven](https://maven.apache.org/) or [Gradle](https://gradle.org/). For more information,
see [Specifying dependencies in
Java](https://docs.cloud.google.com/functions/1stgendocs/writing/specifying-dependencies-java).

## Environment variables

Your Java runtime automatically sets certain environment variables for your
function to use as needed. For details, see [Using Environment
Variables](https://docs.cloud.google.com/functions/1stgendocs/configuring/env-var).

## What's next

- [Learn how to use Java frameworks](https://docs.cloud.google.com/functions/1stgendocs/concepts/java-frameworks.md.txt) that provide out-of-the-box support for writing Java Cloud Run functions.
- [Learn how to use popular APIs and logging
  frameworks](https://docs.cloud.google.com/functions/1stgendocs/concepts/java-logging) to configure the logging behavior of Java Cloud Run functions.
- [Learn about the other JVM languages](https://docs.cloud.google.com/functions/1stgendocs/concepts/jvm-langs.md.txt) you can use to write Cloud Run functions: Kotlin, Groovy, and Scala.