How to Create Multi-Module Maven Springboot Project

Hello Readers,

Today I will try to explain how we can create maven multi-module project for Springboot applications. There are multiple ways to achieve this like using maven commands but I am going to use a simple approach of using start.spring.io and then importing this created project into eclipse. Then adding the new maven modules.

Lets start.
  1. Navigate to https://start.spring.io/
  2. Select project as Maven Project, Language as Java, Spring Boot version as 2.1.3
  3. Under project matadata, enter group name as something like com.yourcomapny and artifact as project name like patient-service
  4. Under dependencies select what all the dependencies you want like Web, DevTools, Actuators etc

  5. Once the project is created, download and unzip into some location
  6. Open your Eclipse IDE, Click on Import and then import the project into eclipse as Existing maven project and then click finish
  7. Once the project got imported, change the patient-servie pom.xml packaging type to pom as shown in the picture below


  8. Now on the patient-service project, right click --> Maven --> New Maven Module Project


  9. Select the checkbox mentioning Create a simple project and provide module name as patient-service-api and then click finish
  10. Now the new maven module project is been created. After this create one more maven module project by repeating step 8 and step 9 with the new module name as patient-service-app
  11. The intention behind the multi module project creation is that in one module we will keep all the interfaces which might be required to be exposed to outside world and keeping the implementation module hidden with outside world.
  12. Now that we have a parent project and two submodules ready, it’s a time for us to have dependency of patient-service-api module onto patient-service-app like below


  13. Just type few characters of the dependency name and it will display the all relevant dependencies by that name. Select the dependency we need and click OK
  14. Once the patient-service-api dependency is added into patient-service-app module the pom.xml file of patient-service-api will look like below



  15. However, the patient-service-api pom.xml is simple one with no dependencies apart from inheriting the parent patient-service project like below




  16. The parent, i.e. patient-service pom.xml would have all springboot starter dependencies.
  17. Now reactor the main class of patient-service and move that main class to patient-service-app
  18. Right click on that main class from patient-service-app then run as Java application or if you have STS plugins added you can select run as springboot application. This will start the application on the port 8080 by default unless you have explicit port configurations.

So by following all the above steps we can have our multi-module maven springboot project ready for working.

in Java, what are the ways to create an object?

Hi Folks,

After a long time I am back with the new post to discuss about the ways of creating a new object in java.

Basically there are multiple ways in which you can create an object instance in java and those are as below:

1. Using new keyword




2. Using class.newInstance()



3. Using class.getConstructors()


4. Using clone()



5. Using Object de-serialization
Make sure the employee class implements Serializable interface

So these are some of the ways in which we create objects in java. Let me know what did you felt about this blog in comments section.

In java how does HasSet enures unique values?

Let us discuss on how the HashSet in java prevents adding the duplicate values. First let us understand how to create a HashSet and add some values to it.

public class HashSetTest{
    
    public static void main(String[] args)
    {
        HashSet<String> hashset = new HashSet>();
        hashset.add("Bangalore");
        hashset.add("Mysore");
        hashset.add("Hubli");
        System.out.println("Set is "+hashset);
    }
} 


Output would be : Hubli, Bangalore,Mysore

What about the insertion order in the above output? Does the insertion order not maintained? Yes in a HashSet the insertion order is not maintained also the values in a HashSet are not sorted.

Now to the above code let us try to add some duplicates as below:

public class HashSetTest{
    
    public static void main(String[] args)
    {
        HashSet<Object> hashset = new HashSet<Object>();
        hashset.add("Bangalore");
        hashset.add("Hubli");
        hashset.add("Mysore");
        hashset.add("Hubli");          // duplicate elements
        hashset.add("Bangalore");      // duplicate elements
        System.out.println("Set is "+hashset);
    }
}

Now the output would be: Bangalore, Mysore, Hubli
Did you notice add() method of HashSet ignored the duplicates? Now the question is how?
When you pass duplicate elements in the  add() method of the Set object, It will return false and do not add to the HashSet, as the element is already present.

Let us go into further deep:


public class HashSet<E>
extends AbstractSet<E>
implements Set<E>, Cloneable, java.io.Serializable

{
    private transient HashMap<E,Object> map;
    // Dummy value to associate with an Object in the backing Map
    private static final Object PRESENT = new Object();
    
    
    public HashSet() {
        map = new HashMap<>();
    }
    
    // SOME CODE ,i.e Other methods in Hash Set
      
    public boolean add(E e) {
        return map.put(e, PRESENT)==null;
    }  
    
    // SOME CODE ,i.e Other methods in Hash Set
}

So , we are achieving uniqueness in Set internally in java through HashMap . Whenever you create an object of HashSet it will create an object of HashMap as you can see in the italic lines in the above code .

Get selected checkbox value using jquery



In this article I will explain how to check uncheck all (select unselect all) CheckBoxes using jQuery.
The check uncheck all functionality will be done using an additional CheckBox that will act as Check All CheckBox. 


Once you double click on the file which has the same code as above, you will see the result as below: