Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.math.BigInteger;
import java.security.MessageDigest;

public class Main {

    public static void main(String[] args) throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);

        MessageDigest md = MessageDigest.getInstance("MD5");
        SomeObject testObject = new SomeObject();

        dos.writeInt(testObject.count);
        dos.writeLong(testObject.product);
        dos.writeDouble(testObject.stdDev);
        dos.writeUTF(testObject.name);
        dos.writeChar(testObject.delimiter);
        dos.flush();

        byte[] hashBytes = md.digest(baos.toByteArray());
        BigInteger testObjectHash = new BigInteger(hashBytes);

        System.out.println("Hash " + testObjectHash);

        dos.close();

    }
}

class SomeObject {
    int count = 200;
    long product = 1;
    double stdDev = 1.456d;
    String name = "Name";
    char delimiter = '\n';
}