Category Archives: Java

Maven – How to Build Jar Files and Obtain Dependencies

This article represents facts on what would it take to build one or more jar files for a given framework/library using Maven, provided the framework’s downloadable files consisted of pom.xml. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. So far, whenever I came across pom.xml file in the framework that I downloaded in order to get the jar file, I hated it. I used to, then, go to internet and get the compiled jar file(s) for the framework/library. And, good thing is that I have been able to get my work done. This was purely out of my …

Continue reading

Posted in Java, Tools, Web. Tagged with .

Java – How to Get Company Updates using LinkedIn API

This article represents code samples and changes that need to be done in original Linkedin-J framework (open-source) to get company updates of different types such as following: Job Posting Status Updates New Product Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.   Code Samples & Steps to Get Company Updates Following files need to be changed along with mentioned changes: LinkedinApiUrls.properties: Following code needs to be added under APIs mentioned under companies: com.google.code.linkedinapi.client.getCompanyStatusUpdates=http://api.linkedin.com/v1/companies/{id}/updates{queryParameters} LinkedInApiUrls.java: Following code needs to be added: public static final String GET_COMPANY_STATUS_UPDATES = linkedInApiUrls.getProperty(“com.google.code.linkedinapi.client.getCompanyStatusUpdates”); CompaniesApiClient.java: Following APIs need to be added: /** * Gets the …

Continue reading

Posted in Java, Web. Tagged with , .

Java – How to Scrape Web using Multi-threading (ExecutorService)

This article represents code examples on how to Scrape multiple URLs at once using Java Multi-threading API such as ExecutorService.  The sole reason why I have been doing scraping lately is the need to get data from web to apply data analytics/science (machine learning algorithms) and extract knowledge from the data. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following are three different methods whose code samples have been presented below: scrapeURLs that takes input file consisting of URLs to be scraped and output file where the output needs to be written scrapeIndividualURLs which takes as an argument, URL …

Continue reading

Posted in Java, Web. Tagged with .

Java – How to Create Binary Search Tree for String Search

This article represents code samples and high level concepts for creating a binary search tree to do String related operations such as some of the following: Search one or more words Replace word with new word Find number of occurences of a given word in a string For those who are new to Binary Search Tree, note that Binary Search Tree is defined as tree that satisfy some of the following criteria: Each node in the tree has at most only two children Each node is represented with a key and associated data Key in left children is less than the parent node and key in the right node is …

Continue reading

Posted in Java, Web. Tagged with , .

Java – How to Create a Binary Search Tree

This article represents the high level concept and code samples which could be used to create a binary search tree in Java. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following are the key points described later in this article: What is a binary search tree? What are different kind of traversals? Code Samples What is a binary search tree? A binary search tree is a binary tree in which every node contains a key that satisfies following criteria: The key in left child is less than the key in the parent node The key in the right …

Continue reading

Posted in Java, Web. Tagged with .

Java – One-Liner Lambda Expression to Print Map/List Objects

This article represents code samples to print element of collections such as Map and List/Set using lambda expression. I just love it as it has made life so simpler by helping me achieve this using just one line of code. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following are the key points described later in this article: Print Map key-Value Pair using Lambda Expression Print List value using Lambda Expression   Print Map key-Value Pair using Lambda Expression Pay attention to forEach function that takes a reference to BiConsumer function interface and prints the key and value. This …

Continue reading

Posted in Java, Web. Tagged with .

Java – Map & BiConsumer Function Lambda Expression Example

This article represents code samples representing lambda expression and the related ease with which one could print key and value of a Map object using one liner. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Code Sample – Printing Map using BiConsumer Functional Interface Following is detail for Map.forEach API in Java 8. Read further on this page. default void forEach(BiConsumer<? super K,? super V> action) Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in …

Continue reading

Posted in Java, Web. Tagged with .

Java – How to Scrape Content from a URL

This article represents take-away code sample that could be used to get or scrape content from a given URL. Those wanting to do a quick web scrape could use this piece of code. I shall be posting a series of blogs which would help one to create a web scraper using Java. The reason why I am hooked to Java web scraping is the need to get the data from web for data analysis. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Code Sample – Get Content from URL Pay attention to some of the following aspects of fetching …

Continue reading

Posted in Java, Web. Tagged with .

Java – Top 10 Java-based Web Frameworks for 2014-2015

This article represents an analysis on Java-based web frameworks that emerged in the top 10 list this year 2014, and  worth consideration for your next project starting this year or next year (2015). I have done data analysis based on following: Job openings (as of today) on a very popular website, indeed.com Discussion threads (for this year) on a very popular Q&A based website, stackoverflow.com Responses on a very popular social bookmarking website, reddit.com Based on the analysis of top 10 frameworks, I have listed the top 5 frameworks which emerged as clear winner. Please feel free to comment/suggest if I missed to mention one or more important frameworks. Also, …

Continue reading

Posted in Java, Web. Tagged with .

