All Products
Search
Document Center

Alibaba Cloud SDK:Set up a Java development environment on Windows

Last Updated:Jun 21, 2026

This tutorial shows how to set up a Java development environment on Windows, using IntelliJ IDEA as an example.

What is a Java development environment?

A Java development environment is a set of tools and configurations for developing Java applications. It includes a Java Development Kit (JDK), an integrated development environment (IDE) such as IntelliJ IDEA, Eclipse, or VSCode, and build tools such as Maven.

Install the JDK

For detailed steps, see Install the JDK on Windows.

Install an IDE

This guide uses IntelliJ IDEA Community as an example. Go to the IntelliJ IDEA Community download page, click Download, and follow the installation wizard.

Important

During installation, on the **Installation Options** step, select the **Add "bin" folder to the PATH** checkbox. For all other steps, click **Next** to accept the default settings.

Create a Maven project

  1. Open IntelliJ IDEA and click **New Project**.

    A project provides a comprehensive environment for the entire software development lifecycle—from coding and testing to building, running, and deployment—helping you efficiently manage your application.

  2. In the **New Project** window, select **Java** from the left panel and configure the following settings:

    Name: Enter a name for your project. This example uses helloaliyun.

    Location: Specify the directory where you want to save your project.

    Build system: Select **Maven** to create a Maven project.

    JDK: Select your desired JDK version. This example uses JDK 8.

    Note

    To select a JDK, click **Add JDK...** and navigate to the installation directory of the JDK that you installed.

    Add sample code: Select this checkbox to automatically create a Main class.

  3. Click **Create**.

    A project named helloaliyun is created. It contains a basic pom.xml file, a src/main/java source directory, and a class named Main.

  4. Verify the setup.

    In the src/main/java directory, navigate to the org.example package and find the Main class. Double-click the class name to open the file, then click the Run icon in the upper-right corner.

    Check the console for the output Hello world!. If this message appears, your Java development environment is set up correctly.

    Sample output:

    "D:\Program Files\Java\jdk-1.8\bin\java.exe" ...
    Hello world!
    Process finished with exit code 0

Next steps

Now that your Java development environment is set up, you can explore its practical applications. The following sections provide use cases and guides for various Java development tasks.

1. Call Alibaba Cloud OpenAPI by using the Java SDK

  1. To make an API call, you must first obtain an AccessKey pair to use as your access credential. We recommend using the AccessKey pair of a RAM user. For more information, see Create an AccessKey pair for a RAM user.

    Important

    After you obtain the AccessKey pair, configure it as an environment variable. For more information, see Configure environment variables on Linux, macOS, and Windows.

  2. Log on to the SDK Center and select the product you want to use. This example uses the DescribeInstanceTypeFamilies API of ECS.

  3. On the Parameters tab, configure the parameters. Refer to the Document tab on the right for the API description, usage notes (especially billing information), and details on each parameter's meaning and usage. For example, when using the DescribeInstanceTypeFamilies API, set the required RegionId parameter to cn-qingdao for China (Qingdao) and the optional Generation parameter to ecs-5 for the series V instance family. The Document tab provides further details for each request parameter, such as its type, whether it is required, and example values.

  4. On the SDK Sample tab, select Java and click Download Project to download the SDK project and decompress it.

  5. Sample code:

    import com.aliyun.ecs20140526.Client;
    import com.aliyun.ecs20140526.models.DescribeInstanceTypeFamiliesRequest;
    import com.aliyun.ecs20140526.models.DescribeInstanceTypeFamiliesResponse;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teaopenapi.models.Config;
    import com.google.gson.Gson;
    public class Sample {
        public static void main(String[] args) {
            try {
                Config config = new Config()
                        // System.getenv retrieves the key from an environment variable.
                        .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                        .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
                config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
                Client client = new Client(config);
                DescribeInstanceTypeFamiliesRequest describeInstanceTypeFamiliesRequest = new DescribeInstanceTypeFamiliesRequest();
                describeInstanceTypeFamiliesRequest.setRegionId("cn-qingdao");
                describeInstanceTypeFamiliesRequest.setGeneration("ecs-5");
                DescribeInstanceTypeFamiliesResponse describeInstanceTypeFamiliesResponse = client.describeInstanceTypeFamilies(describeInstanceTypeFamiliesRequest);
                System.out.println(new Gson().toJson(describeInstanceTypeFamiliesResponse));
            } catch (TeaException teaException) {
                // Print the error code.
                System.out.println(teaException.getCode());
                // Print the error message, which includes the RequestId.
                System.out.println(teaException.getMessage());
                // Print the specific error content returned by the server.
                System.out.println(teaException.getData());
            } catch (Exception e) {
                TeaException error = new TeaException(e.getMessage(), e);
                // Error message.
                System.out.println(error.getMessage());
                // Diagnostic address.
                System.out.println(error.getData().get("Recommend"));
                com.aliyun.teautil.Common.assertAsString(error.message);
            }
        }
    }
              
  6. Result: After running the code, the API returns a statusCode of 200, which indicates a successful call. The response body contains a list of instance families in the InstanceTypeFamilies field. The following snippet shows part of the response:

    ...'statusCode': 200, 'body': {'InstanceTypeFamilies': {'InstanceTypeFamily': [{'Generation': 'ecs-5', 'InstanceTypeFamilyId': 'ecs.g6'}, {'Generation': 'ecs-5', 'InstanceTypeFamilyId': 'ecs.ebmg6'}]}}
  7. For more information about using the Java SDK to call Alibaba Cloud OpenAPI, see Use the Alibaba Cloud SDK for Java in an IDE.

