From 239090861160185fc61128ea3bcdabbe432fd391 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Mon, 22 Jul 2024 17:11:56 +0800 Subject: [PATCH] doc: improve readme for java version and example --- README-CN.md | 20 +++++++++++--------- README.md | 25 ++++++++++++------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/README-CN.md b/README-CN.md index 99886064b0..2e9448baac 100644 --- a/README-CN.md +++ b/README-CN.md @@ -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。 ## 安装依赖 @@ -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( "", // 地域ID "", // RAM账号的AccessKey ID ""); // 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); @@ -109,6 +109,8 @@ public class Main { } ``` +> 因为安全的原因,我们不推荐在源代码中硬编码凭证信息。你应该通过外部配置或者环境变量的方式来访问凭证信息。 + ## 文档 * [环境要求](./docs/0-Requirements-CN.md) diff --git a/README.md b/README.md index c3c6deda17..fbadd76133 100755 --- a/README.md +++ b/README.md @@ -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 @@ -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( "", // The region ID "", // The AccessKey ID of the RAM account ""); // 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); @@ -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)