# Quick Start

### Make your first Java call to the IC canister

To create your first IC canister, follow instructions from the Dfinity Quick Start location.

{% embed url="<https://smartcontracts.org/docs/quickstart/2-quickstart.html>" %}
Dfinity Quick Start
{% endembed %}

You can either use local installation of the Canister SDK or use ICP Ninja.

{% embed url="<https://icp.ninja/>" %}

If you create local project, it will implicitly create the first Motoko file [**main.mo**](https://github.com/ic4j/samples/blob/master/IC4JHelloWorld/src/main.mo). The code is a very simple HelloWorld application with one method named **greet***.*

{% code title="main.mo" %}

```javascript
actor {
  public func greet(name : Text) : async Text {
    return "Hello, " # name # "!";
  };
};
```

{% endcode %}

To run this canister code in [ICP Ninja](https://icp.ninja/) just copy and paste this source to the editor and click the **Deploy** button.

We can start building the first Java application, that will invoke **greet** method. The source of IC4JHelloWorld project can be found [here](https://github.com/ic4j/samples/tree/master/IC4JHelloWorld).

For your Java project you can use either Gradle or Maven build. To include IC4J support in your project include Gradle or Maven dependencies.&#x20;

{% tabs %}
{% tab title="Gradle" %}

```markup
implementation 'org.ic4j:ic4j-agent:0.8.0'
implementation 'org.ic4j:ic4j-candid:0.8.0'
```

{% endtab %}

{% tab title="Maven" %}

```xml
<dependency>
  <groupId>org.ic4j</groupId>
  <artifactId>ic4j-agent</artifactId>
  <version>0.8.0</version>
</dependency>
<dependency>
  <groupId>org.ic4j</groupId>
  <artifactId>ic4j-candid</artifactId>
  <version>0.8.0</version>
</dependency>
```

{% endtab %}
{% endtabs %}

Now we can start writing Java code. The easiest way to communicate with the Internet Computer **Canister** is to use **ProxyBuilder**.&#x20;

The ProxyBuilder module creates the Java proxy object Canister  based on Java interface with Canister annotations. You can find full source of this interface [here](https://github.com/ic4j/samples/blob/master/IC4JHelloWorld/src/main/java/org/ic4j/samples/helloworld/HelloWorldProxy.java).

{% code title="HelloWorldProxy.java" %}

```java
public interface HelloWorldProxy {	
	@UPDATE
	@Name("greet")
	@Waiter(timeout = 30)
	public CompletableFuture<String> greet(@Argument(Type.TEXT)String name);
}
```

{% endcode %}

Next, define the **Type of Method** for the Canister (UPDATE or QUERY), the **Name** of the method and define **Waiter** properties for **UPDATE** method.&#x20;

For method arguments we can also define **Candid** type.

First we have to create the **ReplicaTransport** object using the URL to your Canister (either local or remote). The we use AgentBuilder to create the **Agent Object**.&#x20;

To create the **Canister Proxy** object use ProxyBuilder *create* the method with the agent and the Canister Principal arguments and then *getProxy* method passing Java proxy class.

The full source can be found [here](https://github.com/ic4j/samples/blob/master/IC4JHelloWorld/src/main/java/org/ic4j/samples/helloworld/Main.java).

{% code title="Main.java" %}

```java
ReplicaTransport transport = ReplicaApacheHttpTransport.create(icLocation);
Agent agent = new AgentBuilder().transport(transport).build();			
HelloWorldProxy helloWorldProxy = ProxyBuilder.create(agent, Principal.fromString(icCanister))
					.getProxy(HelloWorldProxy.class);
String value = "world";		
CompletableFuture<String> proxyResponse = helloWorldProxy.greet(value);			
String output = proxyResponse.get();
```

{% endcode %}

Next, to call the Internet Computer Canister you will need 2 properties, **location URL** and **Canister ID.**&#x20;

This is an example to read those properties from the [*application.properties*](https://github.com/ic4j/samples/blob/master/IC4JHelloWorld/src/main/resources/application.properties) file.

{% code title="application.properties" %}

```java
ic.location=https://icp-api.io/
ic.canister=yaku6-4iaaa-aaaab-qacfa-cai
```

{% endcode %}

Replace those properties with ones from your deployed canister, either local or remote.

The **UPDATE** call will run asynchronously and return the Java [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) object.

Next, the Java project can be built and run using **Gradle Script** [build.gradle](https://github.com/ic4j/samples/blob/master/IC4JHelloWorld/build.gradle). (***This build requires Java 1.8;*** if you are using a different version, make the necessary modifications in the script).&#x20;

This build script creates **Fat Ja**r with all the required dependencies.

```
gradle build
```

Next run with Java.

```
java -jar build/libs/ic4j-sample-helloworld-0.6.19.jar
```

The output should look like this.

```
[main] INFO org.ic4j.samples.helloworld.Main - Hello, world!
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ic4j.com/quick-start.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
