Search…
Smart contract languages

Java

One of the design decisions of ICON is to develop on top of existing, robust, and well-used technologies to aid in the developer experience. ICON supports smart contract development in Java, which is consistently listed as a top 5 programming language for quality and usability.
Some key points about Java:
  • Object-oriented, high-level
  • Curly-brace notation
  • Statically-typed
  • Supports inheritance, libraries, user-defined types, etc
There is a tremendous amount of learning material available for Java. See the Further Resources section for more information.

Example contract

The following is the hello world contract sample taken from the ICON smart contract examples repository on Github.
1
/*
2
* Copyright 2020 ICONLOOP Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
package com.iconloop.score.example;
18
19
import score.Context;
20
import score.annotation.External;
21
import score.annotation.Payable;
22
23
public class HelloWorld {
24
private String name;
25
26
public HelloWorld(String name) {
27
this.name = name;
28
}
29
30
@External()
31
public void setName(String name) {
32
this.name = name;
33
}
34
35
@External(readonly=true)
36
public String name() {
37
return name;
38
}
39
40
@External(readonly=true)
41
public String getGreeting() {
42
String msg = "Hello " + name + "!";
43
Context.println(msg);
44
return msg;
45
}
46
47
@Payable
48
public void fallback() {
49
// just receive incoming funds
50
}
51
}
52
Copied!

Further resources

Copy link
Contents
Java