diff --git a/api/src/main/java/io/minio/MinioClient.java b/api/src/main/java/io/minio/MinioClient.java index 9be6207b4..f421fb866 100755 --- a/api/src/main/java/io/minio/MinioClient.java +++ b/api/src/main/java/io/minio/MinioClient.java @@ -167,6 +167,20 @@ * *

Examples on using this library are available here. + * + *

Use {@code MinioClient.builder()} to create S3 client. + * {@code + * // Create client with anonymous access. + * MinioClient minioClient = MinioClient.builder() + * .endpoint("https://play.min.io") + * .build(); + * + * // Create client with credentials. + * MinioClient minioClient = MinioClient.builder() + * .endpoint("https://play.min.io") + * .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") + * .build(); + * } */ @SuppressWarnings({"SameParameterValue", "WeakerAccess"}) public class MinioClient { @@ -213,25 +227,52 @@ public class MinioClient { standardHeaders.add("range"); } + private String userAgent = DEFAULT_USER_AGENT; private PrintWriter traceStream; - // the current client instance's base URL. private HttpUrl baseUrl; - // access key to sign all requests with + private String region; + private boolean isAwsHost; + private boolean isAcceleratedHost; + private boolean isDualStackHost; + private boolean useVirtualStyle; private String accessKey; - // Secret key to sign all requests with private String secretKey; - // Region to sign all requests with - private String region; - - private String userAgent = DEFAULT_USER_AGENT; - private OkHttpClient httpClient; - private boolean isAwsHost = false; - private boolean isAcceleratedHost = false; - private boolean isDualStackHost = false; - private boolean useVirtualStyle = false; + private MinioClient( + HttpUrl baseUrl, + String region, + boolean isAwsHost, + boolean isAcceleratedHost, + boolean isDualStackHost, + boolean useVirtualStyle, + String accessKey, + String secretKey, + OkHttpClient httpClient) { + this.baseUrl = baseUrl; + this.region = region; + this.isAwsHost = isAwsHost; + this.isAcceleratedHost = isAcceleratedHost; + this.isDualStackHost = isDualStackHost; + this.useVirtualStyle = useVirtualStyle; + this.accessKey = accessKey; + this.secretKey = secretKey; + this.httpClient = httpClient; + } + + /** Remove this constructor when all deprecated contructors are removed. */ + private MinioClient(MinioClient client) { + this.baseUrl = client.baseUrl; + this.region = client.region; + this.isAwsHost = client.isAwsHost; + this.isAcceleratedHost = client.isAcceleratedHost; + this.isDualStackHost = client.isDualStackHost; + this.useVirtualStyle = client.useVirtualStyle; + this.accessKey = client.accessKey; + this.secretKey = client.secretKey; + this.httpClient = client.httpClient; + } /** * Creates MinIO client object with given endpoint using anonymous access. @@ -254,21 +295,11 @@ public class MinioClient { * * ::1 * * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(URL url) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean - * secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(String endpoint) throws IllegalArgumentException { - this(endpoint, null, null, null, null, null, null); + this(builder().endpoint(endpoint).build()); } /** @@ -280,21 +311,11 @@ public MinioClient(String endpoint) throws IllegalArgumentException { * * @param url Endpoint as {@link URL} object. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean - * secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(URL url) throws InvalidEndpointException, InvalidPortException { - this(url.toString(), null, null, null, null, null, null); + this(builder().endpoint(url).build()); } /** @@ -306,22 +327,11 @@ public MinioClient(URL url) throws InvalidEndpointException, InvalidPortExceptio * * @param url Endpoint as {@link HttpUrl} object. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean - * secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(HttpUrl url) throws IllegalArgumentException { - this(url.toString(), null, null, null, null, null, null); + this(builder().endpoint(url).build()); } /** @@ -348,23 +358,12 @@ public MinioClient(HttpUrl url) throws IllegalArgumentException { * @param accessKey Access key (aka user ID) of your account in S3 service. * @param secretKey Secret Key (aka password) of your account in S3 service. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean - * secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(String endpoint, String accessKey, String secretKey) throws IllegalArgumentException { - this(endpoint, null, accessKey, secretKey, null, null, null); + this(builder().endpoint(endpoint).credentials(accessKey, secretKey).build()); } /** @@ -392,23 +391,12 @@ public MinioClient(String endpoint, String accessKey, String secretKey) * @param secretKey Secret Key (aka password) of your account in S3 service. * @param region Region name of buckets in S3 service. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean - * secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(String endpoint, String accessKey, String secretKey, String region) throws IllegalArgumentException { - this(endpoint, null, accessKey, secretKey, region, null, null); + this(builder().endpoint(endpoint).region(region).credentials(accessKey, secretKey).build()); } /** @@ -434,8 +422,9 @@ public MinioClient(String endpoint, String accessKey, String secretKey, String r * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String * region, Boolean secure, OkHttpClient httpClient) */ + @Deprecated public MinioClient(URL url, String accessKey, String secretKey) throws IllegalArgumentException { - this(url.toString(), null, accessKey, secretKey, null, null, null); + this(builder().endpoint(url).credentials(accessKey, secretKey).build()); } /** @@ -450,23 +439,12 @@ public MinioClient(URL url, String accessKey, String secretKey) throws IllegalAr * @param accessKey Access key (aka user ID) of your account in S3 service. * @param secretKey Secret Key (aka password) of your account in S3 service. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean - * secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(HttpUrl url, String accessKey, String secretKey) throws IllegalArgumentException { - this(url.toString(), null, accessKey, secretKey, null, null, null); + this(builder().endpoint(url).credentials(accessKey, secretKey).build()); } /** @@ -494,22 +472,16 @@ public MinioClient(HttpUrl url, String accessKey, String secretKey) * @param accessKey Access key (aka user ID) of your account in S3 service. * @param secretKey Secret Key (aka password) of your account in S3 service. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean - * secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(String endpoint, int port, String accessKey, String secretKey) throws IllegalArgumentException { - this(endpoint, port, accessKey, secretKey, null, null, null); + this( + builder() + .endpoint(endpoint, Integer.valueOf(port), null) + .credentials(accessKey, secretKey) + .build()); } /** @@ -538,22 +510,16 @@ public MinioClient(String endpoint, int port, String accessKey, String secretKey * @param secretKey Secret Key (aka password) of your account in S3 service. * @param secure Flag to indicate to use secure (TLS) connection to S3 service or not. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean - * secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) throws IllegalArgumentException { - this(endpoint, null, accessKey, secretKey, null, secure, null); + this( + builder() + .endpoint(endpoint, null, Boolean.valueOf(secure)) + .credentials(accessKey, secretKey) + .build()); } /** @@ -583,21 +549,16 @@ public MinioClient(String endpoint, String accessKey, String secretKey, boolean * @param secretKey Secret Key (aka password) of your account in S3 service. * @param secure Flag to indicate to use secure (TLS) connection to S3 service or not. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure) throws IllegalArgumentException { - this(endpoint, port, accessKey, secretKey, null, secure, null); + this( + builder() + .endpoint(endpoint, Integer.valueOf(port), Boolean.valueOf(secure)) + .credentials(accessKey, secretKey) + .build()); } /** @@ -628,20 +589,18 @@ public MinioClient(String endpoint, int port, String accessKey, String secretKey * @param region Region name of buckets in S3 service. * @param secure Flag to indicate to use secure (TLS) connection to S3 service or not. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String - * region, Boolean secure, OkHttpClient httpClient) + * @see #builder() */ + @Deprecated public MinioClient( String endpoint, int port, String accessKey, String secretKey, String region, boolean secure) throws IllegalArgumentException { - this(endpoint, port, accessKey, secretKey, region, secure, null); + this( + builder() + .endpoint(endpoint, Integer.valueOf(port), Boolean.valueOf(secure)) + .region(region) + .credentials(accessKey, secretKey) + .build()); } /** @@ -675,16 +634,9 @@ public MinioClient( * if it is non-null. * @param httpClient Customized HTTP client object. * @throws IllegalArgumentException Throws to indicate invalid argument passed. - * @see #MinioClient(String endpoint) - * @see #MinioClient(URL url) - * @see #MinioClient(String endpoint, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, String region) - * @see #MinioClient(URL url, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey) - * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) - * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, - * boolean secure) + * @see #builder() */ + @Deprecated public MinioClient( String endpoint, Integer port, @@ -694,228 +646,13 @@ public MinioClient( Boolean secure, OkHttpClient httpClient) throws IllegalArgumentException { - if (endpoint == null) { - throw new IllegalArgumentException("null endpoint"); - } - - if (region != null && region.equals("")) { - region = null; - } - - HttpUrl.Builder urlBuilder = null; - HttpUrl url = HttpUrl.parse(endpoint); - if (url != null) { - if (!"/".equals(url.encodedPath())) { - throw new IllegalArgumentException("no path allowed in endpoint '" + endpoint + "'"); - } - - urlBuilder = url.newBuilder(); - } else { - // endpoint may be a valid hostname, IPv4 or IPv6 address - if (!isValidEndpoint(endpoint)) { - throw new IllegalArgumentException("invalid host '" + endpoint + "'"); - } - - urlBuilder = new HttpUrl.Builder().host(endpoint); - - if (secure == null) { - secure = Boolean.TRUE; - } - } - - if (secure != null) { - if (secure) { - urlBuilder.scheme("https"); - } else { - urlBuilder.scheme("http"); - } - } - - if (port != null) { - if (port < 1 || port > 65535) { - throw new IllegalArgumentException("port " + port + " must be in range of 1 to 65535"); - } - - urlBuilder.port(port); - } - - url = urlBuilder.build(); - - String host = url.host(); - this.isAwsHost = isAwsEndpoint(host); - boolean isAwsChinaHost = false; - if (this.isAwsHost) { - isAwsChinaHost = host.endsWith(".cn"); - if (isAwsChinaHost) { - urlBuilder.host("amazonaws.com.cn"); - } else { - urlBuilder.host("amazonaws.com"); - } - url = urlBuilder.build(); - - this.isAcceleratedHost = isAwsAccelerateEndpoint(host); - this.isDualStackHost = isAwsDualStackEndpoint(host); - if (region == null) { - region = extractRegion(host); - } - this.useVirtualStyle = true; - } else { - this.useVirtualStyle = host.endsWith("aliyuncs.com"); - } - - if (isAwsChinaHost && region == null) { - throw new IllegalArgumentException( - "Region missing in Amazon S3 China endpoint '" + endpoint + "'"); - } - - this.region = region; - this.baseUrl = url; - this.accessKey = accessKey; - this.secretKey = secretKey; - - if (httpClient == null) { - this.httpClient = - new OkHttpClient() - .newBuilder() - .connectTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MINUTES) - .writeTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MINUTES) - .readTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MINUTES) - .protocols(Arrays.asList(Protocol.HTTP_1_1)) - .build(); - String filename = System.getenv("SSL_CERT_FILE"); - if (filename != null && !filename.equals("")) { - try { - this.httpClient = enableExternalCertificates(this.httpClient, filename); - } catch (GeneralSecurityException | IOException e) { - throw new RuntimeException(e); - } - } - } else { - this.httpClient = httpClient; - } - } - - private boolean isAwsEndpoint(String endpoint) { - return (endpoint.startsWith("s3.") || isAwsAccelerateEndpoint(endpoint)) - && (endpoint.endsWith(".amazonaws.com") || endpoint.endsWith(".amazonaws.com.cn")); - } - - private boolean isAwsAccelerateEndpoint(String endpoint) { - return endpoint.startsWith("s3-accelerate."); - } - - private boolean isAwsDualStackEndpoint(String endpoint) { - return endpoint.contains(".dualstack."); - } - - /** - * Extracts region from AWS endpoint if available. Region is placed at second token normal - * endpoints and third token for dualstack endpoints. - * - *

Region is marked in square brackets in below examples. - *

-   * https://s3.[us-east-2].amazonaws.com
-   * https://s3.dualstack.[ca-central-1].amazonaws.com
-   * https://s3.[cn-north-1].amazonaws.com.cn
-   * https://s3.dualstack.[cn-northwest-1].amazonaws.com.cn
-   */
-  private String extractRegion(String endpoint) {
-    String[] tokens = endpoint.split("\\.");
-    String token = tokens[1];
-
-    // If token is "dualstack", then region might be in next token.
-    if (token.equals("dualstack")) {
-      token = tokens[2];
-    }
-
-    // If token is equal to "amazonaws", region is not passed in the endpoint.
-    if (token.equals("amazonaws")) {
-      return null;
-    }
-
-    // Return token as region.
-    return token;
-  }
-
-  /**
-   * copied logic from
-   * https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/CustomTrust.java
-   */
-  private OkHttpClient enableExternalCertificates(OkHttpClient httpClient, String filename)
-      throws GeneralSecurityException, IOException {
-    Collection certificates = null;
-    FileInputStream fis = null;
-    try {
-      fis = new FileInputStream(filename);
-      certificates = CertificateFactory.getInstance("X.509").generateCertificates(fis);
-    } finally {
-      if (fis != null) {
-        fis.close();
-      }
-    }
-
-    if (certificates == null || certificates.isEmpty()) {
-      throw new IllegalArgumentException("expected non-empty set of trusted certificates");
-    }
-
-    char[] password = "password".toCharArray(); // Any password will work.
-
-    // Put the certificates a key store.
-    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
-    // By convention, 'null' creates an empty key store.
-    keyStore.load(null, password);
-
-    int index = 0;
-    for (Certificate certificate : certificates) {
-      String certificateAlias = Integer.toString(index++);
-      keyStore.setCertificateEntry(certificateAlias, certificate);
-    }
-
-    // Use it to build an X509 trust manager.
-    KeyManagerFactory keyManagerFactory =
-        KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
-    keyManagerFactory.init(keyStore, password);
-    TrustManagerFactory trustManagerFactory =
-        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
-    trustManagerFactory.init(keyStore);
-
-    final KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
-    final TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
-
-    SSLContext sslContext = SSLContext.getInstance("TLS");
-    sslContext.init(keyManagers, trustManagers, null);
-    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
-
-    return httpClient
-        .newBuilder()
-        .sslSocketFactory(sslSocketFactory, (X509TrustManager) trustManagers[0])
-        .build();
-  }
-
-  /** Returns true if given endpoint is valid else false. */
-  private boolean isValidEndpoint(String endpoint) {
-    if (InetAddressValidator.getInstance().isValid(endpoint)) {
-      return true;
-    }
-
-    // endpoint may be a hostname
-    // refer https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
-    // why checks are done like below
-    if (endpoint.length() < 1 || endpoint.length() > 253) {
-      return false;
-    }
-
-    for (String label : endpoint.split("\\.")) {
-      if (label.length() < 1 || label.length() > 63) {
-        return false;
-      }
-
-      if (!(label.matches("^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$"))) {
-        return false;
-      }
-    }
-
-    return true;
+    this(
+        builder()
+            .endpoint(endpoint, port, secure)
+            .region(region)
+            .credentials(accessKey, secretKey)
+            .httpClient(httpClient)
+            .build());
   }
 
   private void checkArgs(BaseArgs args) {
@@ -8174,4 +7911,302 @@ protected String uploadPartCopy(
       return result.etag();
     }
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    HttpUrl baseUrl;
+    String region;
+    String accessKey;
+    String secretKey;
+    OkHttpClient httpClient;
+    boolean isAwsHost;
+    boolean isAwsChinaHost;
+    boolean isAcceleratedHost;
+    boolean isDualStackHost;
+    boolean useVirtualStyle;
+    String regionInUrl;
+
+    public Builder() {}
+
+    private boolean isAwsEndpoint(String endpoint) {
+      return (endpoint.startsWith("s3.") || isAwsAccelerateEndpoint(endpoint))
+          && (endpoint.endsWith(".amazonaws.com") || endpoint.endsWith(".amazonaws.com.cn"));
+    }
+
+    private boolean isAwsAccelerateEndpoint(String endpoint) {
+      return endpoint.startsWith("s3-accelerate.");
+    }
+
+    private boolean isAwsDualStackEndpoint(String endpoint) {
+      return endpoint.contains(".dualstack.");
+    }
+
+    /**
+     * Extracts region from AWS endpoint if available. Region is placed at second token normal
+     * endpoints and third token for dualstack endpoints.
+     *
+     * 

Region is marked in square brackets in below examples. + *

+     * https://s3.[us-east-2].amazonaws.com
+     * https://s3.dualstack.[ca-central-1].amazonaws.com
+     * https://s3.[cn-north-1].amazonaws.com.cn
+     * https://s3.dualstack.[cn-northwest-1].amazonaws.com.cn
+     */
+    private String extractRegion(String endpoint) {
+      String[] tokens = endpoint.split("\\.");
+      String token = tokens[1];
+
+      // If token is "dualstack", then region might be in next token.
+      if (token.equals("dualstack")) {
+        token = tokens[2];
+      }
+
+      // If token is equal to "amazonaws", region is not passed in the endpoint.
+      if (token.equals("amazonaws")) {
+        return null;
+      }
+
+      // Return token as region.
+      return token;
+    }
+
+    private void setBaseUrl(HttpUrl url) {
+      String host = url.host();
+      this.isAwsHost = isAwsEndpoint(host);
+      this.isAwsChinaHost = false;
+      if (this.isAwsHost) {
+        this.isAwsChinaHost = host.endsWith(".cn");
+        url =
+            url.newBuilder()
+                .host(this.isAwsChinaHost ? "amazonaws.com.cn" : "amazonaws.com")
+                .build();
+        this.isAcceleratedHost = isAwsAccelerateEndpoint(host);
+        this.isDualStackHost = isAwsDualStackEndpoint(host);
+        this.regionInUrl = extractRegion(host);
+        this.useVirtualStyle = true;
+      } else {
+        this.useVirtualStyle = host.endsWith("aliyuncs.com");
+      }
+
+      this.baseUrl = url;
+    }
+
+    /**
+     * copied logic from
+     * https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/CustomTrust.java
+     */
+    private OkHttpClient enableExternalCertificates(OkHttpClient httpClient, String filename)
+        throws GeneralSecurityException, IOException {
+      Collection certificates = null;
+      try (FileInputStream fis = new FileInputStream(filename)) {
+        certificates = CertificateFactory.getInstance("X.509").generateCertificates(fis);
+      }
+
+      if (certificates == null || certificates.isEmpty()) {
+        throw new IllegalArgumentException("expected non-empty set of trusted certificates");
+      }
+
+      char[] password = "password".toCharArray(); // Any password will work.
+
+      // Put the certificates a key store.
+      KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+      // By convention, 'null' creates an empty key store.
+      keyStore.load(null, password);
+
+      int index = 0;
+      for (Certificate certificate : certificates) {
+        String certificateAlias = Integer.toString(index++);
+        keyStore.setCertificateEntry(certificateAlias, certificate);
+      }
+
+      // Use it to build an X509 trust manager.
+      KeyManagerFactory keyManagerFactory =
+          KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+      keyManagerFactory.init(keyStore, password);
+      TrustManagerFactory trustManagerFactory =
+          TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+      trustManagerFactory.init(keyStore);
+
+      final KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
+      final TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
+
+      SSLContext sslContext = SSLContext.getInstance("TLS");
+      sslContext.init(keyManagers, trustManagers, null);
+      SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
+
+      return httpClient
+          .newBuilder()
+          .sslSocketFactory(sslSocketFactory, (X509TrustManager) trustManagers[0])
+          .build();
+    }
+
+    protected void validateNotNull(Object arg, String argName) {
+      if (arg == null) {
+        throw new IllegalArgumentException(argName + " must not be null.");
+      }
+    }
+
+    protected void validateNotEmptyString(String arg, String argName) {
+      validateNotNull(arg, argName);
+      if (arg.isEmpty()) {
+        throw new IllegalArgumentException(argName + " must be a non-empty string.");
+      }
+    }
+
+    protected void validateNullOrNotEmptyString(String arg, String argName) {
+      if (arg != null && arg.isEmpty()) {
+        throw new IllegalArgumentException(argName + " must be a non-empty string.");
+      }
+    }
+
+    private void validateUrl(HttpUrl url) {
+      if (!url.encodedPath().equals("/")) {
+        throw new IllegalArgumentException("no path allowed in endpoint " + url);
+      }
+    }
+
+    private void validateHostnameOrIPAddress(String endpoint) {
+      // Check endpoint is IPv4 or IPv6.
+      if (InetAddressValidator.getInstance().isValid(endpoint)) {
+        return;
+      }
+
+      // Check endpoint is a hostname.
+
+      // Refer https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
+      // why checks are done like below
+      if (endpoint.length() < 1 || endpoint.length() > 253) {
+        throw new IllegalArgumentException("invalid hostname");
+      }
+
+      for (String label : endpoint.split("\\.")) {
+        if (label.length() < 1 || label.length() > 63) {
+          throw new IllegalArgumentException("invalid hostname");
+        }
+
+        if (!(label.matches("^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$"))) {
+          throw new IllegalArgumentException("invalid hostname");
+        }
+      }
+    }
+
+    private HttpUrl getBaseUrl(String endpoint) {
+      validateNotEmptyString(endpoint, "endpoint");
+      HttpUrl url = HttpUrl.parse(endpoint);
+      if (url == null) {
+        validateHostnameOrIPAddress(endpoint);
+        url = new HttpUrl.Builder().scheme("https").host(endpoint).build();
+      } else {
+        validateUrl(url);
+      }
+
+      return url;
+    }
+
+    public Builder endpoint(String endpoint) {
+      setBaseUrl(getBaseUrl(endpoint));
+      return this;
+    }
+
+    public Builder endpoint(String endpoint, int port, boolean secure) {
+      HttpUrl url = getBaseUrl(endpoint);
+      if (port < 1 || port > 65535) {
+        throw new IllegalArgumentException("port must be in range of 1 to 65535");
+      }
+      url = url.newBuilder().port(port).scheme(secure ? "https" : "http").build();
+
+      setBaseUrl(url);
+      return this;
+    }
+
+    /** Remove this method when all deprecated MinioClient constructors are removed. */
+    private Builder endpoint(String endpoint, Integer port, Boolean secure) {
+      HttpUrl url = getBaseUrl(endpoint);
+      if (port != null) {
+        if (port < 1 || port > 65535) {
+          throw new IllegalArgumentException("port must be in range of 1 to 65535");
+        }
+
+        url = url.newBuilder().port(port).build();
+      }
+
+      if (secure != null) {
+        url = url.newBuilder().scheme(secure ? "https" : "http").build();
+      }
+
+      setBaseUrl(url);
+      return this;
+    }
+
+    public Builder endpoint(URL url) {
+      validateNotNull(url, "url");
+      return endpoint(HttpUrl.get(url));
+    }
+
+    public Builder endpoint(HttpUrl url) {
+      validateNotNull(url, "url");
+      validateUrl(url);
+      setBaseUrl(url);
+      return this;
+    }
+
+    public Builder region(String region) {
+      validateNullOrNotEmptyString(region, "region");
+      this.region = region;
+      this.regionInUrl = region;
+      return this;
+    }
+
+    public Builder credentials(String accessKey, String secretKey) {
+      this.accessKey = accessKey;
+      this.secretKey = secretKey;
+      return this;
+    }
+
+    public Builder httpClient(OkHttpClient httpClient) {
+      validateNotNull(httpClient, "http client");
+      this.httpClient = httpClient;
+      return this;
+    }
+
+    public MinioClient build() {
+      validateNotNull(baseUrl, "endpoint");
+      if (isAwsChinaHost && regionInUrl == null && region == null) {
+        throw new IllegalArgumentException("Region missing in Amazon S3 China endpoint " + baseUrl);
+      }
+
+      if (httpClient == null) {
+        this.httpClient =
+            new OkHttpClient()
+                .newBuilder()
+                .connectTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MINUTES)
+                .writeTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MINUTES)
+                .readTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MINUTES)
+                .protocols(Arrays.asList(Protocol.HTTP_1_1))
+                .build();
+        String filename = System.getenv("SSL_CERT_FILE");
+        if (filename != null && !filename.isEmpty()) {
+          try {
+            this.httpClient = enableExternalCertificates(this.httpClient, filename);
+          } catch (GeneralSecurityException | IOException e) {
+            throw new RuntimeException(e);
+          }
+        }
+      }
+
+      return new MinioClient(
+          baseUrl,
+          (region != null) ? region : regionInUrl,
+          isAwsHost,
+          isAcceleratedHost,
+          isDualStackHost,
+          useVirtualStyle,
+          accessKey,
+          secretKey,
+          httpClient);
+    }
+  }
 }
