ChatGPT Prompt for Java Developer: 12 Prompts for Daily Work
12 ChatGPT prompts for Java developers: code review, JUnit 5 tests, Spring Boot endpoints, concurrency checks, performance, and readable docs for your team.

A ChatGPT prompt for Java developer tasks works best when it carries the facts a reviewer would need: your Java version, build tool, framework, test libraries, and what you are not allowed to change. The 12 prompts below cover code review, JUnit 5 tests, Spring Boot work, concurrency, performance, and docs. Paste one class or diff at a time, remove secrets first, and run every suggested test yourself.
Review and fix code
1. Focused code review
Review this Java class [paste] for Java [version]. List bugs, risks, and style notes in a table with the method, the issue, and the fix. Check money math, nulls, resources, and thread safety.
2. Explain a stack trace
Here is a stack trace [paste] and the methods it points to [paste]. Explain the most likely cause in plain words, what to log to confirm it, and the smallest fix.
3. Exception handling cleanup
Find every place in this code [paste] that swallows an exception or catches Exception broadly, and suggest specific exceptions and messages that keep the cause.
Write tests
4. JUnit 5 tests for a class
Write JUnit 5 tests for [class] [paste] using [Mockito, AssertJ]. Name each test for the behavior, cover edge cases such as empty lists and nulls, and do not mock the class under test.
5. Failing test first for a bug
Bug report: [describe]. Write one JUnit 5 test that fails on this code [paste] and passes once the bug is fixed, then show the fix.
6. Parameterized test table
Turn these input and expected output pairs [paste] into a JUnit 5 parameterized test with a readable name for each case.
Spring Boot work
7. REST endpoint from a spec
Using Spring Boot [version], write a controller, request and response records, and validation for this endpoint spec [paste]. Return clear error responses and list the tests to add.
8. Configuration review
Review this application.yml [paste with secrets removed] for Spring Boot [version]. Flag risky defaults, properties that look misspelled, and values that should come from environment variables.
Performance and concurrency
9. Thread safety check
This class is used by many requests at once [paste]. Find shared mutable state and non-thread-safe classes, and suggest the smallest safe change for Java [version].
10. Slow method investigation
This method is slow with [data size] [paste]. Point out likely hot spots, such as repeated queries or boxing in loops, and tell me what to measure before I change anything.
Docs and learning
11. Javadoc for a public API
Write Javadoc for the public methods in this class [paste]: what each does, parameters, return value, and exceptions thrown. Do not describe behavior the code does not have.
12. Explain a newer Java feature
Explain [records, sealed classes, switch pattern matching, or virtual threads] with a short example based on this code of mine [paste], and tell me which Java version I need.
Run a full review in one prompt
The flagship Java Developer Prompt: Code Review with JUnit 5 Test Plan takes your code, Java version, framework, test stack, intent, and constraints, and returns a findings table, constraint conflicts, a minimal patch, one JUnit 5 test per bug, run commands, and questions for the team. Its example fixes double money math, a shared SimpleDateFormat, and an unclosed file reader without changing public method signatures.
Tips for better Java answers
Always state your Java version, because features such as records or virtual threads depend on it. Name your test libraries so the model does not import ones you do not use. Treat any API you have not seen before as unverified until you find it in the JDK or library docs, and run the tests before and after every change.
Related prompts
If you code in Cursor, use the Cursor rules for Java Spring Boot prompt and read Cursor rules for Java Spring Boot. For larger cleanups, try the code refactoring prompt, and see the code review agent prompt guide.
More coding help: ChatGPT prompts for debugging and code refactoring.
Find more in the Coding category, look through Browse, or post your own on Share.