Blockchain for Beginners 3 - Coding a Block
Coding a Block problem statement
Implement a cryptographic ‘Block' in Javaimport java.time.LocalDate;
public class Block {
private LocalDate timestamp;
private String previousHash;
private String currentHash;
private String data;
Block(LocalDate timestamp, String data) {
this.timestamp = timestamp;
this.data = data;
}
}
Hi there, my name is Marius from AlefTav Coding and in this tutorial you will learn how to implement a Block in programming code.
I installed on my local computer the Java Development Kit (JDK) and IntelliJ IDEA, as my Integrated Development Enviroment (IDE). These are the two software tools I will use to implement my programming code.
I start up IntelliJ, and select, Create New Project.
On the menu, New Project I choose the option, Java, then, click Next, type my Project name as, blockchainapp, and click, Finish.
Then, right click on the option src, choose New, followed by Java Class and type as the Name the word, Block.
I declare four class variables and a constructor as follows:
import java.time.LocalDate;
public class Block {
private LocalDate timestamp;
private String previousHash;
private String currentHash;
private String data;
Block(LocalDate timestamp, String data) {
this.timestamp = timestamp;
this.data = data;
}
}
As outlined in my previous tutorial, some of the Header and Data information needed are the Timestamp, Previous hash, Current hash and Data. The timestamp must reflect an actual date and time, I declare timestamp as a Java data type, LocalDate. The other three variables are declared as the Java data type String.
When I create or construct a block object, I provide the two details, timestamp and data.
In this tutorial you learnt how to implement a cryptographic Block in the Java programming language.
My name is Marius from AlefTav Coding. Thank you for reading and see you in the next tutorial.
Feel free to upvote, re-steem and share. For more of this you can find me at the following links.
https://busy.org/@mariusclaassen
https://steemit.com/@mariusclaassen
https://d.tube/#!/c/mariusclaassen
https://bit.tube/mariusclaassen
https://bit.tube/mariusclaassen