2. Call the Qwen API to implement a conversational feature

  1. Alibaba Cloud Model Studio allows you to call a large model by using an API. It provides multiple access methods, including an OpenAI-compatible API and the DashScope SDK. To call the service, first activate Alibaba Cloud Model Studio and obtain an API key. For more information, see Account Settings.

    Important

    After you obtain an API key, configure it as an environment variable. This avoids hardcoding the key in your application, which reduces the risk of leaks. For instructions, see Configure an API key as an environment variable.

  2. Add the following dependency to your pom.xml file to install the DashScope SDK for Java:

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dashscope-sdk-java</artifactId>
        <!-- Replace 'the-latest-version' with the latest version from https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
        <version>the-latest-version</version>
    </dependency>
  3. After installing the Java and DashScope SDKs, run the following sample code to call the Qwen API:

    package org.example.nlp.ai;
    import java.util.Arrays;
    import java.lang.System;
    import com.alibaba.dashscope.aigc.generation.Generation;
    import com.alibaba.dashscope.aigc.generation.GenerationParam;
    import com.alibaba.dashscope.aigc.generation.GenerationResult;
    import com.alibaba.dashscope.common.Message;
    import com.alibaba.dashscope.common.Role;
    import com.alibaba.dashscope.exception.ApiException;
    import com.alibaba.dashscope.exception.InputRequiredException;
    import com.alibaba.dashscope.exception.NoApiKeyException;
    public class Sample {
        public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
            Generation gen = new Generation();
            Message systemMsg = Message.builder()
                    .role(Role.SYSTEM.getValue())
                    .content("You are a helpful assistant.")
                    .build();
            Message userMsg = Message.builder()
                    .role(Role.USER.getValue())
                    .content("Who are you?")
                    .build();
            GenerationParam param = GenerationParam.builder()
                    // System.getenv retrieves the API key from an environment variable. If you have not configured the environment variable, replace the following line with .apiKey("sk-xxx") and use your API key from Alibaba Cloud Model Studio.
                    .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                    .model("qwen-plus")
                    .messages(Arrays.asList(systemMsg, userMsg))
                    .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                    .build();
            return gen.call(param);
        }
        public static void main(String[] args) {
            try {
                GenerationResult result = callWithMessage();
                System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent());
            } catch (ApiException | NoApiKeyException | InputRequiredException e) {
                System.err.println("Error message: " + e.getMessage());
            }
            System.exit(0);
        }
    }
                    
  4. Result: After running the code, you should see output similar to the following:

    15:44:00.413 [main] DEBUG com.alibaba.dashscope.protocol.okhttp.OkHttpClientFactory - [connectionPool Config] connectionPoolSize: 32
    15:44:00.468 [main] DEBUG com.alibaba.dashscope.protocol.okhttp.OkHttpClientFactory - [connectionPool Config] maxRequests: 32
    15:44:00.468 [main] DEBUG com.alibaba.dashscope.protocol.okhttp.OkHttpClientFactory - [connectionPool Config] maxRequestsPerHost: 32
    I am Qwen, a large language model developed by the Tongyi Lab at Alibaba Group. I can answer questions, create content such as stories, official documents, emails, scripts, and poems, and perform logical reasoning, programming, and even play games. I am proficient in multiple languages and can provide you with a wide range of assistance. If you have any questions or need to create content
  5. For more information about calling the Qwen API, see Use the DashScope SDK for Java.

