Spring Boot : Set JVM Parameters for an Application

In Spring Boot application, you can set the JVM parameters by two ways so that increase the JVM heap size, in case required you can also configure the other parameters like GC alogorithms, MetaSpace etc.

  • Configure Parameters in pom.xml: To pass the JVM parameters for an application , we can set these parameters in spring-boot-maven-plugin in pom.xml plugin section.
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <jvmArguments>-Xms512m -Xmx1024m -XX:+UseZGC -XX:MaxMetaspaceSize=512m</jvmArguments>
    </configuration>
</plugin>
  • Pass JVM parameters through Command line: We can pass the JVM parameters through the command line while running the Spring Boot application jar file.
java -jar zyz-service.jar -Dspring-boot.run.jvmArguments="-Xms512m -Xmx1024m -XX:+UseZGC -XX:MaxMetaspaceSize=512m"

Note: In both the cases these parameters are as below :

  • -Xms512m : Minimum heap size allocate for JVM as 512 MB.
  • -Xmx1024m : Max heap size can be allocate for JVM as 1024 MB.
  • -XX:+UseZGC : Garbage collection algorithm as Z Garbage Collector.
  • -XX:MaxMetaspaceSize=512m : By default in Java 8 or after the MetaSpace size is unlimited but we can configure fix Max limit also.

Let me know the your thought on this post. If this was helpful for make a comment.

Happy Learning !!!

Build Spring Boot Maven Application from Command Line

In the previous article, you have learned about Spring Boot System Requirements. In this article, you will learn about steps to create Spring Boot Application in the Maven environment.

  1. Check Java Version
  2. Check Maven Version
  3. Create Application in Maven
  4. Add Spring Boot Parent
  5. Add spring-boot-starter-
  6. Add Business Functionality
  7. Build & Run

Here you will know in detail about each step.

Check Java Version

You can run command java -version to get the current java version installed in your machine.

Java Version Check

If you are not getting version as above in screen then follow steps in this link: Setup Java/JDK and Eclipse On Window & Linux

Check Maven Version

You can run command mvn -version to get the current Maven version installed in your machine.

Check Maven Version

If you are not getting version as above in screen then follow steps in this link: Configure Maven in Window and Linux?

Create Application in Maven

To Create a Maven-based Web application, go to the directory where you want to create an application run below maven command.

mvn archetype:generate -DgroupId=com.fiot  -DartifactId=SpringBootMavenApp -DarchetypeArtifactId=maven-archetype-quickstart  -DinteractiveMode=false

Create Spring Boot Maven Application from Command Line

It will create a java maven application with the below directory structure.

SpringBootMavenApp
-src
--main
---java
----com
-----fiot
------App.java
--test
---java
----com
-----fiot
------AppTest.java
-pom.xml

Add spring-boot-starter

Added highlighted lines of the statement in pom.xml to make your application Spring Boot Web Application.

Add Spring Boot application dependencies

Let’s discuss in detail these three sections.

spring-boot-starter-parent: It’s a special starter that inherits useful maven defaults. It also provides dependency management so that omit version tags for dependencies.

spring-boot-starter-web: It’s add in the dependencies section to make application as a web which will add all required dependencies for a web application.

Also See: Spring Boot Starters List

spring-boot-maven-plugin: This plugin is used to create an executable jar of your application.

Add Business Functionality

Now your application is having Spring Boot features. You can add your business functionality as per requirement. In this below code we can create one REST service which returns the response as “Hello World!”.

package com.fiot; 

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*; 

@RestController
@EnableAutoConfiguration
public class App
{    
	
	@RequestMapping("/")    
	String home() 
	{        
	return "Hello World!";    
	}     
	
	public static void main(String[] args) throws Exception 
	{        
		SpringApplication.run(App.class, args);    
	} 
}

Here this main method is the starting point of your Spring Boot application that will start Spring container, create beans, load configuration and perform required actions to start the application.

@RestController: This is stereotype annotation which helps to understand the users and Spring framework like whats the purpose of this class like Spring will consider this class when any web request will come.

@RequestMapping: This annotation provides routing information. In this example, tell Spring that any HTTP request with the path “/” should be mapped to the home method.

@EnableAutoConfiguration: This is class-level annotation, which tells to spring boot to guess how you want to configure spring based on configured starters in class paths and jars. Since in pom.xml we have added spring-boot-starter-web added Tomcat and Spring MVC, the auto-configuration will assume you want to develop a web-based application.

Build & Run

To build your application just go to the root directory of the application and run below command.

