{"templateId":"markdown","sharedDataIds":{},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"XRPL Java Code Sample Conventions","siteUrl":"https://xrpl.org/","llmstxt":{"hide":false,"title":"XRPL Developer Portal & Documentation","description":"Explore XRP Ledger documentation, blogs, and other blockchain developer resources needed to start building and integrating with the ledger.","details":{"content":"XRP Ledger concepts, use cases, tutorials, references, and other blockchain developer resources. Also, stay up to date with release announcements and more through the XRPL Blog."},"sections":[{"title":"Introduction","description":"A high-level introduction to the XRP Ledger.","includeFiles":["docs/introduction/**/*.*","about/faq.md"],"excludeFiles":["docs/introduction/index.md"]},{"title":"Use Cases","description":"Real-world applications and business scenarios for the XRP Ledger.","includeFiles":["docs/use-cases/**/*.*"],"excludeFiles":["docs/use-cases/index.md","docs/use-cases/defi/index.md"]},{"title":"Concepts","description":"Core concepts including accounts, tokens, transactions, consensus, and more.","includeFiles":["docs/concepts/**/*.*"],"excludeFiles":["docs/concepts/index.md","docs/concepts/decentralized-storage/index.md","docs/concepts/payment-types/index.md"]},{"title":"Tutorials","description":"Step-by-step guides for building on the XRP Ledger in JavaScript, Python, Go, and more.","includeFiles":["docs/tutorials/**/*.*"],"excludeFiles":[]},{"title":"References","description":"Protocol specification, transaction types, ledger entries, and API methods.","includeFiles":["docs/references/**/*.*"],"excludeFiles":["docs/references/xrp-api.md","docs/references/data-api.md","docs/references/protocol/index.md","docs/references/protocol/ledger-data/ledger-entry-types/index.md","docs/references/protocol/transactions/index.md","docs/references/protocol/transactions/types/index.md","docs/references/http-websocket-apis/api-conventions/index.md","docs/references/http-websocket-apis/public-api-methods/*/index.md","docs/references/http-websocket-apis/admin-api-methods/*/index.md"]},{"title":"Infrastructure","description":"Install, configure, and troubleshoot rippled and Clio servers.","includeFiles":["docs/infrastructure/**/*.*"],"excludeFiles":["docs/infrastructure/index.md","docs/infrastructure/*/index.md","docs/infrastructure/installation/build-run-rippled-in-reporting-mode.md","docs/infrastructure/configuration/data-retention/index.md","docs/infrastructure/configuration/server-modes/index.md"]},{"title":"Blog (2023+)","description":"Recent XRPL Blog posts (showing 2023 and newer).","includeFiles":["blog/2023/**/*.*","blog/2024/**/*.*","blog/2025/**/*.*","blog/2026/**/*.*"],"excludeFiles":[]},{"title":"Resources","description":"Developer resources and contribution guidelines.","includeFiles":["resources/**/*.*"],"excludeFiles":["resources/index.md"]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"xrpl-java-code-sample-conventions","__idx":0},"children":["XRPL Java Code Sample Conventions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Java samples currently exist only in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["tutorial form"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"style","__idx":1},"children":["Style"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"formatting","__idx":2},"children":["Formatting"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["2-space indent"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["UTF-8 source encoding (declared in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["pom.xml"]},")"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"naming","__idx":3},"children":["Naming"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Class/file: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PascalCase"]}," verb-noun (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ManageCredentials.java"]},"); one public class per file"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Variables: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["camelCase"]}," (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["issuerAddress"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["subjectFuture"]},")"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Constants: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["UPPER_SNAKE_CASE"]}," for ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["static final"]}," (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["NETWORK_URL"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["FAUCET_URL"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["EXPLORER_BASE"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CREDENTIAL_TYPE"]},")"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Package: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["com.example.xrpl"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Imports: two blocks separated by a blank line — all non-",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["java.*"]}," imports together (alphabetized: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["com.*"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["okhttp3.*"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["org.*"]},", etc.), then ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["java.*"]}," last. No wildcard imports."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"structure","__idx":4},"children":["Structure"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"folder-layout","__idx":5},"children":["Folder layout"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Each code sample lives at ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["_code-samples/<topic>/java/"]}," as a self-contained Maven project:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"_code-samples/<topic>/java/\n├── README.md\n├── pom.xml\n├── target/                                 # Maven build output; gitignored\n└── src/main/\n    ├── java/com/example/xrpl/\n    │   └── <ClassName>.java                # Tutorial samples (one class per user action)\n    └── resources/\n        └── logback.xml\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Run any sample with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mvn exec:java -Dexec.mainClass=com.example.xrpl.<ClassName>"]}," from the language root directory."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"readme","__idx":6},"children":["README"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["README.md"]}," is the entry point for a reader running the samples."]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Title: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["# <Topic> Example (Java)"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["One-sentence description listing what the directory demonstrates"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["## Setup"]}," section with an ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mvn install"]}," fenced block"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["One ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["##"]}," section per tutorial sample, in the order a reader should run them:"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Heading is a human-readable phrase for the action (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["## Manage Credentials"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["## Issue a Token"]},") — not a code identifier like ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["## ManageCredentials"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Fenced ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sh"]}," block with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mvn exec:java -Dexec.mainClass=com.example.xrpl.<ClassName>"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["One-sentence summary of what the script will output"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Fenced ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sh"]}," block showing actual expected console output (real addresses, tx hashes, JSON dumps, explorer links — captured from a successful sample code run)"]}]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":5},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["---"]}," separator between tutorial sections"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"pomxml","__idx":7},"children":["pom.xml"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Java 11, UTF-8, single xrpl4j dependency, exec plugin for ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mvn exec:java"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"xml","header":{"controls":{"copy":{}}},"source":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0\n                             https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n  <modelVersion>4.0.0</modelVersion>\n\n  <groupId>com.example</groupId>\n  <artifactId>{topic}-samples</artifactId> <!-- e.g., credential-samples; change per directory -->\n  <version>1.0.0</version>\n  <packaging>jar</packaging>\n\n  <properties>\n    <maven.compiler.release>11</maven.compiler.release>\n    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n  </properties>\n\n  <build>\n    <plugins>\n      <plugin>\n        <groupId>org.codehaus.mojo</groupId>\n        <artifactId>exec-maven-plugin</artifactId>\n        <version>3.3.0</version>\n      </plugin>\n    </plugins>\n  </build>\n\n  <dependencies>\n    <dependency>\n      <groupId>org.xrpl</groupId>\n      <artifactId>xrpl4j-client</artifactId>\n      <version>{latest-stable}</version>\n    </dependency>\n  </dependencies>\n</project>\n","lang":"xml"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"logbackxml","__idx":8},"children":["logback.xml"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["src/main/resources/logback.xml"]}," quiets xrpl4j's DEBUG chatter so tutorial output stays readable:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"xml","header":{"controls":{"copy":{}}},"source":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- Quiets xrpl4j's DEBUG chatter so tutorial output stays readable.\n     Raise xrpl4j to DEBUG to see wire-level transaction details. -->\n<configuration>\n  <appender name=\"CONSOLE\" class=\"ch.qos.logback.core.ConsoleAppender\">\n    <encoder>\n      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>\n    </encoder>\n  </appender>\n\n  <logger name=\"org.xrpl.xrpl4j\" level=\"WARN\"/>\n\n  <root level=\"INFO\">\n    <appender-ref ref=\"CONSOLE\"/>\n  </root>\n</configuration>\n","lang":"xml"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"tutorial-files","__idx":9},"children":["Tutorial files"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["xrpl4j sync client"]}," — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["org.xrpl.xrpl4j.client.XrplClient"]},". Use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CompletableFuture.supplyAsync"]}," + ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["allOf().join()"]}," for parallel work (e.g., funding multiple accounts)."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"structure-1","__idx":10},"children":["Structure"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Class-level Javadoc explaining what the sample demonstrates (and any preconditions, if applicable)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["package com.example.xrpl;"]}," + imports (alphabetical within groups, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["java.*"]}," last)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Class declaration with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["NETWORK_URL"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["FAUCET_URL"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["EXPLORER_BASE"]},", and tutorial-specific constants at top:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"private static final HttpUrl NETWORK_URL = HttpUrl.get(\"https://s.altnet.rippletest.net:51234/\");\nprivate static final HttpUrl FAUCET_URL = HttpUrl.get(\"https://faucet.altnet.rippletest.net\");\nprivate static final String EXPLORER_BASE = \"https://testnet.xrpl.org/transactions/\";\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":4},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["main()"]}," wraps ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["run()"]}," and unwraps ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CompletionException"]}," so async failures print the same clean message as sync ones:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"public static void main(String[] args) {\n  try {\n    run();\n  } catch (Exception e) {\n    // Unwrap CompletionException so async failures print the same clean message\n    // as sync failures. CompletableFuture.join() wraps exceptions in CompletionException\n    Throwable cause = (e instanceof CompletionException && e.getCause() != null)\n      ? e.getCause() : e;\n    System.err.println(\"Error: \" + cause.getMessage());\n    System.exit(1);\n  }\n}\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":5},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["private static void run()"]}," holds the main flow."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Connect to network and fund however many accounts the sample needs. Fund in parallel via ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CompletableFuture.supplyAsync"]}," + ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["allOf().join()"]}," when there's more than one. Two-account example:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"// ----- Connect to Testnet and fund accounts -----\nXrplClient xrplClient = new XrplClient(NETWORK_URL);\nSystem.out.println(\"\\n=== Funding issuer and subject accounts on Testnet ===\\n\");\n\nCompletableFuture<KeyPair> issuerFuture = CompletableFuture.supplyAsync(\n  () -> createAndFundWallet(xrplClient));\nCompletableFuture<KeyPair> subjectFuture = CompletableFuture.supplyAsync(\n  () -> createAndFundWallet(xrplClient));\nCompletableFuture.allOf(issuerFuture, subjectFuture).join();\n\nKeyPair issuer = issuerFuture.join();\nKeyPair subject = subjectFuture.join();\nAddress issuerAddress = issuer.publicKey().deriveAddress();\nAddress subjectAddress = subject.publicKey().deriveAddress();\nSystem.out.println(\"Issuer:  \" + issuerAddress);\nSystem.out.println(\"Subject: \" + subjectAddress);\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":7},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Tutorial code steps."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Useful helpers below a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["// ===== Helper functions ====="]}," divider, each prefixed with a one-line comment. Copy any helpers the sample uses — the signatures and bodies below are canonical; only include the ones you call:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"// ===== Helper functions =====\n\n// Generates a new Ed25519 keypair, funds it from the Testnet faucet, and\n// returns the keypair once the account is visible on a validated ledger.\nprivate static KeyPair createAndFundWallet(XrplClient xrplClient) {\n  KeyPair keyPair = Seed.ed25519Seed().deriveKeyPair();\n  Address address = keyPair.publicKey().deriveAddress();\n  FaucetClient faucetClient = FaucetClient.construct(FAUCET_URL);\n  faucetClient.fundAccount(FundAccountRequest.of(address));\n\n  for (int attempt = 0; attempt < 20; attempt++) {\n    try {\n      xrplClient.accountInfo(AccountInfoRequestParams.builder()\n        .account(address)\n        .ledgerSpecifier(LedgerSpecifier.VALIDATED)\n        .build());\n      return keyPair;\n    } catch (JsonRpcClientErrorException notYetVisible) {\n      try {\n        Thread.sleep(1_000L);\n      } catch (InterruptedException e) {\n        Thread.currentThread().interrupt();\n        throw new RuntimeException(\"Account polling interrupted for \" + address + \". \" + e.getMessage(), e);\n      }\n    }\n  }\n  throw new IllegalStateException(\"Faucet funding for \" + address + \" did not confirm in time.\");\n}\n\n// Fetches the next transaction sequence number of an address from\n// the latest validated ledger.\nprivate static UnsignedInteger accountSequence(XrplClient xrplClient, Address address) {\n  try {\n    AccountInfoResult info = xrplClient.accountInfo(AccountInfoRequestParams.builder()\n      .account(address)\n      .ledgerSpecifier(LedgerSpecifier.VALIDATED)\n      .build());\n    return info.accountData().sequence();\n  } catch (JsonRpcClientErrorException e) {\n    throw new RuntimeException(\"Failed to fetch account sequence for \" + address + \". \" + e.getMessage(), e);\n  }\n}\n\n// Fetches the current network fee and returns the recommended fee for\n// a standard (non-multisig, non-batch) transaction.\nprivate static XrpCurrencyAmount recommendedFee(XrplClient xrplClient) {\n  try {\n    return FeeUtils.computeNetworkFees(xrplClient.fee()).recommendedFee();\n  } catch (JsonRpcClientErrorException e) {\n    throw new RuntimeException(\"Failed to fetch network fee. \" + e.getMessage(), e);\n  }\n}\n\n// Computes a safe LastLedgerSequence for a new transaction. The\n// latest validated ledger index plus a small buffer (20 ledgers).\nprivate static UnsignedInteger lastLedgerSequence(XrplClient xrplClient) {\n  try {\n    UnsignedInteger validatedLedger = xrplClient.ledger(LedgerRequestParams.builder()\n        .ledgerSpecifier(LedgerSpecifier.VALIDATED)\n        .build())\n      .ledgerIndexSafe()\n      .unsignedIntegerValue();\n    return validatedLedger.plus(UnsignedInteger.valueOf(20));\n  } catch (JsonRpcClientErrorException e) {\n    throw new RuntimeException(\"Failed to compute LastLedgerSequence. \" + e.getMessage(), e);\n  }\n}\n\n// Prints a transaction as a formatted JSON.\nprivate static void printTransactionJson(Transaction tx) {\n  try {\n    System.out.println(ObjectMapperFactory.create().writerWithDefaultPrettyPrinter().writeValueAsString(tx));\n  } catch (JsonProcessingException e) {\n    throw new RuntimeException(\"Failed to serialize transaction JSON. \" + e.getMessage(), e);\n  }\n}\n\n// Signs and submits a transaction, then polls the network until\n// the transaction reaches a validated state.\nprivate static <T extends Transaction> TransactionResult<T> signSubmitAndWait(\n  XrplClient xrplClient,\n  KeyPair signer,\n  T transaction,\n  Class<T> transactionType\n) {\n  SignatureService<PrivateKey> signatureService = new BcSignatureService();\n\n  UnsignedInteger lastLedgerSequence = transaction.lastLedgerSequence()\n    .orElseThrow(() -> new IllegalArgumentException(\n      \"Must set LastLedgerSequence for polling expiration\"));\n\n  try {\n    SingleSignedTransaction<T> signed = signatureService.sign(signer.privateKey(), transaction);\n    SubmitResult<T> submit = xrplClient.submit(signed);\n\n    if (!TransactionResultCodes.TES_SUCCESS.equals(submit.engineResult())) {\n      throw new IllegalStateException(\n        \"Submission rejected. \" + submit.engineResult() + \" — \" + submit.engineResultMessage());\n    }\n\n    Finality finality;\n    do {\n      Thread.sleep(1_000L);\n      finality = xrplClient.isFinal(\n        signed.hash(),\n        submit.validatedLedgerIndex(),\n        lastLedgerSequence,\n        transaction.sequence(),\n        signer.publicKey().deriveAddress()\n      );\n    } while (finality.finalityStatus() == FinalityStatus.NOT_FINAL);\n\n    if (finality.finalityStatus() != FinalityStatus.VALIDATED_SUCCESS) {\n      throw new IllegalStateException(\n        \"Transaction failed with status \" + finality.finalityStatus()\n          + \". Result code: \" + finality.resultCode().orElse(\"unknown\"));\n    }\n\n    // Retrieve the transaction result; isFinal() only returns finality status\n    return xrplClient.transaction(\n      TransactionRequestParams.of(signed.hash()), transactionType);\n\n  } catch (InterruptedException e) {\n    Thread.currentThread().interrupt();\n    throw new RuntimeException(\"Transaction polling interrupted. \" + e.getMessage(), e);\n  } catch (JsonRpcClientErrorException | JsonProcessingException e) {\n    throw new RuntimeException(\"Transaction processing failed. \" + e.getMessage(), e);\n  }\n}\n\n// Checks for a tesSUCCESS result code. If true, prints an explorer\n// link. Otherwise, throws an error.\nprivate static void requireSuccess(TransactionResult<?> result) {\n  String code = result.metadata().get().transactionResult();\n  String txType = result.transaction().transactionType().value();\n  if (!TransactionResultCodes.TES_SUCCESS.equals(code)) {\n    throw new IllegalStateException(txType + \" failed with error code \" + code);\n  }\n  System.out.println(txType + \" succeeded!\");\n  System.out.println(\"Explorer: \" + EXPLORER_BASE + result.hash());\n}\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"tutorial-code-step-guide","__idx":11},"children":["Tutorial code step guide"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Before each major step, add a section comment and print a banner. Strict format: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["// ----- Title -----"]}," on its own line, then ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["System.out.println(\"\\n=== Title ===\\n\");"]}," immediately after. The title text should match between the two."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Build transactions with the builder pattern; always set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sequence"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["fee"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lastLedgerSequence"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["signingPublicKey"]}," from shared helpers, then print as pretty JSON:",{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"// ----- Prepare CredentialCreate transaction -----\nSystem.out.println(\"\\n=== Preparing CredentialCreate transaction ===\\n\");\n\nCredentialCreate createTx = CredentialCreate.builder()\n  .account(issuerAddress)\n  .subject(subjectAddress)\n  .credentialType(CREDENTIAL_TYPE)\n  .sequence(accountSequence(xrplClient, issuerAddress))\n  .fee(recommendedFee(xrplClient))\n  .lastLedgerSequence(lastLedgerSequence(xrplClient))\n  .signingPublicKey(issuer.publicKey())\n  .build();\nprintTransactionJson(createTx);\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Sign, submit, and wait via the shared ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["signSubmitAndWait"]}," helper, then verify success with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requireSuccess"]},":",{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"// ----- Sign, submit, and wait for CredentialCreate validation -----\nSystem.out.println(\"\\n=== Submitting CredentialCreate transaction ===\\n\");\n\nTransactionResult<CredentialCreate> createResult = signSubmitAndWait(\n  xrplClient, issuer, createTx, CredentialCreate.class);\n\nrequireSuccess(createResult);\n","lang":"java"},"children":[]}]}]}]},"headings":[{"value":"XRPL Java Code Sample Conventions","id":"xrpl-java-code-sample-conventions","depth":1},{"value":"Style","id":"style","depth":2},{"value":"Formatting","id":"formatting","depth":3},{"value":"Naming","id":"naming","depth":3},{"value":"Structure","id":"structure","depth":2},{"value":"Folder layout","id":"folder-layout","depth":3},{"value":"README","id":"readme","depth":3},{"value":"pom.xml","id":"pomxml","depth":3},{"value":"logback.xml","id":"logbackxml","depth":3},{"value":"Tutorial files","id":"tutorial-files","depth":2},{"value":"Structure","id":"structure-1","depth":3},{"value":"Tutorial code step guide","id":"tutorial-code-step-guide","depth":3}],"frontmatter":{"paths":["_code-samples/**/*.java"],"seo":{"title":"XRPL Java Code Sample Conventions"}},"editPage":{"to":"https://github.com/XRPLF/xrpl-dev-portal/tree/master/.claude/rules/java-code-samples.md"},"lastModified":"2026-06-05T19:13:01.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/.claude/rules/java-code-samples","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}