Skip to main content

Posts

Showing posts from September, 2019

Java-Comparable and Comparator with example

Comparable Interface and Comparator Interface in java are very useful for sorting the collection of objects

Comparable Interface in Java with Example
The Comparable interface has compareTo(T obj) method which is used by sorting methods, you can check any Wrapper, String or Date class to confirm this. We should override this method in such a way that it returns a negative integer, zero, or a positive integer if “this” object is less than, equal to, or greater than the object passed as an argument.Comparable is present in java.lang package.We can sort the list elements of Comparable type by Collections.sort(List) method.

Example:

Consider a Employee class that has members like, username, userid,   year of join. Suppose we wish to sort a list of Employee based on year of join.We can implement the Comparable interface with the Employee class, and we override the method compareTo() of Comparable interface.
//A Java program to demonstrate use of Comparable //A class 'Employee' that implem…

WebSocket + Spring boot web application example with source code download

In this article, we will show you how to develop a Simple Spring Boot web application with WebSocket
Why WebSocket?
We already know traditional HTTP requests are unidirectional and heavy.But WebSocket is bi-directional.The initial connection is using HTTP, then this connection gets upgraded to a socket-based connection. This single connection is then used for all future communication.The WebSocket message data exchange is much lighter compared to HTTP
Following technologies stack being used:

Spring Boot 2.1.4.RELEASESpring 5.1.6.RELEASE JDK 1.8Eclipse OxygenBootstrapThymeleafWebSocket
User Interface

Project Structure
Pom.xml[maven]
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
 …

Spring Boot-Angular-Bootstrap-JPA-CRUD

In this article, we will show you how to develop a Spring Boot CRUD  application with, Angular, embedded Tomcat and JPA
Following technologies stack being used:
Spring Boot 2.1.4.RELEASESpring 5.1.6.RELEASE Angular JSJDK 1.8Eclipse OxygenBootstrapThymeleafH2DB -in-memory database User Interface
Project Structure

Pom.xml(maven) <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <parent>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-parent</artifactId>   <version>2.1.4.RELEASE</version>   <relativePath /> <!-- lookup parent from repository -->  </parent>  <artifactId>springboot-jpa-Angular-bootstrap-CRUD&…