diff --git a/api/src/test/java/io/minio/MinioClientTest.java b/api/src/test/java/io/minio/MinioClientTest.java
index 2228d5f4a..462afd6f9 100644
--- a/api/src/test/java/io/minio/MinioClientTest.java
+++ b/api/src/test/java/io/minio/MinioClientTest.java
@@ -42,55 +42,55 @@ public class MinioClientTest {
 
   @Test(expected = IllegalArgumentException.class)
   public void testEndpoint1() throws MinioException {
-    new MinioClient((String) null);
+    MinioClient.builder().endpoint((String) null).build();
     Assert.fail("exception should be thrown");
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testEndpoint2() throws MinioException {
-    new MinioClient("http://play.min.io/mybucket");
+    MinioClient.builder().endpoint("http://play.min.io/mybucket").build();
     Assert.fail("exception should be thrown");
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testEndpoint3() throws MinioException {
-    new MinioClient("minio-.example.com");
+    MinioClient.builder().endpoint("minio-.example.com").build();
     Assert.fail("exception should be thrown");
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testEndpoint4() throws MinioException {
-    new MinioClient("-minio.example.com");
+    MinioClient.builder().endpoint("-minio.example.com").build();
     Assert.fail("exception should be thrown");
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testEndpoint5() throws MinioException {
-    new MinioClient("minio..example.com");
+    MinioClient.builder().endpoint("minio..example.com").build();
     Assert.fail("exception should be thrown");
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testEndpoint6() throws MinioException {
-    new MinioClient("minio._.com");
+    MinioClient.builder().endpoint("minio._.com").build();
     Assert.fail("exception should be thrown");
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testEndpoint7() throws MinioException {
-    new MinioClient("https://s3.amazonaws.com.cn");
+    MinioClient.builder().endpoint("https://s3.amazonaws.com.cn").build();
     Assert.fail("exception should be thrown");
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testPort1() throws MinioException {
-    new MinioClient("play.min.io", 0, "", "", false);
+    MinioClient.builder().endpoint("play.min.io", 0, false).build();
     Assert.fail("exception should be thrown");
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testPort2() throws MinioException {
-    new MinioClient("play.min.io", 70000, "", "", false);
+    MinioClient.builder().endpoint("play.min.io", 70000, false).build();
     Assert.fail("exception should be thrown");
   }
 
@@ -101,52 +101,66 @@ public void testAwsEndpoints()
     String url = null;
 
     // virtual-style checks.
-    client = new MinioClient("https://s3.amazonaws.com");
+    client = MinioClient.builder().endpoint("https://s3.amazonaws.com").build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://mybucket.s3.us-east-1.amazonaws.com/myobject", url);
 
-    client = new MinioClient("https://s3.us-east-2.amazonaws.com", "myaccesskey", "mysecretkey");
+    client =
+        MinioClient.builder()
+            .endpoint("https://s3.us-east-2.amazonaws.com")
+            .credentials("myaccesskey", "mysecretkey")
+            .build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://mybucket.s3.us-east-2.amazonaws.com/myobject", url);
 
-    client = new MinioClient("https://s3-accelerate.amazonaws.com");
+    client = MinioClient.builder().endpoint("https://s3-accelerate.amazonaws.com").build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://mybucket.s3-accelerate.amazonaws.com/myobject", url);
 
     client =
-        new MinioClient(
-            "https://s3.dualstack.ca-central-1.amazonaws.com", "myaccesskey", "mysecretkey");
+        MinioClient.builder()
+            .endpoint("https://s3.dualstack.ca-central-1.amazonaws.com")
+            .credentials("myaccesskey", "mysecretkey")
+            .build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://mybucket.s3.dualstack.ca-central-1.amazonaws.com/myobject", url);
 
-    client = new MinioClient("https://s3-accelerate.dualstack.amazonaws.com");
+    client =
+        MinioClient.builder().endpoint("https://s3-accelerate.dualstack.amazonaws.com").build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://mybucket.s3-accelerate.dualstack.amazonaws.com/myobject", url);
 
     // path-style checks.
-    client = new MinioClient("https://s3.amazonaws.com");
+    client = MinioClient.builder().endpoint("https://s3.amazonaws.com").build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://s3.us-east-1.amazonaws.com/mybucket/myobject", url);
 
-    client = new MinioClient("https://s3.us-east-2.amazonaws.com", "myaccesskey", "mysecretkey");
+    client =
+        MinioClient.builder()
+            .endpoint("https://s3.us-east-2.amazonaws.com")
+            .credentials("myaccesskey", "mysecretkey")
+            .build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://s3.us-east-2.amazonaws.com/mybucket/myobject", url);
 
-    client = new MinioClient("https://s3-accelerate.amazonaws.com");
+    client = MinioClient.builder().endpoint("https://s3-accelerate.amazonaws.com").build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://s3-accelerate.amazonaws.com/mybucket/myobject", url);
 
     client =
-        new MinioClient(
-            "https://s3.dualstack.ca-central-1.amazonaws.com", "myaccesskey", "mysecretkey");
+        MinioClient.builder()
+            .endpoint("https://s3.dualstack.ca-central-1.amazonaws.com")
+            .credentials("myaccesskey", "mysecretkey")
+            .build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://s3.dualstack.ca-central-1.amazonaws.com/mybucket/myobject", url);
 
-    client = new MinioClient("https://s3-accelerate.dualstack.amazonaws.com");
+    client =
+        MinioClient.builder().endpoint("https://s3-accelerate.dualstack.amazonaws.com").build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://s3-accelerate.dualstack.amazonaws.com/mybucket/myobject", url);
@@ -154,66 +168,72 @@ public void testAwsEndpoints()
     // China region.
     // virtual-style checks.
     client =
-        new MinioClient("https://s3.cn-north-1.amazonaws.com.cn", "myaccesskey", "mysecretkey");
+        MinioClient.builder()
+            .endpoint("https://s3.cn-north-1.amazonaws.com.cn")
+            .credentials("myaccesskey", "mysecretkey")
+            .build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://mybucket.s3.cn-north-1.amazonaws.com.cn/myobject", url);
 
     client =
-        new MinioClient(
-            "https://s3-accelerate.amazonaws.com.cn", null, null, null, "cn-north-1", null, null);
+        MinioClient.builder()
+            .endpoint("https://s3-accelerate.amazonaws.com.cn")
+            .region("cn-north-1")
+            .build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://mybucket.s3-accelerate.amazonaws.com.cn/myobject", url);
 
     client =
-        new MinioClient(
-            "https://s3.dualstack.cn-northwest-1.amazonaws.com.cn", "myaccesskey", "mysecretkey");
+        MinioClient.builder()
+            .endpoint("https://s3.dualstack.cn-northwest-1.amazonaws.com.cn")
+            .credentials("myaccesskey", "mysecretkey")
+            .build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals(
         "https://mybucket.s3.dualstack.cn-northwest-1.amazonaws.com.cn/myobject", url);
 
     client =
-        new MinioClient(
-            "https://s3-accelerate.dualstack.amazonaws.com.cn",
-            null,
-            null,
-            null,
-            "cn-north-1",
-            null,
-            null);
+        MinioClient.builder()
+            .endpoint("https://s3-accelerate.dualstack.amazonaws.com.cn")
+            .region("cn-north-1")
+            .build();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://mybucket.s3-accelerate.dualstack.amazonaws.com.cn/myobject", url);
 
     // path-style checks.
     client =
-        new MinioClient("https://s3.cn-north-1.amazonaws.com.cn", "myaccesskey", "mysecretkey");
+        MinioClient.builder()
+            .endpoint("https://s3.cn-north-1.amazonaws.com.cn")
+            .credentials("myaccesskey", "mysecretkey")
+            .build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://s3.cn-north-1.amazonaws.com.cn/mybucket/myobject", url);
 
     client =
-        new MinioClient(
-            "https://s3-accelerate.amazonaws.com.cn", null, null, null, "cn-north-1", null, null);
+        MinioClient.builder()
+            .endpoint("https://s3-accelerate.amazonaws.com.cn")
+            .region("cn-north-1")
+            .build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://s3-accelerate.amazonaws.com.cn/mybucket/myobject", url);
 
     client =
-        new MinioClient(
-            "https://s3.dualstack.cn-northwest-1.amazonaws.com.cn", "myaccesskey", "mysecretkey");
+        MinioClient.builder()
+            .endpoint("https://s3.dualstack.cn-northwest-1.amazonaws.com.cn")
+            .credentials("myaccesskey", "mysecretkey")
+            .build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals(
         "https://s3.dualstack.cn-northwest-1.amazonaws.com.cn/mybucket/myobject", url);
 
     client =
-        new MinioClient(
-            "https://s3-accelerate.dualstack.amazonaws.com.cn",
-            null,
-            null,
-            null,
-            "cn-north-1",
-            null,
-            null);
+        MinioClient.builder()
+            .endpoint("https://s3-accelerate.dualstack.amazonaws.com.cn")
+            .region("cn-north-1")
+            .build();
     client.disableVirtualStyleEndpoint();
     url = client.getObjectUrl("mybucket", "myobject");
     Assert.assertEquals("https://s3-accelerate.dualstack.amazonaws.com.cn/mybucket/myobject", url);
@@ -222,7 +242,7 @@ public void testAwsEndpoints()
   @Test(expected = IllegalArgumentException.class)
   public void testBucketName1()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl(null, "myobject");
     Assert.fail("exception should be thrown");
   }
@@ -230,7 +250,7 @@ public void testBucketName1()
   @Test(expected = InvalidBucketNameException.class)
   public void testBucketName2()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("", "myobject");
     Assert.fail("exception should be thrown");
   }
@@ -238,7 +258,7 @@ public void testBucketName2()
   @Test(expected = InvalidBucketNameException.class)
   public void testBucketName3()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("a", "myobject");
     Assert.fail("exception should be thrown");
   }
@@ -246,7 +266,7 @@ public void testBucketName3()
   @Test(expected = InvalidBucketNameException.class)
   public void testBucketName4()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl(
         "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789", "myobject");
     Assert.fail("exception should be thrown");
@@ -255,7 +275,7 @@ public void testBucketName4()
   @Test(expected = InvalidBucketNameException.class)
   public void testBucketName5()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("a..b", "myobject");
     Assert.fail("exception should be thrown");
   }
@@ -263,7 +283,7 @@ public void testBucketName5()
   @Test(expected = InvalidBucketNameException.class)
   public void testBucketName6()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("a_b", "myobject");
     Assert.fail("exception should be thrown");
   }
@@ -271,7 +291,7 @@ public void testBucketName6()
   @Test(expected = InvalidBucketNameException.class)
   public void testBucketName7()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("a#b", "myobject");
     Assert.fail("exception should be thrown");
   }
@@ -279,7 +299,7 @@ public void testBucketName7()
   @Test(expected = IllegalArgumentException.class)
   public void testObjectName1()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("abc", null);
     Assert.fail("exception should be thrown");
   }
@@ -287,7 +307,7 @@ public void testObjectName1()
   @Test(expected = IllegalArgumentException.class)
   public void testObjectName2()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("abc", "");
     Assert.fail("exception should be thrown");
   }
@@ -295,7 +315,7 @@ public void testObjectName2()
   @Test(expected = IllegalArgumentException.class)
   public void testObjectName3()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("abc", "a/./b");
     Assert.fail("exception should be thrown");
   }
