Friday, July 13, 2018

Spring boot web application with JSP

In this article we will see a sample spring boot web application with front end as JSP

Maven project structure -

Spring boot web application with thymeleaf

In this article we will see a sample spring boot web application with front end as thymeleaf. To know more about thymeleaf, click here.

Note you can use any other view technology like JSP instead of thymeleaf as per your requirement

Project structure -

Friday, June 15, 2018

Simple Springboot + hibernate + mysql example

This is a simple spring boot + hibernate (JPA) example.

Below are the tables created in MySQL

create table category
catid int not null auto_increment,primary key (catid),
catname  varchar(30) not null

create table menu
menuid int not null auto_increment, primary key (menuid),
menuname varchar(60) not null,
catid int not null, 
        foreign key (catid) references category(catid)


Here is the pom.xml file

Saturday, December 9, 2017

What is new with Java 9

Being a Java professional, if you were waiting for the big news then finally here it is - Java 9 has been released into the technical workspace recently and the features embedment is just amazing. In this article, we will take a quick tour of the new features introduced in Java 9 and how they can help you in getting your programming skills better.

The modularization with project Jigsaw

After the release of Java 8, Lambdas and improved APIs functionalities changed the daily life of the Java developers. However, one feature that was awaited since a long time to become the highlight of freshly released Java 9 version i.e. modularization with the project jigsaw.

Before modularization, JDK was defined as a programming environment with various undesirable dependencies between different areas of implementation. There was a quick need to eliminate all of these dependencies to get a more modular Java program.

The Jigsaw module system helped in starting compilation with base module only. The Java applications can be started by installing base modules only that are actually needed by the program, not any other undesirable module components. In this way, it will enhance overall runtime and compile-time capabilities with the reliable configuration setting enhanced encapsulation mechanism.

With Java 9, you would be able to design your own modules with the declaration of multiple packages inside. Let us see a quick example, how to create or define modules in Java 9 version.

In this example, we have been used two keywords “exports” and “requires” with significantly different purposes. The “Exports” keyword will tell you about the packages you wanted to show to the outside world. At the same time, the “requires” keyword signifies about the packages you need from the outside. The concept may be a little bit confusing at first glance, but it goes really interesting with practical implementation.

Modules can also be used as classical JAR files inside classpath. In Java 9, modularization concept has replaced the keyword “classpath” with “modulepath” where you can find all the modules declared by you.

Domain-driven design with Java 9

With the introduction of modularization in Java 9, it has become possible for the developers to make software architecture better and more expressive. Now the layers in software architecture can be defined as modules and each of the interfaces can be defined more precisely as compared to the past.

This would be easy for the compiler as well to detect or prevent the architecture violations. Let us have a quick look on domain-driven design with Java 9 –

Saturday, November 4, 2017

What is Garbage Collection log? How to enable & analyze?

Objects are created in the memory to service incoming requests. Once requests are serviced, newly created objects will become useless (i.e. garbage). This garbage must be evicted from the memory so that there is enough room created in the memory to service the new incoming requests. If there isn’t sufficient memory, the application can experience poor response times, OutOfMemoryError, and fatal crashes.
In Java, Android, C#…, garbage collection is automatic, whereas in the several predecessor programming languages (C, C++) – programmer must write code explicitly to release the objects after they are used. So, it’s a major convenience for Java, Android, and C# application developers. But this automatic garbage collection is not free, it comes with a price. Automatic Garbage Collection can have a profound impact on:
1.       Application Response Time
2.       CPU
3.       Memory

Application Response Time

To garbage collect objects automatically, entire application has to be paused intermittently to mark the objects that are in use and sweep away the objects that are not used. During this pause period, all customer transactions which are in motion in the application will be stalled (i.e. frozen). Depending on the type of GC algorithm and memory settings that you configure, pause times can run from few milliseconds to few seconds to few minutes. Thus, Garbage Collection can affect your application SLA (Service Level Agreement) significantly.


Garbage collection consumes a lot of CPU cycles. Each application will have thousands/millions of objects sitting in memory. Each object in memory should be investigated periodically to see whether they are in use? If it’s in use, who is referencing it? Whether those references are still active? If they are not in use, they should be evicted from memory. All these investigations and computation requires a considerable amount of CPU power.


Of course, poor GC configuration can lead to high memory consumption and vice versa. Most applications saturate memory first before saturating other resources (CPU, network bandwidth, storage). Most applications upgrade their EC2 instance size to get additional memory rather to get additional CPU or network bandwidth.
Thus to have top notch SLAs and reduce the bill from your cloud hosting provider, your applications Garbage collection has to be function effectively.
In order to study and optimize Garbage Collections impact on the application’s performance, one has to enable Garbage Collection Logging. Besides that, Garbage Collections logs can be used to troubleshoot memory-related problems in the application.