> For the complete documentation index, see [llms.txt](https://learn.qanplatform.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.qanplatform.com/developers/qvm-multi-language-smart-contracts/docs-for-supported-languages/java-smart-contract/compiling-a-smart-contract-in-java.md).

# Compiling a smart contract in Java

Java is quite different from C/C++/Go/Rust since it’s required JRE to execute.\
The `javac` standard compiler produces JVM bytecode from Java source (class file) not a static executable binary.

In this sample, we’ll use GraalVM Native Image to produce static binary that suitable for deploying and executing under QVM environment.

```
# compile JVM bytecode (Java class file)
javac contract.java

# compile class file to static binary
native-image --static contract

# check the output binary size
wc -c contract
13644368 contract
```

### Compiling Java contract to static binary with the QVM compiler

We already supply a simple compiler container which will perform the most optimized build of turning above sample contract to a static binary which can be run by QVM.

Since you saved the previous sample contract as `contract.java` in your current directory, you can run the compiler like this:

```bash
docker run --rm -v $(pwd):/ws qanplatform/qvm-compiler-java
```

Afterwards you will end up with a statically linked linux ELF binary called "contract" in your current directory.

```shell
# checking output size of QVM compiler
ls -alh contract
-rwxr-xr-x  1 user  group    863K Jun 22 15:48 contract
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://learn.qanplatform.com/developers/qvm-multi-language-smart-contracts/docs-for-supported-languages/java-smart-contract/compiling-a-smart-contract-in-java.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
