Developing Business Blockchain Applications on Hyperledger IMC Institute
The document provides a comprehensive guide for developing business blockchain applications on Hyperledger using Google Cloud Platform. It details the setup process of an Ubuntu virtual server, installation of Hyperledger Composer and Fabric, and instructions for creating and testing a business network. Additionally, it explains how to generate REST APIs for the business network, complete with sample code and deployment information.
4. คอมเม็น ต์
คอมเม็น ต์ค ือ ข้อ ความทีแ ทรกอยูใ นโปรแกรม
่ ่
คอมเม็น ต์เ ขีย นไว้เ พือ
่
• อธิบ ายโปรแกรม
• ให้ผ ู้อ ่า นเข้า ใจโปรแกรมง่า ยยิ่ง ขึ้น
• ช่ว ยทำา ให้ก ารแก้ไ ขและปรับ ปรุง โปรแกรมเป็น ไปได้
ง่า ยขึ้น
ภาษาจาวากำา หนดรูป แบบของการเขีย นคอมเม็น ต์
ไว้ส ามรูป แบบดัง นี้
• // This is a comment
คอมเม็น ต์ส ำา หรับ ข้อ ความบรรทัด เดีย ว
• /* This is also a comment */
คอมเม็น ต์ส ำา หรับ ข้อ ความตั้ง แต่ห นึ่ง บรรทัด ขึ้น ไป
• /** This is a comment for documentation */
5. ตัว อย่า งโปรแกรม
/* This program is to show
/* This program is to show
how to write comments
how to write comments */*/
public class CommentDemo {{
public class CommentDemo
// Main method
// Main method
public static void main(String args[]) {{
public static void main(String args[])
/** This is aa comment for documentation */
/** This is comment for documentation */
System.out.println("Document");
System.out.println("Document");
}}
}}
11. คีย ์เ วิร ์ด ที่ใ ช้ใ นภาษาจาวา
abstract continue for new switch
assert default goto package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while
27. ตัว อย่า งโปรแกรม
public class VariableAssignDemo {
public class VariableAssignDemo {
public static void main(String args[]) {
public static void main(String args[]) {
int x,y;
int x,y;
boolean b1;
boolean b1;
float z = 3.414f; /* The program will not be
float z = 3.414f; /* The program will not be
compiled successfully if
compiled successfully if
a character f is missing */
a character f is missing */
double w;
double w;
x = 5;
x = 5;
y = 4;
y = 4;
b1 = (x > y);
b1 = (x > y);
w = x * 3.2;
w = x * 3.2;
System.out.println("x = " + x + " y = " + y);
System.out.println("x = " + x + " y = " + y);
System.out.println("b1 = " + b1);
System.out.println("b1 = " + b1);
System.out.println("z = " + z + " w = " + w);
System.out.println("z = " + z + " w = " + w);
}}
}}
28. ค่า คงที่
การประกาศค่า คงทีใ นภาษาจาวาทำา ได้โ ดยการ
่
ใส่ค ีย เ วิร ์ด final หน้า คำา สั่ง ประกาศช์ื์ ่อ โดยมี
์
รูป แบบดัง นี้
final dataType CONSTANT_NAME = expression;
ตัว อย่า งเช่น คำา สั่ง
final int MINIMUM = 4;
final double MIN_GPA = 2.00;
29. ตัว อย่า งโปรแกรม
public class ConstantDemo {
public class ConstantDemo {
public static void main(String args[]) {
public static void main(String args[]) {
final int MAXIMUM = 10;
final int MAXIMUM = 10;
final double MIN_GPA;
final double MIN_GPA;
System.out.println("Maximum is " + MAXIMUM);
System.out.println("Maximum is " + MAXIMUM);
MIN_GPA = 2.00;
MIN_GPA = 2.00;
System.out.println("Minimum GPA is " + MIN_GPA);
System.out.println("Minimum GPA is " + MIN_GPA);
//
// MIN_GPA = 3.00;
MIN_GPA = 3.00; //illegal
//illegal
}}
}}
32. ตัว อย่า งโปรแกรม
public class VariableScopeDemo {
public class VariableScopeDemo {
public int i;
public int i; // object variable
// object variable
public void method1() {
public void method1() {
int j = 4;
int j = 4; // local variable
// local variable
int k = 2;
int k = 2; // another local variable
// another local variable
}}
public void method2() {
public void method2() {
int j = 0;
int j = 0; // local variable
// local variable
System.out.println(i);
System.out.println(i);
// calling an object variable i
// calling an object variable i
//
// System.out.println(k);
System.out.println(k); // illegal
// illegal
}}
}}
37. ตัว อย่า งโปรแกรม
public class IncrementDemo {
public class IncrementDemo {
public static void main(String args[]) {
public static void main(String args[]) {
int x;
int x;
int y;
int y;
x = 5;
x = 5;
y = x++;
y = x++;
System.out.println("x = "+x+" y = "+y);
System.out.println("x = "+x+" y = "+y);
y = ++x;
y = ++x;
System.out.println("x = "+x+" y = "+y);
System.out.println("x = "+x+" y = "+y);
}}
}}
x = 6 y = 5
ผลลัพ ธ์ท ไ ด้จ ากการรัน โปรแกรม 7
ี่ x = y = 7
39. ตัว อย่า งโปรแกรม
public class BooleanDemo {
public class BooleanDemo {
public static void main(String args[]) {
public static void main(String args[]) {
int x = 5;
int x = 5;
int y = 4;
int y = 4;
boolean b1;
boolean b1;
b1 = (x!=y);
b1 = (x!=y);
System.out.println("x not equal to y is "+b1);
System.out.println("x not equal to y is "+b1);
System.out.println("y less than 0 is "+(y<0));
System.out.println("y less than 0 is "+(y<0));
}}
}}
55. ตัว อย่า งโปรแกรม
public class PromotionDemo {
public class PromotionDemo {
public static void main(String args[]) {
public static void main(String args[]) {
int i;
int i;
long l;
long l;
float fl = 4.2f;
float fl = 4.2f;
i = 4;
i = 4;
l = i;
l = i;
fl = i;
fl = i;
double x = fl;
double x = fl;
fl = 4.2;
fl = 4.2; //illegal
//illegal
}}
}}
68. ตัว อย่า งโปรแกรม
public class PrintDemo {
public class PrintDemo {
public static void main(String args[]) {
public static void main(String args[]) {
int x = 3, y = 4, z = 5;
int x = 3, y = 4, z = 5;
System.out.print("x = "+x);
System.out.print("x = "+x);
System.out.println(" y = "+y);
System.out.println(" y = "+y);
System.out.println("z = "+z);
System.out.println("z = "+z);
}}
}}
x = 3 y = 4
ผลลัพ ธ์ท ไ ด้จ ากการรัน โปรแกรม 5
ี่ z =
69. การ รับ ข้อ มูล เข้า มาทาง
Command Line
เมธอดทีช ื่อ main() จะมี argument เป็น String
่
args[] ซึง สามารถที่จ ะ รับ argument ทีส ง ผ่า นมา
่ ่ ่
จาก command line ได้
ตัว อย่า งเช่น
public class Sample {
public static void main(String args[]) {
System.out.println(“My name is ” + args[0] +
“ and I am a ” + args[1]);
}
}
ถ้า ป้อ นอิน พุต ตรง command line เป็น java
Sample Tommy boy
จะได้ผ ลลัพ ธ์ค ือ My name is Tommy and I am a boy