Spark Java AJAX post example using JQuery

This post is very similar with the Spark Java example with JQuery Ajax except here we would use POST method for the Ajax call. Like the other example, we would get input of two numbers from the web page UI, make a ajax POST call to server with those numbers, the numbers get added at the server and returned result and finally display the result to web page UI without refreshing the page.

Spark Java example with AJAX JQuery

Spark is a relatively new, simple and lightweight framework written in Java which helps developers to rapidly create web services in minimal effort. It comes with embedded Jetty web server which hosts the web services. The syntax of declaring web services are very simple, quite similar with Node.js, which makes Node.js developers learn SparkJava quickly. Spark framework only works on Java 8 as it is built on Java 8’s Lambda philosophy.

Create thread in Java

The Thread class is the main class for creating and executing thread in Java. We can use this class in two ways: 1. Create a subclass of Thread class and overriding it’s run() method. 2. Create an instance of Runnable interface and creating a Thread object with this. Note: The Thread class is also implementing Runnable interface. Now let us see this two approaches with code examples: 1. Thread class with overriding run() method Create a subclass named SampleThread extending Thread:

Gradle Hello World Example Java

What is Gradle? Gradle is a very popular build tool today in the ecosystem of Java based languages. Although it can be used for other languages as well. Gradle is based on the principal of convention over configuration which is also been popular with Maven. Unlike XML in Maven, Gradle uses Groovy for its language which makes it a very powerful tool. One can do almost anything using Gradle. It has very good plugin system with various ready-made plugins available which can be used for different situations / environments / purposes.