Dealing with multiple java versions ubuntu

 

Dealing with multiple java versions is not a hard job. It is very simple but we need to use the same commands.

Suppose that you have multiple java versions install in your system. But some applications required java 7, some applications required java 8 and some other required another java version. Now it’s time to manage the java versions according to your application compatibility.

First, you need to list the all installed version of Java. The following command list all installed versions of Java with the default Java version.

update-java-alternatives --list

The results may vary, but this is an example of the output:


java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-8-oracle 1081 /usr/lib/jvm/java-8-oracle

Identify your Java version, in this case, it is java-8-oracle. Then set it as the default with (replacing with the appropriate name from above listed Java versions)

sudo update-java-alternatives --jre --set

 There is another way you can set a default version of Java. Use the following commands

sudo update-alternatives --config java

This command results:


There are 2 choices for the alternative java (providing /usr/bin/java).


Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
* 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode


Press enter to keep the current choice[*], or type selection number:

* is showing your current Java version. The above selections require the index of Java on your choice. For example, type 1 for Java 7 or press enter to keep same.

Congratulations,  you have successfully updated your default Java version.

Thanks

Hyperledger Fabric vs Hyperledger Sawtooth

Hyperledger

Before going through the difference between Fabric and Sawtooth, let’s take a look in Hyperledger.
Hyperledger is project that was initiated by Linux Foundation. Hyperledger is not a blockchain. The goal of hyperledger project is to provide as open source distributed ledger framework that can be used to develop the blockchain applications. Currently there are six projects under the hyperledger.
Fabric
Iroha
Fabric chaintool
Fabric SDK Py
Blockchain explorer
Sawtooth

There is a new project, Corda, expected to be added to the Hyperledger project.
Fabric vs Sawtooth
According to their documentation
Hyperledger Fabric is a platform for distributed ledger solutions, underpinned by a modular architecture delivering high degrees of confidentiality, resiliency, flexibility, and scalability. It is designed to support pluggable implementations of different components, and accommodate the complexity and intricacies that exist across the economic ecosystem.
Hyperledger Sawtooth is an enterprise blockchain platform for building distributed ledger applications and networks. The design philosophy targets keeping ledgers distributed and making smart contracts safe, particularly for enterprise use.

Here are the differences between Hyperledger Fabric and Hyperledger Sawtooth.

  1. Fabric originally contributed by IBM and Sawtooth is Contributed by Intel.
  2. Fabric supports permissioned blockchain network whereas Hyperledger Sawtooth supports both permissioned and permissionless blockchain networks.
  3. Hyperledger Sawtooth can support very large networks in compare to Hyperledger Fabric.
  4. Hyperledger Fabric supports Kafka based consensus whereas Hyperledger Sawtooth supports PoET(Proof of Elapsed Time) consensus algorithm.
  5. Hyperledger Sawtooth uses transaction processor whereas Hyperledger Fabric uses chaincode to write smart contracts.
    The transaction processor functions are converted into chaincode by Hyperledger Composer whereas without using Composer, we need to write our own chaincode.
  6. Sawtooth supports Ethereum Solidity based smart contracts(We can write Sawtooth smart contracts in Solidity) with its Seth Framework which is not supported by Fabric.
  7. The fabric is more secure by using MSP and different CA while Sawtooth has a flexible approach using roles and permissions.
  8. Sawtooth supports transaction batches i.e. either all the transactions in a batch are committed or none of them is committed whereas Fabric decide either a number of a transaction will commit or the block cut time of Kafka brokers.

These are the points that differentiate Hyperledger Fabric and Hyperledger Sawtooth.

Playing with Array of Embedded Documents

MongoDB is a document-oriented database and stores data in BSON(Binary JSON). BSON sup­ports the em­bed­ding of doc­u­ments and ar­rays with­in oth­er doc­u­ments and ar­rays. It is very hard to querying embedded array document if we don’t care. If you afraid of querying with MongoDB array then this blog can help you. Let’s suppose that you have a collection named post. The post has two documents.


db.posts.insertMany( [ 
{ "title"  :  "Playing with Array of Embedded Documents","content"  :  "This is mongodb blog" , "comments"  :  [ { "text" : "very good post" , "user" : 5 , "length" : 14 } , { "text" : "interesting" , "user" : 2 , "length" : 11 } , { "text" : "Nice" , "user" : 5 , "length" : 4 } ] ,"tags" : [  "mongodb" , "embedded" ] },
{ "title" : "Second Blog" , "content" : "Second blogs" , "comments" : [ { "text" : "Like it" , "user" : 3 , "length" : 7 } , { "text" : "interesting" , "user" : 2 , "length" : 11 } , { "text" : "Nice" , "user" : 5 , "length" : 4 } ] , "tags" : [ "mongodb" , "array" ] }
] );

Let’s start querying with embedded array documents.

The following query matches only those documents where the comments array contains at least one element with user equal to 3.


db.posts.find( { "comments.user" : 3 } ).pretty();

Results:


{
    "_id" : ObjectId("5aa67d11bd140cb8e57cd134"),
    "title" : "Second Blog",
    "content" : "Second blogs",
    "comments" : [
        {
            "text" : "Like it",
            "user" : 3,
            "length" : 7
        },
        {
            "text" : "interesting",
            "user" : 2,
            "length" : 11
        },
        {
            "text" : "Nice",
            "user" : 5,
            "length" : 4
        }
    ],
    "tags" : [
        "mongodb",
        "array"
    ]
}

The following query matches only those documents where the comments array contains at least one element with user equal to 3 and length equal to 7.


db.posts.find( { comments : { $elemMatch : { user : 3, length : 7 } } } ).pretty();

You will get the same result as the first query.

In the following query, the projection { “comments.$”: 1 } returns only the first element where a user is 3 and length is 7.


db.posts.find( { comments : { $elemMatch : { user : 3 , length : 7 } } } , { "comments.$" : 1 } ).pretty();

Results:


{
    "_id" : ObjectId("5aa67d11bd140cb8e57cd134"),
    "comments" : [
        {
            "text" : "Like it",
            "user" : 3,
            "length" : 7
        }
    ]
}

The following query returns matched document which has “array” tag.


db.posts.find( { tags: { $all: [ "array" ] } } ).pretty();

Results:


{
    "_id" : ObjectId("5aa67d11bd140cb8e57cd134"),
    "title" : "Second Blog",
    "content" : "Second blogs",
    "comments" : [
        {
            "text" : "Like it",
            "user" : 3,
            "length" : 7
        },
        {
            "text" : "interesting",
            "user" : 2,
            "length" : 11
        },
        {
            "text" : "Nice",
            "user" : 5,
            "length" : 4
        }
    ],
    "tags" : [
        "mongodb",
        "array"
    ]
}

The above queries help, when we are trying to query to embedded array document in MongoDB.

Hope you enjoyed it.

Thanks