@@ -303,7 +323,7 @@ public void testObjectName3()
   @Test(expected = IllegalArgumentException.class)
   public void testObjectName4()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObjectUrl("abc", "a/../b");
     Assert.fail("exception should be thrown");
   }
@@ -313,7 +333,7 @@ public void testReadSse1()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
     KeyGenerator keyGen = KeyGenerator.getInstance("AES");
     keyGen.init(256);
-    MinioClient client = new MinioClient("http://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("http://play.min.io:9000").build();
     client.statObject(
         StatObjectArgs.builder()
             .bucket("mybucket")
@@ -326,7 +346,7 @@ public void testReadSse1()
   @Test(expected = IllegalArgumentException.class)
   public void testWriteSse1()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("http://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("http://play.min.io:9000").build();
     KeyGenerator keyGen = KeyGenerator.getInstance("AES");
     keyGen.init(256);
     client.putObject(
@@ -340,7 +360,7 @@ public void testWriteSse1()
   @Test(expected = IllegalArgumentException.class)
   public void testWriteSse2()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("http://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("http://play.min.io:9000").build();
     Map myContext = new HashMap<>();
     myContext.put("key1", "value1");
     client.putObject(
@@ -362,7 +382,7 @@ public void testInvalidResponse1()
     server.enqueue(response);
     server.start();
 
-    MinioClient client = new MinioClient(server.url(""));
+    MinioClient client = MinioClient.builder().endpoint(server.url("")).build();
     client.listBuckets();
     Assert.fail("exception should be thrown");
   }
@@ -379,7 +399,7 @@ public void testInvalidResponse2()
     server.enqueue(response);
     server.start();
 
-    MinioClient client = new MinioClient(server.url(""));
+    MinioClient client = MinioClient.builder().endpoint(server.url("")).build();
     client.listBuckets();
     Assert.fail("exception should be thrown");
   }
@@ -396,7 +416,7 @@ public void testInvalidResponse3()
     server.enqueue(response);
     server.start();
 
-    MinioClient client = new MinioClient(server.url(""));
+    MinioClient client = MinioClient.builder().endpoint(server.url("")).build();
     client.listBuckets();
     Assert.fail("exception should be thrown");
   }
@@ -413,7 +433,7 @@ public void testInvalidResponse4()
     server.enqueue(response);
     server.start();
 
-    MinioClient client = new MinioClient(server.url(""));
+    MinioClient client = MinioClient.builder().endpoint(server.url("")).build();
     client.listBuckets();
     Assert.fail("exception should be thrown");
   }
@@ -421,7 +441,12 @@ public void testInvalidResponse4()
   @Test(expected = RegionConflictException.class)
   public void testMakeBucketRegionConflicts()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("http://play.min.io:9000", "foo", "bar", "us-east-1");
+    MinioClient client =
+        MinioClient.builder()
+            .endpoint("http://play.min.io:9000")
+            .credentials("foo", "bar")
+            .region("us-east-1")
+            .build();
     client.makeBucket(MakeBucketArgs.builder().bucket("mybucket").region("us-west-2").build());
     Assert.fail("exception should be thrown");
   }
@@ -429,7 +454,7 @@ public void testMakeBucketRegionConflicts()
   @Test(expected = IllegalArgumentException.class)
   public void testInvalidExpiresRange1()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getPresignedObjectUrl(
         GetPresignedObjectUrlArgs.builder()
             .method(Method.GET)
@@ -442,7 +467,7 @@ public void testInvalidExpiresRange1()
   @Test(expected = IllegalArgumentException.class)
   public void testInvalidExpiresRange2()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getPresignedObjectUrl(
         GetPresignedObjectUrlArgs.builder()
             .method(Method.GET)
@@ -455,7 +480,7 @@ public void testInvalidExpiresRange2()
   @Test(expected = IllegalArgumentException.class)
   public void testGetObjectNegativeOffset()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObject(
         GetObjectArgs.builder()
             .bucket("mybucket")
@@ -469,7 +494,7 @@ public void testGetObjectNegativeOffset()
   @Test(expected = IllegalArgumentException.class)
   public void testGetObjectNegativeLength()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObject(
         GetObjectArgs.builder()
             .bucket("mybucket")
@@ -483,7 +508,7 @@ public void testGetObjectNegativeLength()
   @Test(expected = IllegalArgumentException.class)
   public void testGetObjectZeroLength()
       throws NoSuchAlgorithmException, IOException, InvalidKeyException, MinioException {
-    MinioClient client = new MinioClient("https://play.min.io:9000");
+    MinioClient client = MinioClient.builder().endpoint("https://play.min.io:9000").build();
     client.getObject(
         GetObjectArgs.builder()
             .bucket("mybucket")
diff --git a/build.gradle b/build.gradle
index 084941201..dee444ddc 100644
--- a/build.gradle
+++ b/build.gradle
@@ -101,6 +101,7 @@ subprojects {
             importOrder 'edu', 'com', 'io', 'java', 'javax', 'org', ''
             removeUnusedImports()
             googleJavaFormat()
+            paddedCell()
         }
         groovyGradle {
             target '*.gradle'
diff --git a/docs/API.md b/docs/API.md
index a61d0ffae..9f83e5ec5 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -1,19 +1,25 @@
 # Java Client API Reference [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io)
 
-## Initialize MinIO Client object.
+## Create MinIO Client.
 
 ## MinIO
 
 ```java
-MinioClient minioClient = new MinioClient("https://play.min.io",
-    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+MinioClient minioClient =
+    MinioClient.builder()
+        .endpoint("https://play.min.io")
+        .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+        .build();
 ```
 
 ## AWS S3
 
 ```java
-MinioClient s3Client = new MinioClient("https://s3.amazonaws.com",
-    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+MinioClient minioClient =
+    MinioClient.builder()
+        .endpoint("https://s3.amazonaws.com")
+        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
+        .build();
 ```
 
 | Bucket operations                                       | Object operations                                       |
@@ -47,144 +53,82 @@ MinioClient s3Client = new MinioClient("https://s3.amazonaws.com",
 | [`setBucketTags`](#setBucketTags)                       |                                                         |
 | [`setDefaultRetention`](#setDefaultRetention)           |                                                         |
 
-## 1. Constructors
-|                                                                                                                          |
-|--------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(String endpoint) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-1]_ |
-| Creates MinIO client object with given endpoint using anonymous access.                                                  |
-
-|                                                                                                                  |
-|------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(URL url) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-2]_ |
-| Creates MinIO client object with given url using anonymous access.                                               |
-
-|                                                                                                                               |
-|-------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(okhttp3.HttpUrl url) throws  InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-3]_ |
-| Creates MinIO client object with given HttpUrl object using anonymous access.                                                 |
-
-|                                                                                                                                                              |
-|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(String endpoint, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-4]_ |
-| Creates MinIO client object with given endpoint, access key and secret key.                                                                                  |
-
-|                                                                                                                                                                         |
-|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(String endpoint, int port,  String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-5]_ |
-| Creates MinIO client object with given endpoint, port, access key and secret key using secure (HTTPS) connection.                                                       |
-
-|                                                                                                                                                                              |
-|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-6]_ |
-| Creates MinIO client object with given endpoint, access key and secret key using secure (HTTPS) connection.                                                                  |
-
-|                                                                                                                                                                                        |
-|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-7]_ |
-| Creates MinIO client object using given endpoint, port, access key, secret key and secure option.                                                                                      |
-
-|                                                                                                                                                                  |
-|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(okhttp3.HttpUrl url, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-8]_ |
-| Creates MinIO client object with given URL object, access key and secret key.                                                                                    |
-
-|                                                                                                                                                      |
-|------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(URL url, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-9]_ |
-| Creates MinIO client object with given URL object, access key and secret key.                                                                        |
-
-|                                                                                                                                                                              |
-|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(String endpoint, String accessKey, String secretKey, String region) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-10]_ |
-| Creates MinIO client object with given URL object, access key and secret key.                                                                                                |
-
-|                                                                                                                                                                                                        |
-|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, boolean secure) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-11]_ |
-| Creates MinIO client object using given endpoint, port, access key, secret key, region and secure option.                                                                                              |
-
-|                                                                                                                                                                                                                                             |
-|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `public MinioClient(String endpoint, Integer port, String accessKey, String secretKey, String region, Boolean secure, okhttp3.OkHttpClient httpClient) throws InvalidEndpointException, InvalidPortException` _[[Javadoc]][constructor-12]_ |
-| Creates MinIO client object using given endpoint, port, access key, secret key, region and secure option.                                                                                                                                   |
+## 1. MinIO Client Builder
 
-__Parameters__
-
-| Parameter    | Type                   | Description                                                                        |
-|--------------|------------------------|------------------------------------------------------------------------------------|
-| `endpoint`   | _String_               | Endpoint is an URL, domain name, IPv4 address or IPv6 address of S3 service.       |
-|              |                        | Examples:                                                                          |
-|              |                        | https://s3.amazonaws.com                                                           |
-|              |                        | https://play.min.io                                                                |
-|              |                        | https://play.min.io:9000                                                           |
-|              |                        | localhost                                                                          |
-|              |                        | play.min.io                                                                        |
-| `url`        | _URL_                  | Endpoint as URL object.                                                            |
-| `url`        | _okhttp3.HttpUrl_      | Endpoint as okhttp3.HttpUrl object.                                                |
-| `port`       | _int_                  | (Optional) TCP/IP port number. 80 and 443 are used as defaults for HTTP and HTTPS. |
-| `accessKey`  | _String_               | (Optional) Access key (aka user ID) of your account in S3 service.                 |
-| `secretKey`  | _String_               | (Optional) Secret Key (aka password) of your account in S3 service.                |
-| `secure`     | _boolean_              | (Optional) Flag to indicate to use secure connection to S3 service or not.         |
-| `region`     | _String_               | (Optional) Region name of buckets in S3 service.                                   |
-| `httpClient` | _okhttp3.OkHttpClient_ | (Optional) Custom HTTP client object.                                              |
+MinIO Client Builder is used to create MinIO client. Builder has below methods to accept arguments.
+| Method          | Description                                                                                                                                |
+|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------|
+| `endpoint()`    | Accepts endpoint as a String, URL or okhttp3.HttpUrl object and optionally accepts port number and flag to enable secure (TLS) connection. |
+|                 | Endpoint as a string can be formatted like below:                                                                                          |
+|                 | `https://s3.amazonaws.com`                                                                                                                 |
+|                 | `https://play.min.io`                                                                                                                      |
+|                 | `https://play.min.io:9000`                                                                                                                 |
+|                 | `localhost`                                                                                                                                |
+|                 | `play.min.io`                                                                                                                              |
+| `credentials()` | Accepts access key (aka user ID) and secret key (aka password) of an account in S3 service.                                                |
+| `region()`      | Accepts region name of S3 service. If specified, all operations use this region otherwise region is probed per bucket.                     |
+| `httpClient()`  | Custom HTTP client to override default.                                                                                                    |
 
-__Example__
+__Examples__
 
 ### MinIO
 
 ```java
 // 1. Create client to S3 service 'play.min.io' at port 443 with TLS security
 // for anonymous access.
-MinioClient minioClient = new MinioClient("https://play.min.io");
+MinioClient minioClient = MinioClient.builder().endpoint("https://play.min.io").build();
 
 // 2. Create client to S3 service 'play.min.io' at port 443 with TLS security
 // using URL object for anonymous access.
-MinioClient minioClient = new MinioClient(new URL("https://play.min.io"));
+MinioClient minioClient = MinioClient.builder().endpoint(new URL("https://play.min.io")).build();
 
 // 3. Create client to S3 service 'play.min.io' at port 9000 with TLS security
 // using okhttp3.HttpUrl object for anonymous access.
-MinioClient minioClient = new MinioClient(new HttpUrl.parse("https://play.min.io:9000"));
+MinioClient minioClient =
+    MinioClient.builder().endpoint(HttpUrl.parse("https://play.min.io:9000")).build();
 
 // 4. Create client to S3 service 'play.min.io' at port 443 with TLS security
 // for authenticated access.
-MinioClient minioClient = new MinioClient("https://play.min.io",
-    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+MinioClient minioClient =
+    MinioClient.builder()
+	    .endpoint("https://play.min.io")
+		.credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+		.build();
 
 // 5. Create client to S3 service 'play.min.io' at port 9000 with non-TLS security
 // for authenticated access.
-MinioClient minioClient = new MinioClient("play.min.io", 9000,
-    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+MinioClient minioClient =
+    MinioClient.builder()
+	    .endpoint("play.min.io", 9000, false)
+	    .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+		.build();
 
 // 6. Create client to S3 service 'play.min.io' at port 9000 with TLS security
 // for authenticated access.
-MinioClient minioClient = new MinioClient("play.min.io", 9000,
-    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", true);
+MinioClient minioClient =
+    MinioClient.builder()
+	    .endpoint("play.min.io", 9000, true)
+		.credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+		.build();
 
 // 7. Create client to S3 service 'play.min.io' at port 443 with TLS security
-// using URL object for authenticated access.
-MinioClient minioClient = new MinioClient(new URL("https://play.min.io"),
-     "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
-
-// 8. Create client to S3 service 'play.min.io' at port 443 with TLS security
-// using okhttp3.HttpUrl object for authenticated access.
-MinioClient minioClient = new MinioClient(HttpUrl.parse("https://play.min.io"),
-    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
-
-// 9. Create client to S3 service 'play.min.io' at port 443 with TLS security
 // and region 'us-west-1' for authenticated access.
-MinioClient minioClient = new MinioClient("https://play.min.io",
-    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", "us-west-1");
-
-// 10. Create client to S3 service 'play.min.io' at port 9000 with TLS security
-// and region 'eu-east-1' for authenticated access.
-MinioClient minioClient = new MinioClient("play.min.io", 9000,
-    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", "eu-east-1", true);
-
-// 11. Create client to S3 service 'play.min.io' at port 9000 with TLS security,
+MinioClient minioClient =
+    MinioClient.builder()
+	    .endpoint(new URL("https://play.min.io"))
+		.credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+		.region("us-west-1")
+		.build();
+
+// 8. Create client to S3 service 'play.min.io' at port 9000 with TLS security,
 // region 'eu-east-1' and custom HTTP client for authenticated access.
-MinioClient minioClient = new MinioClient("play.min.io", 9000,
-    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", "eu-east-1",
-    true, customHttpClient);
+MinioClient minioClient =
+    MinioClient.builder()
+	    .endpoint("https://play.min.io:9000")
+		.credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+		.region("eu-east-1")
+		.httpClient(customHttpClient)
+		.build();
 ```
 
 ### AWS S3
@@ -192,58 +136,76 @@ MinioClient minioClient = new MinioClient("play.min.io", 9000,
 ```java
 // 1. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security
 // for anonymous access.
-MinioClient s3Client = new MinioClient("https://s3.amazonaws.com");
+MinioClient s3Client = MinioClient.builder().endpoint("https://s3.amazonaws.com").build();
 
 // 2. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security
 // using URL object for anonymous access.
-MinioClient minioClient = new MinioClient(new URL("https://s3.amazonaws.com"));
+MinioClient s3Client = MinioClient.builder().endpoint(new URL("https://s3.amazonaws.com")).build();
 
 // 3. Create client to S3 service 's3.amazonaws.com' at port 9000 with TLS security
 // using okhttp3.HttpUrl object for anonymous access.
-MinioClient s3Client = new MinioClient(new HttpUrl.parse("https://s3.amazonaws.com"));
+MinioClient s3Client =
+    MinioClient.builder().endpoint(HttpUrl.parse("https://s3.amazonaws.com")).build();
 
 // 4. Create client to S3 service 's3.amazonaws.com' at port 80 with TLS security
 // for authenticated access.
-MinioClient s3Client = new MinioClient("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+MinioClient s3Client =
+    MinioClient.builder()
+	    .endpoint("s3.amazonaws.com")
+		.credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
+		.build();
 
 // 5. Create client to S3 service 's3.amazonaws.com' at port 443 with non-TLS security
 // for authenticated access.
-MinioClient s3Client = new MinioClient("s3.amazonaws.com", 433, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+MinioClient s3Client =
+    MinioClient.builder()
+        .endpoint("s3.amazonaws.com", 433, false)
+		.credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
+		.build();
 
 // 6. Create client to S3 service 's3.amazonaws.com' at port 80 with non-TLS security
 // for authenticated access.
-MinioClient s3Client = new MinioClient("s3.amazonaws.com",
-    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", false);
+MinioClient s3Client =
+    MinioClient.builder()
+	    .endpoint("s3.amazonaws.com", 80, false)
+        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
+		.build();
 
 // 7. Create client to S3 service 's3.amazonaws.com' at port 80 with TLS security
 // for authenticated access.
-MinioClient s3Client = new MinioClient("s3.amazonaws.com", 80,
-    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true);
+MinioClient s3Client =
+    MinioClient.builder()
+	    .endpoint("s3.amazonaws.com", 80, true)
+        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
+		.build();
 
 // 8. Create client to S3 service 's3.amazonaws.com' at port 80 with non-TLS security
-// using URL object for authenticated access.
-MinioClient s3Client = new MinioClient(new URL("s3.amazonaws.com"),
-    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
-
-// 9. Create client to S3 service 's3.amazonaws.com' at port 80 with non-TLS security
-// using okhttp3.HttpUrl object for authenticated access.
-MinioClient s3Client = new MinioClient(HttpUrl.parse("s3.amazonaws.com"),
-    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
-
-// 10. Create client to S3 service 's3.amazonaws.com' at port 80 with non-TLS security
 // and region 'us-west-1' for authenticated access.
-MinioClient s3Client = new MinioClient("s3.amazonaws.com",
-    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", "us-west-1");
-
-// 11. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security
+MinioClient s3Client =
+    MinioClient.builder()
+	    .endpoint("s3.amazonaws.com", 80, false)
+        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
+		.region("us-west-1")
+		.build();
+
+// 9. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security
 // and region 'eu-west-2' for authenticated access.
-MinioClient s3Client = new MinioClient("s3.amazonaws.com", 443,
-    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", "eu-west-2", true);
-
-// 12. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security,
+MinioClient s3Client =
+    MinioClient.builder()
+	    .endpoint("s3.amazonaws.com", 443, true)
+		.credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY").
+		.region("eu-west-2")
+		.build();
+
+// 10. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security,
 // region 'eu-central-1' and custom HTTP client for authenticated access.
-MinioClient s3Client = new MinioClient("s3.amazonaws.com", 443,
-    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", "eu-central-1", true, customHttpClient);
+MinioClient s3Client =
+    MinioClient.builder()
+	    .endpoint("s3.amazonaws.com", 443, true)
+        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
+		.region("eu-central-1")
+		.httpClient(customHttpClient)
+		.build();
 ```
 
 ## Common Exceptions
diff --git a/examples/BucketExists.java b/examples/BucketExists.java
index 17a8b79bf..aec612a1e 100644
--- a/examples/BucketExists.java
+++ b/examples/BucketExists.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Check whether 'my-bucketname' exist or not.
       boolean found =
diff --git a/examples/ComposeObject.java b/examples/ComposeObject.java
index ada2778e8..503f2633f 100644
--- a/examples/ComposeObject.java
+++ b/examples/ComposeObject.java
@@ -28,12 +28,19 @@ public class ComposeObject {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* play.minio.io for test and development. */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io:9000",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Create a ComposeSource to compose Object.
       ComposeSource s1 = new ComposeSource("my-bucketname-one", "my-objectname-one");
diff --git a/examples/ComposeObjectEncrypted.java b/examples/ComposeObjectEncrypted.java
index eb92ab45f..e115f32f4 100644
--- a/examples/ComposeObjectEncrypted.java
+++ b/examples/ComposeObjectEncrypted.java
@@ -33,12 +33,19 @@ public class ComposeObjectEncrypted {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* play.minio.io for test and development. */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io:9000",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       byte[] key = "01234567890123456789012345678901".getBytes(StandardCharsets.UTF_8);
       SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
diff --git a/examples/CopyObject.java b/examples/CopyObject.java
index 610361060..9cdf76a66 100644
--- a/examples/CopyObject.java
+++ b/examples/CopyObject.java
@@ -34,14 +34,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       KeyGenerator keyGen = KeyGenerator.getInstance("AES");
       keyGen.init(256);
diff --git a/examples/DeleteBucketEncryption.java b/examples/DeleteBucketEncryption.java
index b983a16b6..004b7a3ff 100644
--- a/examples/DeleteBucketEncryption.java
+++ b/examples/DeleteBucketEncryption.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       minioClient.deleteBucketEncryption(
           DeleteBucketEncryptionArgs.builder().bucket("my-bucketname").build());
diff --git a/examples/DeleteBucketLifeCycle.java b/examples/DeleteBucketLifeCycle.java
index 4f2a3c436..5d88215f8 100644
--- a/examples/DeleteBucketLifeCycle.java
+++ b/examples/DeleteBucketLifeCycle.java
@@ -26,9 +26,20 @@ public class DeleteBucketLifeCycle {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       // Pass blank as life cycle in setBucketLifeCycle method.
       minioClient.deleteBucketLifeCycle(
           DeleteBucketLifeCycleArgs.builder().bucket("my-bucketName").build());
diff --git a/examples/DeleteBucketNotification.java b/examples/DeleteBucketNotification.java
index 7d3a882d6..d8d0ca2ee 100644
--- a/examples/DeleteBucketNotification.java
+++ b/examples/DeleteBucketNotification.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       minioClient.deleteBucketNotification(
           DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build());
diff --git a/examples/DeleteBucketPolicy.java b/examples/DeleteBucketPolicy.java
index 32d5f8209..25137db09 100644
--- a/examples/DeleteBucketPolicy.java
+++ b/examples/DeleteBucketPolicy.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       minioClient.deleteBucketPolicy(
           DeleteBucketPolicyArgs.builder().bucket("my-bucketname").build());
diff --git a/examples/DeleteBucketTags.java b/examples/DeleteBucketTags.java
index f81980621..106475f5f 100644
--- a/examples/DeleteBucketTags.java
+++ b/examples/DeleteBucketTags.java
@@ -26,9 +26,20 @@ public class DeleteBucketTags {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       minioClient.deleteBucketTags(DeleteBucketTagsArgs.builder().bucket("my-bucketname").build());
       System.out.println("Bucket tags deleted successfully");
     } catch (MinioException e) {
diff --git a/examples/DeleteDefaultRetention.java b/examples/DeleteDefaultRetention.java
index 7d0f6c688..45b602d11 100644
--- a/examples/DeleteDefaultRetention.java
+++ b/examples/DeleteDefaultRetention.java
@@ -26,11 +26,21 @@ public class DeleteDefaultRetention {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
+      /* play.min.io for test and development. */
+      MinioClient minioClient =
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
       /* Amazon S3: */
-      MinioClient s3Client =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
-      s3Client.deleteDefaultRetention(
+      minioClient.deleteDefaultRetention(
           DeleteDefaultRetentionArgs.builder().bucket("my-lock-enabled-bucketname").build());
 
       System.out.println("Default retention configuration is deleted successfully");
diff --git a/examples/DeleteObjectTags.java b/examples/DeleteObjectTags.java
index 8e050739a..9a0c342b3 100644
--- a/examples/DeleteObjectTags.java
+++ b/examples/DeleteObjectTags.java
@@ -26,9 +26,20 @@ public class DeleteObjectTags {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       minioClient.deleteObjectTags(
           DeleteObjectTagsArgs.builder().bucket("my-bucketname").object("my-objectname").build());
       System.out.println("Object tags deleted successfully");
diff --git a/examples/DisableObjectLegalHold.java b/examples/DisableObjectLegalHold.java
index 5b7de893d..668ca8a6c 100644
--- a/examples/DisableObjectLegalHold.java
+++ b/examples/DisableObjectLegalHold.java
@@ -25,13 +25,19 @@ public class DisableObjectLegalHold {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException, IllegalArgumentException {
     try {
-
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Disable object legal hold.
       minioClient.disableObjectLegalHold(
diff --git a/examples/DisableVersioning.java b/examples/DisableVersioning.java
index d093158dc..fe00d6dbb 100644
--- a/examples/DisableVersioning.java
+++ b/examples/DisableVersioning.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Disable versioning on 'my-bucketname'.
       minioClient.disableVersioning(
diff --git a/examples/DownloadObject.java b/examples/DownloadObject.java
index 0eb300959..bd208b62f 100644
--- a/examples/DownloadObject.java
+++ b/examples/DownloadObject.java
@@ -31,14 +31,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       {
         // Download 'my-objectname' from 'my-bucketname' to 'my-filename'
diff --git a/examples/EnableObjectLegalHold.java b/examples/EnableObjectLegalHold.java
index 777d274c6..c96f50fce 100644
--- a/examples/EnableObjectLegalHold.java
+++ b/examples/EnableObjectLegalHold.java
@@ -25,13 +25,19 @@ public class EnableObjectLegalHold {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException, IllegalArgumentException {
     try {
-
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Enable object legal hold.
       minioClient.enableObjectLegalHold(
diff --git a/examples/EnableVersioning.java b/examples/EnableVersioning.java
index 79b4904cd..8268c90be 100644
--- a/examples/EnableVersioning.java
+++ b/examples/EnableVersioning.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Enable versioning on 'my-bucketname'.
       minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucketname").build());
diff --git a/examples/GetBucketEncryption.java b/examples/GetBucketEncryption.java
index 10884c595..d083520bd 100644
--- a/examples/GetBucketEncryption.java
+++ b/examples/GetBucketEncryption.java
@@ -30,14 +30,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       SseConfiguration config =
           minioClient.getBucketEncryption(
diff --git a/examples/GetBucketLifeCycle.java b/examples/GetBucketLifeCycle.java
index 889d32ecb..a0c45fb83 100644
--- a/examples/GetBucketLifeCycle.java
+++ b/examples/GetBucketLifeCycle.java
@@ -26,9 +26,20 @@ public class GetBucketLifeCycle {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       String lifecycle =
           minioClient.getBucketLifeCycle(
               GetBucketLifeCycleArgs.builder().bucket("my-bucketName").build());
diff --git a/examples/GetBucketNotification.java b/examples/GetBucketNotification.java
index 86a2a71a8..3755ab80e 100644
--- a/examples/GetBucketNotification.java
+++ b/examples/GetBucketNotification.java
@@ -29,14 +29,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       NotificationConfiguration config =
           minioClient.getBucketNotification(
diff --git a/examples/GetBucketPolicy.java b/examples/GetBucketPolicy.java
index 4ede6ef1c..d049a0804 100644
--- a/examples/GetBucketPolicy.java
+++ b/examples/GetBucketPolicy.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       String policy =
           minioClient.getBucketPolicy(
diff --git a/examples/GetBucketTags.java b/examples/GetBucketTags.java
index df686aef1..93b77cb76 100644
--- a/examples/GetBucketTags.java
+++ b/examples/GetBucketTags.java
@@ -27,9 +27,20 @@ public class GetBucketTags {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       Tags tags =
           minioClient.getBucketTags(GetBucketTagsArgs.builder().bucket("my-bucketname").build());
       System.out.println("Bucket tags: " + tags.get());
diff --git a/examples/GetDefaultRetention.java b/examples/GetDefaultRetention.java
index c14c280cc..bfdc1ada8 100644
--- a/examples/GetDefaultRetention.java
+++ b/examples/GetDefaultRetention.java
@@ -27,12 +27,22 @@ public class GetDefaultRetention {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
+      /* play.min.io for test and development. */
+      MinioClient minioClient =
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
       /* Amazon S3: */
-      MinioClient s3Client =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       ObjectLockConfiguration config =
-          s3Client.getDefaultRetention(
+          minioClient.getDefaultRetention(
               GetDefaultRetentionArgs.builder().bucket("my-lock-enabled-bucketname").build());
 
       System.out.println("Default retention configuration of bucket");
diff --git a/examples/GetObject.java b/examples/GetObject.java
index b960abbad..d052219b5 100644
--- a/examples/GetObject.java
+++ b/examples/GetObject.java
@@ -30,14 +30,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Get input stream to have content of 'my-objectname' from 'my-bucketname'
       InputStream stream =
diff --git a/examples/GetObjectProgressBar.java b/examples/GetObjectProgressBar.java
index 815e7da57..60be69c7b 100644
--- a/examples/GetObjectProgressBar.java
+++ b/examples/GetObjectProgressBar.java
@@ -38,14 +38,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      // "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Check whether the object exists using statObject(). If the object is not found,
       // statObject() throws an exception. It means that the object exists when statObject()
diff --git a/examples/GetObjectRetention.java b/examples/GetObjectRetention.java
index 2f8b14456..8c2a3a249 100644
--- a/examples/GetObjectRetention.java
+++ b/examples/GetObjectRetention.java
@@ -27,13 +27,19 @@ public class GetObjectRetention {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException, IllegalArgumentException {
     try {
-
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Get object lock retention
       Retention retention =
diff --git a/examples/GetObjectTags.java b/examples/GetObjectTags.java
index 8dd011553..c951ea824 100644
--- a/examples/GetObjectTags.java
+++ b/examples/GetObjectTags.java
@@ -27,9 +27,20 @@ public class GetObjectTags {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       Tags tags =
           minioClient.getObjectTags(
               GetObjectTagsArgs.builder().bucket("my-bucketname").object("my-objectname").build());
diff --git a/examples/GetPartialObject.java b/examples/GetPartialObject.java
index 0ec9509d2..f37cfdb40 100644
--- a/examples/GetPartialObject.java
+++ b/examples/GetPartialObject.java
@@ -30,14 +30,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Get input stream to have content of 'my-objectname' from 'my-bucketname' starts from
       // byte position 1024 and length 4096.
diff --git a/examples/GetPresignedObjectUrl.java b/examples/GetPresignedObjectUrl.java
index 5d40b5b1b..e154b88cb 100644
--- a/examples/GetPresignedObjectUrl.java
+++ b/examples/GetPresignedObjectUrl.java
@@ -29,14 +29,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Get presigned URL string to delete 'my-objectname' in 'my-bucketname' and its life time
       // is one day.
diff --git a/examples/IsObjectLegalHoldEnabled.java b/examples/IsObjectLegalHoldEnabled.java
index c7fba81db..fe760df2d 100644
--- a/examples/IsObjectLegalHoldEnabled.java
+++ b/examples/IsObjectLegalHoldEnabled.java
@@ -27,13 +27,19 @@ public class IsObjectLegalHoldEnabled {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException, IllegalArgumentException {
     try {
-
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Enable object legal hold.
       minioClient.enableObjectLegalHold(
diff --git a/examples/IsVersioningEnabled.java b/examples/IsVersioningEnabled.java
index 082853fff..5050d176a 100644
--- a/examples/IsVersioningEnabled.java
+++ b/examples/IsVersioningEnabled.java
@@ -31,14 +31,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Create bucket 'my-bucketname' if it doesn`t exist.
       if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket("my-bucketname").build())) {
diff --git a/examples/ListBuckets.java b/examples/ListBuckets.java
index ac9c9b26b..babe41b24 100644
--- a/examples/ListBuckets.java
+++ b/examples/ListBuckets.java
@@ -29,14 +29,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // List buckets we have atleast read access.
       List bucketList = minioClient.listBuckets();
diff --git a/examples/ListIncompleteUploads.java b/examples/ListIncompleteUploads.java
index f81ad212d..97ca24241 100644
--- a/examples/ListIncompleteUploads.java
+++ b/examples/ListIncompleteUploads.java
@@ -31,14 +31,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Check whether 'my-bucketname' exist or not.
       boolean found =
diff --git a/examples/ListObjects.java b/examples/ListObjects.java
index 7ee6443fc..3d4b03fb8 100644
--- a/examples/ListObjects.java
+++ b/examples/ListObjects.java
@@ -30,14 +30,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       {
         // Lists objects information.
diff --git a/examples/ListenBucketNotification.java b/examples/ListenBucketNotification.java
index 88e2ea890..d0b5bc80b 100644
--- a/examples/ListenBucketNotification.java
+++ b/examples/ListenBucketNotification.java
@@ -32,10 +32,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       String[] events = {"s3:ObjectCreated:*", "s3:ObjectAccessed:*"};
       try (CloseableIterator> ci =
diff --git a/examples/MakeBucket.java b/examples/MakeBucket.java
index 3c8642165..967dc730f 100644
--- a/examples/MakeBucket.java
+++ b/examples/MakeBucket.java
@@ -29,14 +29,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Create bucket 'my-bucketname' if it doesn`t exist.
       if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket("my-bucketname").build())) {
diff --git a/examples/PresignedGetObject.java b/examples/PresignedGetObject.java
index f17648e37..cf9c889d2 100644
--- a/examples/PresignedGetObject.java
+++ b/examples/PresignedGetObject.java
@@ -29,14 +29,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Get presigned URL string to download 'my-objectname' in 'my-bucketname' and its life time
       // is one day.
diff --git a/examples/PresignedPostPolicy.java b/examples/PresignedPostPolicy.java
index 3898b5220..54003e914 100644
--- a/examples/PresignedPostPolicy.java
+++ b/examples/PresignedPostPolicy.java
@@ -30,14 +30,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Create new PostPolicy object for 'my-bucketname', 'my-objectname' and 7 days expire time
       // from now.
diff --git a/examples/PresignedPutObject.java b/examples/PresignedPutObject.java
index d2451ea6e..e231de21e 100644
--- a/examples/PresignedPutObject.java
+++ b/examples/PresignedPutObject.java
@@ -31,14 +31,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Get presigned URL string to upload 'my-objectname' in 'my-bucketname'
       // with response-content-type as application/json and its life time is
diff --git a/examples/PutObject.java b/examples/PutObject.java
index 6c1d2e8a4..c6a19b0c2 100644
--- a/examples/PutObject.java
+++ b/examples/PutObject.java
@@ -34,14 +34,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Create some content for the object.
       StringBuilder builder = new StringBuilder();
diff --git a/examples/PutObjectProgressBar.java b/examples/PutObjectProgressBar.java
index a224afd0a..837f97133 100644
--- a/examples/PutObjectProgressBar.java
+++ b/examples/PutObjectProgressBar.java
@@ -32,14 +32,17 @@ public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException, MinioException {
     /* play.min.io for test and development. */
     MinioClient minioClient =
-        new MinioClient(
-            "https://play.min.io",
-            "Q3AM3UQ867SPQQA43P2F",
-            "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+        MinioClient.builder()
+            .endpoint("https://play.min.io")
+            .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+            .build();
+
     /* Amazon S3: */
-    // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com",
-    // "YOUR-ACCESSKEYID",
-    // "YOUR-SECRETACCESSKEY");
+    // MinioClient minioClient =
+    //     MinioClient.builder()
+    //         .endpoint("https://s3.amazonaws.com")
+    //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+    //         .build();
 
     String objectName = "my-objectname";
     String bucketName = "my-bucketname";
diff --git a/examples/PutObjectUiProgressBar.java b/examples/PutObjectUiProgressBar.java
index 0bf15582e..1fab958d4 100644
--- a/examples/PutObjectUiProgressBar.java
+++ b/examples/PutObjectUiProgressBar.java
@@ -61,17 +61,19 @@ public void go() {
    */
   private void uploadFile(String fileName)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException, MinioException {
-
     /* play.min.io for test and development. */
     MinioClient minioClient =
-        new MinioClient(
-            "https://play.min.io",
-            "Q3AM3UQ867SPQQA43P2F",
-            "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+        MinioClient.builder()
+            .endpoint("https://play.min.io")
+            .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+            .build();
+
     /* Amazon S3: */
-    // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com",
-    // "YOUR-ACCESSKEYID",
-    // "YOUR-SECRETACCESSKEY");
+    // MinioClient minioClient =
+    //     MinioClient.builder()
+    //         .endpoint("https://s3.amazonaws.com")
+    //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+    //         .build();
 
     File file = new File(fileName);
     try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) {
diff --git a/examples/RemoveBucket.java b/examples/RemoveBucket.java
index 436446abb..3b08c3064 100644
--- a/examples/RemoveBucket.java
+++ b/examples/RemoveBucket.java
@@ -29,14 +29,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Remove bucket 'my-bucketname' if it exists.
       // This operation will only work if your bucket is empty.
diff --git a/examples/RemoveIncompleteUpload.java b/examples/RemoveIncompleteUpload.java
index 92e3f2cb2..bf98d3652 100644
--- a/examples/RemoveIncompleteUpload.java
+++ b/examples/RemoveIncompleteUpload.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Remove all incomplete multipart upload sessions for a given bucket and object name.
       minioClient.removeIncompleteUpload(
diff --git a/examples/RemoveObject.java b/examples/RemoveObject.java
index 48df7006e..3cc804509 100644
--- a/examples/RemoveObject.java
+++ b/examples/RemoveObject.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Remove object.
       minioClient.removeObject(
diff --git a/examples/RemoveObjects.java b/examples/RemoveObjects.java
index cf4bb931f..11827c3a7 100644
--- a/examples/RemoveObjects.java
+++ b/examples/RemoveObjects.java
@@ -33,14 +33,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       List objects = new LinkedList<>();
       objects.add(new DeleteObject("my-objectname1"));
diff --git a/examples/SelectObjectContent.java b/examples/SelectObjectContent.java
index 5ed8b9252..247a08a1a 100644
--- a/examples/SelectObjectContent.java
+++ b/examples/SelectObjectContent.java
@@ -37,14 +37,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       byte[] data =
           ("Year,Make,Model,Description,Price\n"
diff --git a/examples/SetBucketEncryption.java b/examples/SetBucketEncryption.java
index a96a3ee75..649c919c0 100644
--- a/examples/SetBucketEncryption.java
+++ b/examples/SetBucketEncryption.java
@@ -33,14 +33,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       List rules = new LinkedList<>();
       rules.add(new SseConfigurationRule(null, SseAlgorithm.AES256));
diff --git a/examples/SetBucketLifeCycle.java b/examples/SetBucketLifeCycle.java
index cf3d93243..21418d9d9 100644
--- a/examples/SetBucketLifeCycle.java
+++ b/examples/SetBucketLifeCycle.java
@@ -26,9 +26,20 @@ public class SetBucketLifeCycle {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       String lifeCycle =
           "expire-bucket"
               + "Enabled365"
diff --git a/examples/SetBucketNotification.java b/examples/SetBucketNotification.java
index f16b15048..4ef123adc 100644
--- a/examples/SetBucketNotification.java
+++ b/examples/SetBucketNotification.java
@@ -31,13 +31,19 @@ public class SetBucketNotification {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Local MinIO for test and development. */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("http://127.0.0.1:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       NotificationConfiguration config = new NotificationConfiguration();
 
diff --git a/examples/SetBucketPolicy.java b/examples/SetBucketPolicy.java
index faa0ab978..07f7b89ba 100644
--- a/examples/SetBucketPolicy.java
+++ b/examples/SetBucketPolicy.java
@@ -28,14 +28,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       StringBuilder builder = new StringBuilder();
       builder.append("{\n");
diff --git a/examples/SetBucketTags.java b/examples/SetBucketTags.java
index c6e145256..49245d9ca 100644
--- a/examples/SetBucketTags.java
+++ b/examples/SetBucketTags.java
@@ -28,9 +28,20 @@ public class SetBucketTags {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       Map map = new HashMap<>();
       map.put("Project", "Project One");
       map.put("User", "jsmith");
diff --git a/examples/SetDefaultRetention.java b/examples/SetDefaultRetention.java
index 71f805075..31d48bbce 100644
--- a/examples/SetDefaultRetention.java
+++ b/examples/SetDefaultRetention.java
@@ -29,15 +29,25 @@ public class SetDefaultRetention {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
+      /* play.min.io for test and development. */
+      MinioClient minioClient =
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
       /* Amazon S3: */
-      MinioClient s3Client =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Declaring config with Retention mode as Compliance and duration as 100 days
       ObjectLockConfiguration config =
           new ObjectLockConfiguration(RetentionMode.COMPLIANCE, new RetentionDurationDays(100));
 
-      s3Client.setDefaultRetention(
+      minioClient.setDefaultRetention(
           SetDefaultRetentionArgs.builder()
               .bucket("my-lock-enabled-bucketname")
               .config(config)
diff --git a/examples/SetObjectRetention.java b/examples/SetObjectRetention.java
index b860610b2..11303899e 100644
--- a/examples/SetObjectRetention.java
+++ b/examples/SetObjectRetention.java
@@ -30,13 +30,19 @@ public class SetObjectRetention {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException, IllegalArgumentException {
     try {
-
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       // Declaring config with Retention mode as Compliance and
       // retain until 3 days from current date.
diff --git a/examples/SetObjectTags.java b/examples/SetObjectTags.java
index 1598dd107..5075e0229 100644
--- a/examples/SetObjectTags.java
+++ b/examples/SetObjectTags.java
@@ -28,9 +28,20 @@ public class SetObjectTags {
   public static void main(String[] args)
       throws IOException, NoSuchAlgorithmException, InvalidKeyException {
     try {
-      /* Amazon S3: */
+      /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
+
+      /* Amazon S3: */
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
+
       Map map = new HashMap<>();
       map.put("Project", "Project One");
       map.put("User", "jsmith");
diff --git a/examples/StatObject.java b/examples/StatObject.java
index 2c6f7305b..4d07f7e51 100644
--- a/examples/StatObject.java
+++ b/examples/StatObject.java
@@ -33,14 +33,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       KeyGenerator keyGen = KeyGenerator.getInstance("AES");
       keyGen.init(256);
diff --git a/examples/UploadObject.java b/examples/UploadObject.java
index e4c3765a0..bddda4f59 100644
--- a/examples/UploadObject.java
+++ b/examples/UploadObject.java
@@ -34,14 +34,17 @@ public static void main(String[] args)
     try {
       /* play.min.io for test and development. */
       MinioClient minioClient =
-          new MinioClient(
-              "https://play.min.io",
-              "Q3AM3UQ867SPQQA43P2F",
-              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
+          MinioClient.builder()
+              .endpoint("https://play.min.io")
+              .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+              .build();
 
       /* Amazon S3: */
-      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
-      //                                           "YOUR-SECRETACCESSKEY");
+      // MinioClient minioClient =
+      //     MinioClient.builder()
+      //         .endpoint("https://s3.amazonaws.com")
+      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
+      //         .build();
 
       {
         // Upload 'my-filename' as object 'my-objectname' in 'my-bucketname'.
diff --git a/functional/FunctionalTest.java b/functional/FunctionalTest.java
index 485917105..f2664b217 100644
--- a/functional/FunctionalTest.java
+++ b/functional/FunctionalTest.java
@@ -4199,7 +4199,7 @@ public static void main(String[] args) throws Exception {
 
     int exitValue = 0;
     try {
-      client = new MinioClient(endpoint, accessKey, secretKey);
+      client = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
       // Enable trace for debugging.
       // client.traceOn(System.out);
 
@@ -4216,7 +4216,12 @@ public static void main(String[] args) throws Exception {
         // Get new bucket name to avoid minio azure gateway failure.
         bucketName = getRandomName();
         // Quick tests with passed region.
-        client = new MinioClient(endpoint, accessKey, secretKey, region);
+        client =
+            MinioClient.builder()
+                .endpoint(endpoint)
+                .credentials(accessKey, secretKey)
+                .region(region)
+                .build();
         FunctionalTest.runQuickTests();
       }
     } catch (Exception e) {
diff --git a/functional/TestUserAgent.java b/functional/TestUserAgent.java
index 25d1040af..fca96cfb1 100644
--- a/functional/TestUserAgent.java
+++ b/functional/TestUserAgent.java
@@ -23,7 +23,7 @@
 
 public class TestUserAgent {
   public static void main(String[] args) throws Exception {
-    MinioClient client = new MinioClient("http://example.org");
+    MinioClient client = MinioClient.builder().endpoint("http://example.org").build();
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     client.traceOn(baos);
     client.bucketExists(BucketExistsArgs.builder().bucket("any-bucket-name-works").build());