Author Archives: Ajitesh Kumar

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

How to Gradle Spring MVC Web Project

The article describes steps that are required to build the a Spring MVC web application project using Gradle tool. Step 1: Web Application Folder Make sure you have maven-based web application folder. We recommend you to check our article published on different possible layouts of web application folders. As a recap, following is how the web application folder structure would look like: src/main/java (Consists of Java files) src/main/resources src/main/scripts src/main/webapps: This would further have following folder structure: assets (publicly accessible files) css js images META-INF WEB-INF lib (spring/hibernate & other libraries) views (jsp files) hibernate.cfg.xml (if hibernate is used as well) spring-servlet.xml web.xml   Step 2: Create a Gradle Script …

Continue reading

Posted in Java. Tagged with , .

Google Datastore Query Get By ID & Filter – Code Example

Following are code samples on Google App Engine Datastore Query and how to get entities by id and based on filters. Get Entity By Id Pay attention to the code “datastore.get(KeyFactory.createKey( “savedreport”, reportId). “savedreport” is the name of entity. DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Entity entity = null; try { entity = datastore.get(KeyFactory.createKey(“savedreport”, reportId)); } catch(EntityNotFoundException e) { e.printStackTrace(); }   Get Entity By One Filter Pay attention to “setFilter” method Filter createdByFilter = new FilterPredicate(“created_by”, FilterOperator.EQUAL, userId ); Query query = new Query(“sqm”).setFilter( createdByFilter ); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); List entities = datastore.prepare(query).asList( FetchOptions.Builder.withLimit( count ) );   Get Entity By Multiple Filter Pay attention to usage of multiple FilterPredicate …

Continue reading

Posted in Java. Tagged with , .

Code Example – User Authentication with Google App Engine Java Applications

The article presents quick code samples that could be used to adopt Google User authentication service. These strategies have been used in the google app, http://agilesqm.appspot.com. Following key aspects are presented in this article. Web.xml configuration to restrict access to pages Use Google User service   Web.xml configuration to restrict access to pages With following code in web.xml, one could restrict access to one or more pages in matter of no time. You could try on how below configuration works by accessing the page, http://agilesqm.appspot.com/createreport and you would be sent to Google login if not yet logged in on the browser. <security-constraint> <web-resource-collection> <web-resource-name>createreport</web-resource-name> <url-pattern>/createreport</url-pattern> </web-resource-collection> <auth-constraint> <role-name>*</role-name> </auth-constraint> <user-data-constraint> …

Continue reading

Posted in Java. Tagged with , .

7 Reasons for Java Developers to Adopt Google App Engine

The article represents top 7 reasons why one would want to adopt Google App Engine to do quick Java applications. If you are a bunch of java developers who wants to try out your idea and give a demo to a select group of users, I would recommend you to try out google app engine. Following are top 7 reasons: Eclipse IDE Support As Google supports Eclipse IDE plugin for working with google app engine, it is very helpful to get started quickly in no time. All that is required is download Google App Engine plugin within your Eclipse and start immediately by creating a Google web application. You would find …

Continue reading

Posted in Java. Tagged with , .

Code Example – How to Make AJAX Calls with Java Spring MVC

This article is aimed to provide quick code samples to rookies who would like to quickly get started with AJAX while working with Spring MVC based web application. In example below, the AJAX call is made on form submit to retrieve data from server and process it further. Step 1: Get JQuery Library Download JQuery library and place it in JS folder within one of your web assets folder. Even simpler, include following google script code and you are all set.   Step 2: Create a Form Create a form such as following that would be dealt in this example.   Step 3: Create AJAX Code Step 3 is about …

Continue reading

Posted in Java. Tagged with , .

How to Convert JSON String to Google Datatable for Google Charts