3. Call the DeepSeek API

This section describes how to call DeepSeek models by using APIs on the Alibaba Cloud Model Studio platform. deepseek-r1 and deepseek-v3 each provide 1 million free tokens, and some distilled models are available for a limited-time free trial.

  1. To call the service, first activate Alibaba Cloud Model Studio and obtain an API key. For more information, see Account Settings.

    Important

    After you obtain an API key, configure it as an environment variable. This avoids hardcoding the key in your application, which reduces the risk of leaks. For instructions, see Configure an API key as an environment variable.

  2. Add the following dependency to your pom.xml file to install the DashScope SDK for Java:

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dashscope-sdk-java</artifactId>
        <!-- Replace 'the-latest-version' with the latest version from https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
        <version>the-latest-version</version>
    </dependency>
    Important

    The DashScope SDK version must be 2.18.2 or later.

  3. After installing the Java and DashScope SDKs, run the following sample code to call the DeepSeek model service:

    import java.util.Arrays;
    import java.lang.System;
    import com.alibaba.dashscope.aigc.generation.Generation;
    import com.alibaba.dashscope.aigc.generation.GenerationParam;
    import com.alibaba.dashscope.aigc.generation.GenerationResult;
    import com.alibaba.dashscope.common.Message;
    import com.alibaba.dashscope.common.Role;
    import com.alibaba.dashscope.exception.ApiException;
    import com.alibaba.dashscope.exception.InputRequiredException;
    import com.alibaba.dashscope.exception.NoApiKeyException;
    public class Sample {
        public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
            Generation gen = new Generation();
            Message userMsg = Message.builder()
                    .role(Role.USER.getValue())
                    .content("Which is larger: 9.9 or 9.11?")
                    .build();
            GenerationParam param = GenerationParam.builder()
                    // If you have not configured an environment variable, replace the following line with .apiKey("sk-xxx") and use your API key from Alibaba Cloud Model Studio.
                    .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                    .model("deepseek-r1")
                    .messages(Arrays.asList(userMsg))
                    // Do not set this to "text".
                    .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                    .build();
            return gen.call(param);
        }
        public static void main(String[] args) {
            try {
                GenerationResult result = callWithMessage();
                System.out.println("Reasoning:");
                System.out.println(result.getOutput().getChoices().get(0).getMessage().getReasoningContent());
                System.out.println("Final answer:");
                System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent());
            } catch (ApiException | NoApiKeyException | InputRequiredException e) {
                // Use a logging framework to record exception information.
                System.err.println("An error occurred while calling the generation service: " + e.getMessage());
            }
            System.exit(0);
        }
    }
                    
  4. Review the output.

    Reasoning:
    Hmm, the user is asking which is larger, 9.9 or 9.11. This looks simple, but it may need careful analysis, especially how the numbers are interpreted. First, I should confirm whether the user means decimals or something else, like version numbers or dates. But as a common math question, it should be a decimal comparison.
    First, I need to clarify the structure of these numbers. 9.9 is usually 9 plus 0.9, which is 9.90. 9.11 is 9 plus 0.11. The integer parts are both 9, so I compare the fractional parts: 0.90 and 0.11. Clearly, 0.90 is greater than 0.11, so 9.9 is larger than 9.11. However, a common confusion happens when the numbers are treated as version numbers, such as software versions.
    But the user may have a different context. If treated as a version number, 9.11 can mean version 9, update 11, while 9.9 means version 9, update 9, and then 9.11 is greater. So I may need to confirm the context, but as a standard decimal comparison, 9.9 is larger.
    Final answer:
    When comparing 9.9 and 9.11 as **decimal numbers**:
    - Treat 9.9 as 9.90, so the fractional part is 0.90.
    - The fractional part of 9.11 is 0.11.
    - Since **0.90 > 0.11**, **9.9 > 9.11**.
    If you mean **version numbers** (such as software versions):
    - 9.11 can mean the 11th update of version 9, while 9.9 is the 9th update, so **9.11 > 9.9**.
    **By default, as decimals, 9.9 is larger.**