Posts

Java 8 | Fetch top N unique numbers from list

Below Java 8 example shows how to fetch top N unique numbers from ArrayList. Traditional looping will require more logic to first remove duplicates, sort numbers and then store N numbers to different list. Java 8 provides stream API to do all the above steps in single line of code.  Descending order (N = 3)

NodeJS | Simple Tweet API

Image
This post is about simple tweet api created using NodeJs and MongoDB. You can get a code from  Github link . Below REST APIs are provided. We need to have Node installed   before using this project. ExpressJS is used with MongoDB to store tweets.

Apache Spark | Run first spark program

Image
In this post we are going to run sample spark program. If you want to setup spark locally go to this post . In the last post we created slave node with 2 cores and 2g memory. This worker node will be used by master to run your spark jobs. Spark installations provides some sample programs to run on cluster. This can be found at below location. We will be running JavaWordCount program locally in spark cluster.

Apache Spark | Setup Spark in local

Image
In this post we are going to setup Apache Spark  in Ubuntu machine. Apache Spark is high performance engine  for Big data such as batches, and streaming of data. Spark provides up-to 100x times speed than any other engines. Spark is compatible with Java, Python, R. Step 1 : Download Spark installations from website . This will download  spark-2.3.1-bin-hadoop2.7.tgz in your local. Extract files from zip as below.

Java | Builder Design Pattern

Java POJO classes can be created using different design patterns. Below is example how Builder pattern works. Normally, Simple java POJO class setter-call has void return type. Builder pattern replace void return type and returns current object of class(ie. return this). Builder pattern can be used to replace parameterised constructor. Also when we create object the code is more readable. Example :

Spring | Autowiring Qualifier

Spring provides @Qualifier annotation to refer correct bean while doing autowiring. Suppose we have interface IService which has two concrete implementation. When we try to Autowire IService object in any other class it will throw exception as there are two beans. Spring Qualifier is used in such situation to place object of correct implementation class to autowired object.   Now, above iservice object will hold object of IServiceImplTwo class.

Spring | JMS Listener via JmsListener annotation

Spring framework provides annotation based configuration for dependency injection. Normally, MessageListener  interface needs to be implemented in Queue/Topic receiver class for incoming messages. The overridden onMessage method in that class handle the incoming message. Spring provides below annotations to enable jms communication. @JmsListener  annotation can mark any method to handle message.  @EnableJms  annotation to detect and register  @JmsListener  methods for jms messages. Below is class to handle jms message. @JmsListener requires default jms container factory configuration. Add below lines in bean conf file for this. Please refer this post for conf file. Deploy war file to JBoss server and send sample message from Gems tool.