The article presents the solution to some of the issues that I faced while converting JSON string to Google Datatable. The primary reason for me to write an article on seemingly looking trivial issue is that I ended up spending lot of time in doing research and reaching to the solution.   Problem Scenario/Issues One AJAX request is made to the server to retrieve the JSON data and draw the Google chart (LineChart in this example) using this JSON data. Following is how the JSON data looks like after being sent from the server-side code: {cols: [ {id: ‘task’, label: ‘Task’, type: ‘string’}, {id: ‘hours’, label: ‘Hours per Day’, type: …

Continue reading

Posted in Java. Tagged with , .

Code Samples to get started with Google Charts & Visualization APIs

sample google chart

The article describes on some of the aspects related with Google Visualization APIs and how to quickly get started with it. To be able to do justice with this blog and more related blogs to come in near future, I went ahead and create a project, AgileSQM, on Google App Engine (cloud) and used following technologies to create a sample chart as shown below: Google App Engine as platform with Jetty as underlying web server Google NoSQL Datastore Google Visualization APIs  Spring MVC (Component model) Bootstrap (UI framework) Eclipse IDE (with Google App Engine platform) Helpful Bookmarks on Visualization APIs While getting started with Google Visualization APIs and working on …

Continue reading

Posted in Java. Tagged with .

HTML Div, Span & Table From Non-HTML Horse’s Mouth :)

Honestly speaking, I have been, primarily, focusing all my energy on programming languages such as Java, PHP, Scala, Haskell etc and Javascript recently, and not really doing enough on HTML/CSS side. However, to try some of my ideas, I do use to pick up code for HTML/CSS from different pages after searching from Google. Over a period of time, this helped me to gain a perspective on what is “div” and “span” and what is the difference between “Div” and “Table”. Interestingly, I found these topics presenting challenges to rookie HTML/CSS developers in terms of understanding when to use what? I have tried to present my understanding of “Div”, “Span” and …

Continue reading

Posted in Web. Tagged with .

Spring MVC Web with Google NoSQL Datastore on GAE Cloud

The article represents key aspects of integrating your Spring MVC web application with Google NoSQL Datastore while working on Google App Engine cloud computing platform. Additionally, it presents code samples for you to get started in a quick manner. You may access the sample application talked about in this article on this page, Welcome to GAE World! Following has been discussed: High-level architecture & design Setup NoSQL Data Model (NoSQL data entity vis-a-vis Google Datastore) Implementation including code samples such as following: Controller (HelloController) JSP (hello.jsp) DAOs (GoogleDSCommentDAO) High-level Architecture & Design Following are key technologies used for the implementation discussed in this article: Spring MVC Google Datastore (NoSQL Database) …

Continue reading

Posted in Cloud, Java. Tagged with , .

5 Steps to Get Spring MVC Web Application on Google App Engine

The article represents steps on what you need to do to get your first Spring MVC Hello World web application project on Google App Engine (GAE). As a pre-requisite, we recommend you to check our earlier article on How to get started with Google App Engine. The article would help you to quickly get your started with GAE based web development using Eclipse IDE. We shall work  with our existing Non Spring MVC project (check this page) and convert it into Spring MVC based web application. Step 1: Spring MVC Libraries Get Spring MVC libraries within folder (war/WEB-INF/lib). Also, do not forget to get following two runtime dependent libraries: commons-logging-1.1.3.jar …

Continue reading

Posted in Java. Tagged with .

How to Get Started with Google App Engine Java Project

hello world code samples

The article presents quick tips to get started with your next Java Web Application on Google App Engine (GAE). I was able to create my first web application on Cloud (GAE) named as “The Coders Shop”,  in couple of hours, however, with little hiccups which I have mentioned in this article. Pre-requisites Following are pre-requisites to get started quickly: Create a Google account. This would be used to create an App Engine Id that would represent your web application on the web. For an app engine id, xyz, the web URL of your application will be xyz.appspot.com. You could alternatively create App Engine Id right from within Eclipse shown below. …

Continue reading

Posted in Java. Tagged with .

Java Functional Interface Explained with Code Samples

The article aims to describe functional interface in Java 8 with the help of hello world code samples. What is Functional Interface? Simply speaking, a functional interface is the plain old Java interface with JUST ONE and ONLY ONE abstract method also termed as the functional method. However, that does not stop functional interface to not contain default and static methods. Following is an example of a functional interface: @FunctionalInterface public interface HelloInterface { // Abstract method void sayHello( String name ); // Static method static void sayThanks() { System.out.println( “Thank You!” ); } // Default method default void sayHelloWorld() { System.out.println( “Hello World!” ); } } Observations: In the …

Continue reading

Posted in Java. Tagged with .

What does Interface in Java 8 Look Like?

Before we go into looking at different aspects of interface in Java 8, lets look at some of the definitions found on some of the source-of-truth websites that seem to contradict the definition of Interface in Java by defining it with a generic definition despite the fact that interface got evolved (such as below 🙂 and has got a new definition in Java 8. Whether or not, the evolved interface in Java 8 is a good move, is beyond the scope of this article. However, please feel free to share your comments. Lets look at some of the following definitions of a Java interface I took from the web at the time of …

Continue reading

Posted in Java. Tagged with .

Learn Functional Programming Before Java Lambdas, Functional Interfaces

As Java 8 got out-of-door, I wanted to quickly get on board with understanding and writing Lambda expressions and functional interfaces. But it was not easy like previous Java versions. And, the primary reason is the different programming paradigm one needs to understand in order to make use of Java Lambdas and functional interfaces concepts. And, this programming paradigm is functional programming. In one of the pages on functional programming (FP) I came across, it spoke about the change in thinking/mindset one, especially OOP developer, needs to bring in order to do a great job with functional programming. This is primarily because in OOP world, objects are first class citizens …

Continue reading

Posted in Programming. Tagged with .

Java 8 Lambda Expressions Examples using Calculator Implementation

lambda expressions examples

The article demonstrates the Lambda expressions using Calculator (interface) code samples. It also makes use of Functional interfaces from java.util.function package to demonstrate Calculator implementation using BiFunction and BinaryOperator interfaces. Calculator Implementation Demonstrating Lambda Expressions The Calculator methods implementation would be explained using both, traditional approach and the approach making use of Lambda expressions. Traditional Approach Using traditional approach, many would have gone implementing Calculator add, substract, multiply and divide function based on following: Define a Calculator interface with four methods namely add, subtract, multiply and divide; Another approach could be to create a single method with an operation flag and provide conditional implementation based on flag. Create a CalculatorImpl …

Continue reading

Posted in Java. Tagged with .

Java Unit Testing Interview Questions

ATG interview questions

The article presents some of the frequently asked interview questions in relation with unit testing with Java code. Please suggest other questions tthat you came across and I shall include in the list below. What is unit testing? Which unit testing framework did you use? What are some of the common Java unit testing frameworks? Ans: Read the definition of Unit testing on Wikipedia page for unit testing. Simply speaking, unit testing is about testing a block of code in isolation. There are two popular unit testing framework in Java named as Junit, TestNG.   In SDLC, When is the right time to start writing unit tests? Ans: Test-along if …

Continue reading

Posted in Interview questions, Unit Testing. Tagged with , , .