Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: improve readme for java version and example #923

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

1. 要使用 Alibaba Cloud SDK for Java ,您需要一个云账号以及一对`Access Key ID`和`Access Key Secret`。 请在阿里云控制台中的[RAM管理页面](https://ram.console.aliyun.com)上创建和查看您的Access Key,或者联系您的系统管理员。
2. 要使用 Alibaba Cloud SDK for Java 访问某个产品的API,您需要事先在[阿里云控制台](https://home.console.aliyun.com)中开通这个产品。
3. Alibaba Cloud SDK for Java 需要1.6以上的JDK
3. Alibaba Cloud SDK for Java 需要 1.8 以上的 JDK

## 安装依赖

Expand Down Expand Up @@ -68,32 +68,32 @@

## 快速使用

以下这个代码示例向您展示了调用 Alibaba Cloud SDK for Java 的3个主要步骤:

1. 创建DefaultAcsClient实例并初始化。
2. 创建API请求并设置参数。
3. 发起请求并处理应答或异常。
以下这个代码示例向您展示了如何调用 Alibaba Cloud SDK for Java:

```java
package com.testprogram;

import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.ecs.model.v20140526.*;

public class Main {
public static void main(String[] args) {
// 创建DefaultAcsClient实例并初始化
// 1. 创建DefaultAcsClient实例并初始化
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // 地域ID
"<your-access-key-id>", // RAM账号的AccessKey ID
"<your-access-key-secret>"); // RAM账号Access Key Secret
IAcsClient client = new DefaultAcsClient(profile);
// 创建API请求并设置参数

// 2. 创建API请求并设置参数
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.setPageSize(10);
// 发起请求并处理应答或异常

// 3. 发起请求并处理应答或异常
DescribeInstancesResponse response;
try {
response = client.getAcsResponse(request);
Expand All @@ -109,6 +109,8 @@ public class Main {
}
```

> 因为安全的原因,我们不推荐在源代码中硬编码凭证信息。你应该通过外部配置或者环境变量的方式来访问凭证信息。

## 文档

* [环境要求](./docs/0-Requirements-CN.md)
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ If you have any problem while using Alibaba Cloud SDK for Java, please [submit a
## Requirements

- To use Alibaba Cloud SDK for Java, you must have an Alibaba Cloud account as well as an `AccessKey ID` and an `AccessKey Secret`. Create and view your AccessKey on the [RAM console](https://ram.console.aliyun.com "RAM console") or contact your system administrator.

- To use the Alibaba Cloud SDK for Java to access the APIs of a product, you must first activate the product on the [Alibaba Cloud console](https://home.console.aliyun.com) if required.

- The Alibaba Cloud Java SDK requires JDK 1.6 or later.
- The Alibaba Cloud Java SDK requires JDK 1.8 or later.

## Installation

Expand Down Expand Up @@ -71,34 +69,32 @@ If maven is not downloading jar packages from a central repository, you need to

## Quick Examples

The following code example shows the three main steps to use Alibaba Cloud SDK for Java :

1. Create and initialize a `DefaultAcsClient` instance.

2. Create an API request and set parameters.

3. Initiate the request and handle the response or exceptions.
The following code example shows how to use Alibaba Cloud SDK for Java :

```java
package com.testprogram;

import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.ecs.model.v20140526.*;

public class Main {
public static void main(String[] args) {
// Create and initialize a DefaultAcsClient instance
// 1. Create and initialize a DefaultAcsClient instance
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // The region ID
"<your-access-key-id>", // The AccessKey ID of the RAM account
"<your-access-key-secret>"); // The AccessKey Secret of the RAM account
IAcsClient client = new DefaultAcsClient(profile);
// Create an API request and set parameters

// 2. Create an API request and set parameters
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.setPageSize(10);
// Initiate the request and handle the response or exceptions

// 3. Initiate the request and handle the response or exceptions
DescribeInstancesResponse response;
try {
response = client.getAcsResponse(request);
Expand All @@ -114,6 +110,9 @@ public class Main {
}
```

> For security reason, we don't recommend to hard code credentials information in source code. You should access
> credentials from external configurations or environment variables.

## Documentation

- [Requirements](./docs/0-Requirements-EN.md)
Expand Down
Loading