--- title: "Java" slug: "cloudfunctions-example-java" tags: ["Cloud Functions", "Cloud Functions examples"] updated: 2026-09-17T09:18:17Z published: 2026-09-17T09:18:17Z canonical: "guide.ncloud-docs.com/cloudfunctions-example-java" --- > ## Documentation Index > Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # Java Available in Classic and VPC This section describes how to create and use Java actions in a variety of ways, and includes application examples. ## Create an action Creating Java actions is similar to creating JavaScript and Swift actions. Note To compile and test actions, [JDK 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) must be set up in your local environment. A Java action is a Java program with a main method. The method must be defined in the following format: ``` public static com.google.gson.JsonObject main(com.google.gson.JsonObject); ``` Considering this requirement, here is an example of creating a Java action: 1. Create a source code file named Hello.java. ``` import com.google.gson.JsonObject; public class Hello { public static JsonObject main(JsonObject args) { String name = "World"; String place = "Naver"; if (args.has("name")) name = args.getAsJsonPrimitive("name").getAsString(); if (args.has("place")) place = args.getAsJsonPrimitive("place").getAsString(); JsonObject response = new JsonObject(); response.addProperty("payload", "Hello, " + name + " in " + place + "!"); return response; } } ``` 2. Use the command to compile Hello.java into a JAR file named hello.jar. ``` $ javac Hello.java ``` ``` $ jar cvf hello.jar Hello.class ``` 3. Upload the generated hello.jar file to create an action named helloJava. ![cloudfunctions-example-java_v2_01_ko](https://cdn.document360.io/6998976f-9d95-4df8-b847-d375892b92c2/Images/Documentation/cloudfunctions-example-java_v2_01_en.png?sv=2026-02-06&spr=https&st=2026-11-14T04%3A24%3A14Z&se=2026-11-14T05%3A24%3A14Z&sr=c&sp=r&sig=Xm%2F5Mcd7%2Bfsgvam0RbX7bLNnwByVAvxqtgxZingnjCs%3D) > Main class: Set to Hello class. If the class is not in the default package, you can use the Java fully-qualified class name (FQCN) including the package, such as com.example.MyMain. ![compute-15-2-302_ko](https://cdn.document360.io/6998976f-9d95-4df8-b847-d375892b92c2/Images/Documentation/compute-15-2-302_en.png?sv=2026-02-06&spr=https&st=2026-11-14T04%3A24%3A14Z&se=2026-11-14T05%3A24%3A14Z&sr=c&sp=r&sig=Xm%2F5Mcd7%2Bfsgvam0RbX7bLNnwByVAvxqtgxZingnjCs%3D) If you want to change the method name of the Java action, you can create an action by specifying a method name like methodName. ![compute-15-2-303_ko](https://cdn.document360.io/6998976f-9d95-4df8-b847-d375892b92c2/Images/Documentation/compute-15-2-303_en.png?sv=2026-02-06&spr=https&st=2026-11-14T04%3A24%3A14Z&se=2026-11-14T05%3A24%3A14Z&sr=c&sp=r&sig=Xm%2F5Mcd7%2Bfsgvam0RbX7bLNnwByVAvxqtgxZingnjCs%3D) Caution When compiling Java files, [google-gson](https://github.com/google/gson) must be included in the Java CLASSPATH.