Stop Writing Glue Code: AI in Java, the Clean Way A developer published a working example showing how Java teams can replace hand-written HTTP and JSON glue code for LLM calls with LangChain4j's AiServices, declaring a plain Java interface annotated with @SystemMessage and @UserMessage and letting the library generate the implementation that calls Anthropic's Claude. The example, built on Java 21 with the langchain4j-anthropic 1.24.1 dependency, classifies support tickets into BILLING, TECHNICAL or OTHER and returns typed results without manual escaping or response parsing. Every Java team that starts working with large language models hits the same wall. The first demo is easy: build a JSON body, send an HTTP request, parse the response, print the text. Then the requirements arrive. The model must return a typed object. The prompt must be reused in six places. The same request must be retried on rate limits. Suddenly the codebase is full of string concatenation, manual JSON mapping and fragile parsing code. That code has a name: glue code. This article shows a cleaner approach. With LangChain4j, you declare a plain Java interface, annotate its methods with the prompt, and the library generates the implementation that calls Claude for you. You write the contract, not the plumbing. The full working example is in the repository 02 - AI Services https://github.com/josesaid/02-ai-services , and the project page is at josesaid.github.io/02-ai-services https://josesaid.github.io/02-ai-services/ . Consider a simple task: classify a support ticket. A first attempt usually looks like this: String prompt = "Classify this ticket as BILLING, TECHNICAL or OTHER. Ticket: " + ticket; String body = """ {"model":"claude-haiku-5-5","max tokens":50, "messages": {"role":"user","content":"%s"} } """.formatted prompt.replace "\"", "\\\"" ; HttpRequest request = HttpRequest.newBuilder URI.create API URL .header "x-api-key", apiKey .header "anthropic-version", "2023-06-01" .POST HttpRequest.BodyPublishers.ofString body .build ; HttpResponse