mvn package

When you run this command it will take time because download required dependencies from maven repository and after successful compile and package. It will create one more folder as a target in the root of your application.

To run your application use below command.

java -jar ./target/SpringBootMavenApp-1.0-SNAPSHOT.jar

When an application successfully executed then got to the browser and in address bar use this URL http://localhost:8080 after submit you will get a response as “Hello World!!”.

Now your Maven based Spring Boot application is ready, you can add your code based on your project need.

Happy Learning !!!

Build Maven Web Application

To build maven based dynamic web application, Maven provide maven-archetype-webapp archetype artifact. You can follow below steps to create from Dynamic Web application from command line.

Pre-Requisite

Go to directory/ workspace where you want to create maven Java project. Below is command to create it.

mvn archetype:generate -DgroupId=com.{group}.app -DartifactId={App Name} -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Example :

mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=TestMavenWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Because we are creating our first project with maven that’s why it will download lots of jars and dependency from maven repository.

C:\Users\facingissuesonit\workspace-sample>mvn archetype:generate -DgroupId=com.facingissuesissueonit -DartifactId=TestMavenWebApp
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\facingissuesonit\workspace-sample
[INFO] Parameter: package, Value: com.facingissuesissueonit
[INFO] Parameter: groupId, Value: com.facingissuesissueonit
[INFO] Parameter: artifactId, Value: TestMavenWebApp
[INFO] Parameter: packageName, Value: com.facingissuesonit
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.374 s
[INFO] Finished at: 2017-06-09T16:52:33-04:00
[INFO] Final Memory: 14M/148M
[INFO] ------------------------------------------------------------------------

Above command will create project with name TestMavenWebApp in your current directory and will show directory structure as below.

TestMavenWebApp
-src
--main
---webapp
----WEB-INF
-----web.xml
----index.jsp
---resources
-pom.xml

Project pom.xml will have entry as below.

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.facingissuesissueonit</groupId>
  <artifactId>TestMavenWebApp1</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>TestMavenWebApp1 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>TestMavenWebApp</finalName>
  </build>
</project>

Build Project : Go to project directory and run below command to build your project. It will go through all these steps to complete build life cycle as you can see from console logs.It will create war file for your application.

1. validate
2. generate-sources
3. process-sources
4. generate-resources
5. process-resources
6. compile
7. test

mvn package

C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestMavenWebApp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ TestMavenWebApp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ TestMavenWebApp ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ TestMavenWebApp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ TestMavenWebApp ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ TestMavenWebApp ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ TestMavenWebApp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [TestMavenWebApp] in [C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\target\TestMavenWebApp]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\src\main\webapp]
[INFO] Webapp assembled in [65 msecs]
[INFO] Building war: C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\target\TestMavenWebApp.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.352 s
[INFO] Finished at: 2017-06-10T14:37:25-04:00
[INFO] Final Memory: 12M/114M
[INFO] ------------------------------------------------------------------------

Now our build is successful and architecture created by maven is ready. Now time to import this project in eclipse.

Import to Eclipse : To import this project in eclipse first we need to convert this project according to eclipse and then import it.

  • Convert to Eclipse Maven Project : Use below command
    mvn eclipse:eclipse -Dwtpversion=2.0
