# Java SDK Quickstart

> Install the Copyleaks Java SDK, authenticate, and submit your first scan in under 5 minutes with this step-by-step guide.

This guide will walk you through installing the official Java SDK and running your first scan. In just a few minutes, you'll be able to check content for plagiarism, AI-generated text, moderation and more directly from your Java application.

Before you start, ensure you have the following:
- An active Copyleaks account. If you don't have one, **[sign up for free](https://api.copyleaks.com/signup)**.
- You can find your API key on the **[API Dashboard](https://api.copyleaks.com/dashboard)**.
## Get Started

<Steps>
  <Step title="Installation">
    The SDK requires **Java 11 or higher**. Add the official `copyleaks-java-sdk` dependency to your project's `pom.xml` file.

    ```xml title="pom.xml"
      <dependency>
          <groupId>com.copyleaks.sdk</groupId>
          <artifactId>copyleaks-java-sdk</artifactId>
          <version>5.1.0</version>
      </dependency>
    ```
  </Step>

  <Step title="Quick Example: Scan Text">
    <Warning>
    Remember to replace the placeholder credentials and webhook URL with your actual values.
    </Warning>

    ```java title="ScanExample.java"
    import classes.Copyleaks;
    import models.response.CopyleaksAuthToken;
    import models.submissions.CopyleaksFileSubmissionModel;
    import models.submissions.properties.SubmissionProperties;
    import models.submissions.properties.SubmissionWebhooks;
    import java.nio.charset.StandardCharsets;
    import java.util.Base64;
    import java.util.Random;

    public class ScanExample {
        // --- Your Credentials ---
        private static final String EMAIL_ADDRESS = "YOUR_EMAIL_ADDRESS";
        private static final String KEY = "YOUR_API_KEY";
        private static final String WEBHOOK_URL = "https://your-server.com/webhook/{STATUS}";
        // --------------------

        public static void main(String[] args) {
            CopyleaksAuthToken token;
            try {
                // Log in to the Copyleaks API
                System.out.println("Authenticating...");
                token = Copyleaks.login(EMAIL_ADDRESS, KEY);
                System.out.println(" Logged in successfully!");

                // Prepare your content for scanning
                System.out.println("Submitting text for scanning...");
                String textToScan = "Hello world, this is a test.";
                String base64Content = Base64.getEncoder().encodeToString(textToScan.getBytes(StandardCharsets.UTF_8));
                String filename = "test.txt";
                String scanId = Integer.toString(new Random().nextInt(100000));
                
                // Configure the scan
                SubmissionWebhooks webhooks = new SubmissionWebhooks(WEBHOOK_URL);
                SubmissionProperties submissionProperties = new SubmissionProperties(webhooks);
                submissionProperties.setSandbox(true); // Turn on sandbox mode for testing

                CopyleaksFileSubmissionModel submissionModel = new CopyleaksFileSubmissionModel(base64Content, filename, submissionProperties);

                // Submit the scan to Copyleaks
                Copyleaks.submitFile(token, scanId, submissionModel);
                System.out.println(" Scan submitted successfully! Scan ID: " + scanId);
                System.out.println("You will be notified via your webhook when the scan is complete.");

            } catch (Exception e) {
                System.out.println(" An error occurred:");
                e.printStackTrace();
            }
        }
    }
    ```
  </Step>

  <Step title="Understanding the Code">
    The example code performs four main actions to submit a scan:

    1.  **Login:** It authenticates with your email and API key to get a secure `CopyleaksAuthToken` object, which is required for all subsequent requests.
    2.  **Prepare Content:** It takes a simple string of text and encodes it into Base64 format.
    3.  **Configure Scan:** It creates a `SubmissionProperties` object containing `SubmissionWebhooks` to define the scan's behavior. We enable `sandbox` mode for safe testing and provide the webhook URL.
    4.  **Submit for Scanning:** It creates a `CopyleaksFileSubmissionModel` with the content and properties, then sends it to the Copyleaks API. The process is asynchronous; Copyleaks will notify your webhook URL once the scan is complete.
  </Step>
</Steps>

## Next Steps

<CardGroup cols={2}>
  <Card title="GitHub Repository" icon="github" href="https://github.com/Copyleaks/Java-Plagiarism-Checker">Check the official SDK repository on GitHub for more examples and details.</Card>
  <Card title="Maven Central" icon="java" href="https://central.sonatype.com/artifact/com.copyleaks.sdk/copyleaks-java-sdk?smo=true">View the official package on the Maven Central Repository to see all available versions.</Card>

</CardGroup>

<CardGroup cols={2}>
  <Card title="Check for Plagiarism" icon="magnifying-glass" href="/guides/authenticity/detect-plagiarism-text">
    Detect plagiarism in text documents using the Copyleaks API. Search billions of sources to find unoriginal content.
  </Card>
  <Card title="Detect AI-Generated Content" icon="robot" href="/guides/ai-detector/ai-text-detection">
    Detect AI-generated text via sync or async API calls. This guide covers sync detection, see the Authenticity API Guide for async.
  </Card>
  <Card title="Assess Grammar and Writing Quality" icon="spell-check" href="/guides/writing/check-grammar">
    Get writing and grammar suggestions via API. Authenticate, submit text, and access full details in the docs.
  </Card>
  <Card title="Moderate Text" icon="shield-halved" href="/guides/moderation/moderate-text">
    Scan and moderate text content for unsafe or policy-relevant material across 10+ categories.
  </Card>
</CardGroup>
