Wednesday, July 25, 2018

Simple junit test case with mockito

Mocking is a way to test the functionality of a class in isolation. Mockito facilitates creating mock objects seamlessly. It uses Java Reflection in order to create mock objects for a given interface. Mock objects are nothing but proxy for actual implementations. To know more about mockito, click here.

Maven dependiencies

This is simple junit testing, we will see integration testing in a different article.

Greeting.java
This is the Greeting.java class for which we are writing junit test cases

GreetingTest.java

Find a pair of elements from an array whose sum equals to a given number

The best way would be to insert every element into a hashset. Then for every x, we can just look up its complement, T-x.
Overall the Time Complexity of this approach is O(n).


Simple block chain code with Java

A blockchain is the structure of data that represents a financial ledger entry, or a record of a transaction. Block chain contains list of blocks, each block will contain transaction and a hashcode of previous block. similarly next block will contain its transaction and hashcode of current block thus if any of the transaction value gets change in blockchain subsequent blocks hashcode will change.



If you dont know about hashcode, The hashcode of a Java Object is simply a number, it is 32-bit signed int, that allows an object to be managed by a hash-based data structure.

Transaction.java - It contains transaction information

Friday, July 13, 2018

Spring boot web application with JSP

In this article we will see a sample spring boot web application with front end as JSP

Maven project structure -

Spring boot web application with thymeleaf


In this article we will see a sample spring boot web application with front end as thymeleaf. To know more about thymeleaf, click here.

Note you can use any other view technology like JSP instead of thymeleaf as per your requirement

Project structure -