Language cheatsheet
Java, Maven and Gradle 25 Cheatsheet
JDK commands to compile, run and diagnose Java programs, plus the Maven and Gradle commands for builds and tests.
Compile and run
- Check the Java version — Print the installed JDK version.
- Compile a source file — Compile Hello.java to Hello.class.
- Run a compiled class — Run the main method of a class in the current folder.
- Run a single source file directly — Compile and run a single file in one step, without javac.
- Run a jar — Run an executable jar that names its main class.
- Run with a classpath — Put a folder of jars and the current folder on the classpath.
- Set the maximum heap size — Allow the JVM to use up to 2 GB of heap.
- Open the interactive shell — Try out Java expressions without writing a class. Exit with /exit.
- List a jar's contents — Show the files inside a jar.
Diagnostics
- List running Java processes — Show Java process IDs with their main class or jar.
- Take a thread dump — Print every thread's stack. Useful for hangs and deadlocks.
- Show heap usage — Print a summary of the heap.
- Write a heap dump — Save the heap to a file to analyze memory leaks.
- Dump the heap on OutOfMemoryError — Have the JVM write a heap dump automatically when memory runs out.
- Show the flags a JVM is using — Print the JVM flags of a running process.
Maven
- Check the Maven version — Print the Maven and Java versions it uses.
- Create a Maven project — Generate a project from the quickstart archetype without prompts.
- Compile — Compile the main source code.
- Run the tests with Maven — Compile and run the unit tests.
- Package — Build the jar or war into target.
- Clean and install — Delete target, build, test and install the artifact into your local repository.
- Build with Maven without running tests — Compile and package, skipping test execution.
- Run one test — Run a single test method.
- Show the Maven dependency tree — Print dependencies and their transitive dependencies.
- Find dependency updates — List dependencies that have newer versions.
- Build one module of many — Build a module and the modules it depends on in a multi-module project.
- Build in parallel — Use one thread per CPU core.
- Show the effective POM — Print the POM after inheritance and profiles are applied.
- Add the Maven wrapper — Add mvnw so everyone builds with the same Maven version.
Gradle
- Create a Gradle project — Generate a new project interactively.
- Add the Gradle wrapper — Generate gradlew so everyone builds with the same Gradle version.
- Build the project — Compile, test and package.
- Clean and build — Delete the build folder, then build.
- Run the tests with Gradle — Compile and run the unit tests.
- Run one test class — Run the tests in a single class.
- Build with Gradle without running tests — Exclude the test task from the build.
- List available tasks — Show the tasks you can run.
- Show the Gradle dependency tree — Print the dependencies of the project.
- Find why a dependency is included — Show how a dependency is resolved and which dependency brings it in.
- Refresh dependencies — Ignore cached dependency resolution and check the repositories again.
- Rebuild on file changes — Re-run the task whenever its inputs change.
- Show a full stack trace — Print the stack trace of build failures to diagnose them.
Related cheatsheets
- C++ 23 cheatsheet — Compile and debug C++ with g++ and CMake, and use modern C++ (up to C++23): containers, algorithms, smart pointers, templates and threads.
- C# 14 cheatsheet — Modern C# 14 syntax for strings, nullability, collections, LINQ, records, pattern matching, async code and generics.
- CSS 3 cheatsheet — Layout with flexbox and grid, responsive design, custom properties, animations and modern selectors.
- Go 1 cheatsheet — The go command for modules, building, testing and cross-compiling, plus the code patterns you write every day.
- HTML 5 cheatsheet — HTML5 page structure, text, links, images, forms, tables and metadata, with accessible patterns.
- JavaScript 2025 cheatsheet — Modern JavaScript for arrays, strings, objects, async code, the DOM and modules, in copy-ready snippets.