Java – Top 5 Exception Handling Coding Practices to Avoid

exception handling coding practices

This article represents top 5 coding practices related with Java exception handling that you may want to watch out for or better say, avoid, while doing coding for exception handling. Recently, I have been involved with code review of multiple Java projects and found following as most commonly seen coding instances across various Java projects. As a matter of fact, I recently ran sonar code analysis on Spring Core project (Spring Framework) and found the below mentioned instances related with exception handling. Please note that these are suggested to be avoided as a general coding practice and do not mean that they can not be used at all. There are …

Continue reading

Posted in Java, Web. Tagged with .

AngularJS – Single Page App with RESTful APIs & Spring MVC

Single Page App with AngularJS

The article presents recipe to create single page application with AngularJS & Spring MVC where different pages are required to do transactions with server using RESTful API. The demonstration is created on this page, http://hello-angularjs.appspot.com/angularjs-single-page-app-restful-apis. Code samples and related concepts are presented for following requirements of single page app: Initially one page is loaded with side navigation. Clicking on side navigation loads new view (data) from server by consuming RESTful API using ngResource, $resource service with “query” action method Clicking on individual items link loads the related data from server, again by consuming RESTful API using ngResource, $resource service with “get” action method Submitting a set of data consumes a …

Continue reading

Posted in Java, Javascript. Tagged with , .

AngularJS – Post Data with ngResource, RESTful APIs and Spring MVC

angularjs restful api

  The article presents concepts and some take-away code samples for developers wanting to POST data to RESTFul APIs using ngResource ($resource) service with SpringMVC on server side. The demo for this example could be found on this page, http://hello-angularjs.appspot.com/angularjs-restful-apis-post-method-code-example.   The primary reason why I loved this approach rather than using $http service is the fact that using ngResource allows you to have abstraction such as a $resource class & its instance on which you have action methods to interact with RESTful APIs. It makes it quite easier to work with RESTful integration. On $resource class object, one could directly call action methods such as get, save. However, on …

Continue reading

Posted in Java, Javascript, UI. Tagged with , .

AngularJS – Consume RESTful APIs with ngResource or $http

angularjs restful api

  The article presents concepts and code samples on how to consume RESTful APIs with help of AngularJS $resource or $http service. The server side code is written on top of Spring MVC framework. Please feel free to point out suggestions on this blog.Following are key techniques using which one could consumer RESTful APIs Use low-level $http service to retrieve data using GET method. The demo could be found on this page Use $resource service to retrieve data using GET or QUERY action method. The demo could be found on this page   RESTful APIs with Low-level $http Service One could directly use low-level $http service to consumer RESTful APIs …

Continue reading

Posted in Java, Javascript, UI. Tagged with , , , .

AngularJS – How to Post JSON Data using AJAX & SpringMVC

The article presents code samples that one could use to quickly get started with posting JSON data using AngularJS  $http service while working with SpringMVC web application. The demo for the code below could be found on this page, http://hello-angularjs.appspot.com/angularjs-http-service-ajax-post-json-data-code-example.  Earlier, I posted this article where one could post the html data (text/html) using AJAX & SpringMVC. Following are key steps: Create SpringMVC Controller methods and a POJO Create AngularJS Controller Method Create View   SpringMVC Controller methods and a POJO Following are key steps: Create a controller method to access the page consisting of UI that will be posting using AJAX Create a controller method that shall be receiving the …

Continue reading

Posted in Java, Javascript. Tagged with , , , .

AngularJS & SpringMVC – How to Fix 415 Unsupported Media Type Error

  The article presents tips on how to fix 415 Unsupported Media Type error while working with AngularJS & SpringMVC web application when one tries to POST JSON data using $http service. The sole reason I wanted to write this blog is to help many of my friends who are most likely to hit this one when they work on posting JSON data to SpringMVC web controller using $http service. Possible scenarios: Most likely, you might not have included Jackson libraries in the classpath. Thus, go to http://wiki.fasterxml.com/JacksonDownload and download all the jar files. Alternatively, get slightly back-dated version of all of the libraries in one jar file from http://www.java2s.com/Code/Jar/j/Downloadjacksonall199jar.htm. …

Continue reading

Posted in Java, Javascript. Tagged with , , , .

AngularJS – How to POST Data using AJAX & Spring MVC – Part 1

The article presents the code example that one may use to post data to server using AngularJS $http service, while working with Spring MVC web application. The same is demonstrated in the following page: http://hello-angularjs.appspot.com/angularjs-http-service-ajax-post-code-example. This article is first in the series of articles on different techniques that could be used to POST different formats of data to the server when working with AngularJS and Spring MVC. In this article, the code samples demonstrate how to post plain HTML text data (text/html) format to the server. Following are key steps: Create Spring MVC web controllers methods Create AngularJS controller method using $http service to post data Create view to receive input …

Continue reading

Posted in Java, Javascript. Tagged with , , , .