C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp>mvn eclipse:eclipse -Dwtpversion=2.0
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestMavenWebApp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.10:eclipse (default-cli) > generate-resources @ TestMavenWebApp >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.10:eclipse (default-cli) < generate-resources @ TestMavenWebApp <<<
[INFO]
[INFO] --- maven-eclipse-plugin:2.10:eclipse (default-cli) @ TestMavenWebApp ---
[INFO] Adding support for WTP version 2.0.
[INFO] Using Eclipse Workspace: C:\Users\facingissuesonit\workspace-sample
[WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: C:\Program Files\Java\jre1.8.0_73
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "TestMavenWebApp" to C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.608 s
[INFO] Finished at: 2017-06-09T16:54:24-04:00
[INFO] Final Memory: 14M/115M
[INFO] ------------------------------------------------------------------------

Import in Eclipse : Follow below steps to import TestMavenWebApp project in Eclipse

Eclipse File -> Import -> General-> Existing Project in Workspace -> Select Project TestMavenWebApp

It will show some compile time issue on index.jsp page because   not attached with any Web Server and also select Java compiler version from facet as given screen.

TestMavenWebApp Project -> Right Click ->Properties -> Project Facets

Select Runtime and Java compiler version as configured in class path. Click on apply and OK.

Dynamic Web Application Facet and Server Configuration

Your Project is ready to more development and configured in eclipse . It will have below directory Structure.

Dynamic Web Application Directory Structure

Run Project:

TestMavenWebApp Project ->Run As ->Run On Server

We will get below screen after successful execution.

Deploy Web application

Now your Dynamic Web application is ready, you can create your own pages as per project need.

Happy Learning !!!

Maven Java Application from Command Line

In this below example will show you create maven based java application from commandline and steps to import in eclipse/STS.

Maven provide maven-archetype-quickstart archetype artifact to create maven based java application from command prompt. You can follow these steps to build the application.

Pre-Requisite

Go to directory/ workspace where you want to create maven Java project. Below is command to create it.

mvn archetype:generate -DgroupId=com.{group}.app -DartifactId={App Name} -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Example :

mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=test-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Because we are creating our first project with maven that’s why it will download lots of jars or dependencies from maven global repository.

C:\Users\facingissuesonit\workspace-sample>mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=test-app -DarchetypeArtifactId=maven-archetype
-quickstart -DinteractiveMode=false
 
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\facingissuesonit\workspace-sample
[INFO] Parameter: package, Value: com.facingissuesonit.app
[INFO] Parameter: groupId, Value: com.facingissuesonit.app
[INFO] Parameter: artifactId, Value: test-app
[INFO] Parameter: packageName, Value: com.facingissuesonit.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\facingissuesonit\workspace-sample\test-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.133 s
[INFO] Finished at: 2017-06-06T03:55:59-04:00
[INFO] Final Memory: 14M/148M
[INFO] ------------------------------------------------------------------------

Above example command will create project with name test-app in your current directory and will show directory structure as below.

Test-app
-src
--main
---java
----com
-----facingissuesonit
------app
-------App.java
--test
---java
----com
-----facingissuesonit
------app
-------AppTest.java
-pom.xml

Project pom.xml will have entry as below.

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.facingissuesonit.app</groupId>
  <artifactId>test-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>test-app</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Build Project : Go to project directory and run below command to build your project. It will go through all these steps to complete build life cycle as you can see from console logs.

1. validate
2. generate-sources
3. process-sources
4. generate-resources
5. process-resources
6. compile
7. test

mvn package

C:\Users\facingissuesonit\workspace-sample\test-app>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-app ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\test-app\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\facingissuesonit\workspace-sample\test-app\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-app ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\test-app\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\facingissuesonit\workspace-sample\test-app\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test-app ---
[INFO] Surefire report directory: C:\Users\facingissuesonit\workspace-sample\test-app\target\surefire-reports
 
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.facingissuesonit.app.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec
 
Results :
 
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
 
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-app ---
[INFO] Building jar: C:\Users\facingissuesonit\workspace-sample\test-app\target\test-app-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.372 s
[INFO] Finished at: 2017-06-06T04:07:45-04:00
[INFO] Final Memory: 16M/145M
[INFO] ------------------------------------------------------------------------

Now our build is successful. We can use below command in target folder to run test-app project.

C:\Users\facingissuesonit\workspace-sample\test-app\target>java -cp test-app-1.0-SNAPSHOT.jar com.facingissuesonit.app.App
Hello World!

Import to Eclipse : To import this project in eclipse first we need to convert this project according to eclipse and then import it.

  • Convert to Eclipse Maven Project : Use below command
    mvn eclipse:eclipse
C:\Users\facingissuesonit\workspace-sample\test-app>mvn eclipse:eclipse
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.10:eclipse (default-cli) > generate-resources @ test-app >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.10:eclipse (default-cli) < generate-resources @ test-app <<< [INFO] [INFO] --- maven-eclipse-plugin:2.10:eclipse (default-cli) @ test-app --- [INFO] Using Eclipse Workspace: C:\Users\facingissuesonit\workspace-sample [WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: C:\Program Files\Java\jre1.8.0_73 [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaults suffice [INFO] Wrote Eclipse project for "test-app" to C:\Users\facingissuesonit\workspace-sample\test-app. [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.717 s [INFO] Finished at: 2017-06-06T04:56:14-04:00 [INFO] Final Memory: 12M/114M [INFO] ------------------------------------------------------------------------

Import in Eclipse : Follow below steps to import test-app project in Eclipse

Eclipse File -> Import -> General-> Existing Project in Workspace -> Select Project test-app

Import Maven Java application in eclipse

Now your Maven based Java application is ready to develop your project.

Happy Learning !!!

Java/JDK Setup On Windows and Linux with Eclipse

Before creating the Java project, the first thing is to check to JDK installed or not in your machine.

How to check Java version in your machine?

Window

  • Go to search
  • Type cmd and enter or search for Command prompt
  • You will see a black screen for the command prompt as below.
  • Type java -version to get detail about it.

Linux

  • On the current screen type command as java -version to get detail about it.
Check Java Version

The above screen is for the case when java is installed on your screen. If JDK/JRE is not installed on your machine then you will get a message like “Java is not recognized as an internal-external command.”

How to setup Java from Initial?

If JDK/JRE is not set up in your machine then follow below steps:

Download JDK from this siteDownload JDK Latest Version

Windows

  • After downloading click on the .exe file to install
  • Follow all steps as the next button and continue as long as a process not complete.
  • Default download location for Java will be  “C:\Program Files\Java\jdkVerXYZ”
Java/JDK Directory

To access Java from command prompts or IDE need to configure environment variables as JAVA_HOME and Path. The value of JAVA_HOME would be home directory path where JDK installed and Path would be (JAVA_HOME/bin)

Follow these steps to configure the environment variables

  • Go to Computer ->right click-> Properties -> Advance System Settings->System Variable
  • or Go to search type ENV and click on enter.
  • Enter that value of JAVA_HOME as below
Set JAVA_HOME
  • Set the Path by appending at last as below %JAVA_HOME%/bin;
  • Follow the above steps to check Java versions.

Linux 

  • Download JDK and untar it.
  • Go to your home directory/ sudo directory and set JAVA_HOME and Path in .bashrc file as below:

export JAVA_HOME=/opt/app/<installation directory>/jdk1.8.0_66

          export Path=%JAVA_HOME%/bin:$Path

  •   Save .bashrc file
  •  Now run java -version  to check configuration is successful.

Configure Eclipse IDE

Download Eclipse: Download Eclipse Latest Version

  • Click on the installable of Eclipse IDE.
  • Continue the installation by next click.
  • Select the path of JDK as installed.
  • Select the workspace location for your projects.

Now you are ready to create new projects in Eclipse IDE.

See Also :

Happy Learning !!!

JDK and JRE configuration with Eclipse/STS

To set path of JDK for your project in eclipse follow below steps:

  • Right click on your project -> select properties.
  • Click in Library tab
  • To remove or update JRE/JDK remove existing from list as below.

See Also: Setup Java/JDK and Eclipse On Window & Linux

Eclipse : How to set JDK/JRE Path
  • Click on add Library and select option as “JRE System Library” and click on Next button.
Eclipse : How to set JDK/JRE Path
  • If you need to use existing JRE/JDK you can select from installed JRE or if need to add new one click on Add button.
  • You will get popup of JRE definition. click on Directory option and select JAVA (JRE/JDK) version home directory as in below screen shot
  • Click on Finish button.
Eclipse : How to set JDK/JRE Path
  • Select one Installed JRE which want to use on your project.
  • Click on “Apply and Close” button.
Eclipse : How to set JDK/JRE Path
  • Finally selected JRE/JDK added to your project.
  • Click on “Apply and Close” button.
Eclipse : How to set JDK/JRE Path

Now your eclipse is ready to develop application with configured JDK version.

Happy Learning !!!

Spring Boot Overview

Spring Boot is a Spring module that provides the RAD feature to the Spring framework. Spring Boot makes easy to create a stand-alone, production-based application that can “just run” with very little configuration. It doesn’t generate code and not require an XML configuration.

You can create a Java application that can run by command java -jar or create traditional web application by creating war and deploy on the server.

Note:

  • Spring Boot Current Version: 5.3.15 Release (June 9, 2021)
  • Written in Java
  • Website: https://spring.io/

Spring Boot Advantages

  • Spring Boot Create stand-alone Spring applications that can be started using uber jar i.e java -jar.
  • Spring Boot embed Tomcat, Jetty or Undertow directly. You don’t need to deploy WAR files explicitly
  • Spring Boot provides featured ‘starter’ POMs to simplify your Maven configuration.
  • Spring Boot automatically configures Spring dependencies whenever possible.
  • Spring Boot provides production-ready non-functional features (metrics, health checks, security and externalized configuration) by the actuator.
  • Spring Boot required no XML configuration and also not generate any code.

Spring Boot Disadvantages

Spring Boot also have some of disadvantages as below:

  • Main challenge with Spring Boot is lack of control of developers with starters because install additional dependencies (that often not used) which increase the application deployment file size.
  • Spring boot is good for microservices which are deployed over containers but i would not recommend to use in a large or monolithic based applications.

Spring Boot Features

  • Spring Application
  • Web Development
  • Application Events and Features
  • Externalized Configuration
  • Profiling
  • Properties Files
  • YAML support
  • Type-safe Configuration
  • Logging
  • Security
  • Admin Features
  • Internationalization

Spring Boot Version

  • Spring Boot 0.9 Release in 2002
  • Spring Boot 1.0 Release in 2003
  • Spring Boot 2.0 Release in 2006
  • Spring Boot 3.0 Release in 2009
  • Spring Boot 4.0 Release in 2013
  • Spring Boot 5.0 Release in 2017
  • Spring Boot 5.2.4 Release on February 25, 2020
  • Spring Boot 5.3.15 Release on June 9, 2021

References

Happy Learning !!!

Springboot Framework Exception Hierarchy

Springboot framework having following exceptions. These Spring exceptions occurred while developing applications.

Springboot Framework Exception Hierarchy

To learn more on these Springboot exceptions follow the given links.

Reference

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/NestedRuntimeException.html

Data Structure And Algorithms Complexity (Big-O)

Big-O notation is a mathematical representation used to describe the complexity of a data structure and algorithm. There are two types of Complexity :

  1. Time Complexity: Its measure based on steps need to follow for an algorithm.
  2. Space Complexity: It measures the space required to perform an algorithm and data structure.

Data Structure and Algorithm Decision

Data structure and algorithm decisions are based on the complexity of size and operations need to perform on data. Some algorithms perform better on a small set of data while others perform better for big data sets for certain operations.

These days Space Complexity is not big concerns but the main performance of an algorithm measures based on time complexity. We can make the decision to choose an algorithm based on below performance criteria with respect to Complexity.

ComplexityPerformance
O(1)Excellent
O(log(n))Good
O(n)Fair
O(n log(n))Bad
O(n^2)Horrible
O(2^n)Horrible
O(n!)Horrible
Complexity Level

This post almost covers data structure and algorithms space and time Big-O complexities. Here you can also see time complexities for types of operations like access, search, insertion, and deletion.

See also: 

Data Structure Space and Time Complexity

Data StructureTime ComplexitySpace Complexity
AverageWorst
AccessSearchInsertionDeletion
ArrayΘ(1)Θ(n)Θ(n)Θ(n)O(n)
StackΘ(n)Θ(n)Θ(1)Θ(1)O(n)
QueueΘ(n)Θ(n)Θ(1)Θ(1)O(n)
Singly-Linked ListΘ(n)Θ(n)Θ(1)Θ(1)O(n)
Doubly-Linked ListΘ(n)Θ(n)Θ(1)Θ(1)O(n)
Skip ListΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n log(n))
Hash TableN/AΘ(1)Θ(1)Θ(1)O(n)
Binary Search TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
Cartesian TreeN/AΘ(log(n))Θ(log(n))Θ(log(n))O(n)
B-TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
Red-Black TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
Splay TreeN/AΘ(log(n))Θ(log(n))Θ(log(n))O(n)
AVL TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
KD TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)
Data Structure Complexity

Sorting Algorithms Space and Time Complexity

AlgorithmTime ComplexitySpace Complexity
BestAverageWorstWorst
Quick SortΩ(n log(n))Θ(n log(n))O(n^2)O(log(n))
Merge SortΩ(n log(n))Θ(n log(n))O(n log(n))O(n)
Tim SortΩ(n)Θ(n log(n))O(n log(n))O(n)
Heap SortΩ(n log(n))Θ(n log(n))O(n log(n))O(1)
Bubble SortΩ(n)Θ(n^2)O(n^2)O(1)
Insertion SortΩ(n)Θ(n^2)O(n^2)O(1)
Selection SortΩ(n^2)Θ(n^2)O(n^2)O(1)
Tree SortΩ(n log(n))Θ(n log(n))O(n^2)O(n)
Shell SortΩ(n log(n))Θ(n(log(n))^2)O(n(log(n))^2)O(1)
Bucket SortΩ(n+k)Θ(n+k)O(n^2)O(n)
Radix SortΩ(nk)Θ(nk)O(nk)O(n+k)
Counting SortΩ(n+k)Θ(n+k)O(n+k)O(k)
Cube SortΩ(n)Θ(n log(n))O(n log(n))O(n)
Sorting Algorithms Complexity

Let me know your thought on it.

Happy Learning !!!