Posts

Custom Exception Handling For Spring Boot Rest Controller

Image
There can be a scenario where we want to send a custom success or error message as a response to the Rest API call. This can be easily achievable using @ControllerAdvice annotation by implementing Custom Exception Handler. It can be either global error message or controller level messages. Here I am going to explain how to implement a global exception handler in spring boot. Below are the steps to implement custom error response in Spring boot Rest Controller   Implement a custom exception handler by extending ResponseEntityExceptionHandler with @ControllerAdvice annotation. Implement a Custom Exception.  Design a CustomApiException Response Model. Throw custom exception from Rest Service. Step 1 - Implementing a Custom Exception Handler When implementing a custom exception handler either you can implement a custom method to handle the exception or override the default "handleException" method  Example to implement a custom exception handler method  Below exception handler me

Get rid of boring for loop and try using "range" and "rangeClosed"

Most of the Java developer already started using Java 15 but here is the feature in java 8  which  i want  to introduce to the people who doesn't  know about it or may be not using it. Lets see about two static methods  "range()" and "rangeClosed()". Usage  These two methods are available in IntStream and LongStream. IntStream -  IntStream class is an specialization of Stream interface for int primitive. It represents an stream of primitive int-valued elements supporting sequential and parallel aggregate operations.  IntStream is part of the java. util. stream package and implements AutoCloseable and BaseStream interfaces. Syntax range It returns the sequential ordered IntStream .It includes only the startInclusive value . static  IntStream  range( int  startInclusive ,  int  endInclusive) rangeClosed It returns the sequential ordered IntStream .It includes startInclusive and endInclusive values . static IntStream rangeClosed( int startInclusive , int endInclus

Create MultiSelect Dropdown using vue-multiselect

If you are working with bootstrap vue you might be noticed that bootstrap-vue doesn't have a searchable multi-select drop down yet. There are a lot of other vue plugins that provide this feature. I found vue-multiselect as a better one. It supports searchable multi-select dropdown with Vuex. It also has multiple props that can be used to parse option data. Let us create a simple vue-multi-select dropdown . Step 1: Install vue/multiselect via npm           npm install vue-multiselect --save Step 2: Import multiselect component inside vue file where ever its is used              <template>              </template>              <script>               import Multiselect from "vue-multiselect";              export default {              name: "SearchManagedObjectsForm",              components:{                   Multiselect               },              data() {                }             } </script>

Introduction on Extjs

Image
This post will give you a basic idea about ExtJS. Here is the Official website link for ExtJS                             https://www.sencha.com/products/extjs/ what  is EXT JS? Ext JS is the most powerful JavaScript based application development platform. It allows you to create data-intensive HTML 5 applications using JavaScript with cross-browser compatibility. It  is a product of Snecha . Why EXT JS? Ext JS framework allows us to build enterprise application with unified user experience using JavaScript without writing any HTML 5 or CSS code. It also includes lot of built in themes and UI component which reduces your effort on writing HTML and CSS components to build any web applications Features Of EXT JS Supports object oriented programming which makes easy application development and maintenance. Customizable UI widgets with collection of UI components like Grids,forms,charts,tree. Ext JS supports Single Page Application development. Ext JS

Rubber Duck Debugging

Image
                                                                 Hey all i just came across the funny yet useful debugging technique which few of us were actually doing with out knowing about it. Its called rubber duck debugging . We all used to ask for help from our colleagues when we are really in a trouble to solve issues we face in our day to day work.While doing that we would explain our code to them so that your friend can help you to identify  bugs in your code. Rubber duck debugging is nothing but explaining  your code to a physical rubber duck which you can place in your work place :) .and this duck will be your colleague or friend . The goal is while explaining your code to rubber duck you can explore your code by yourself and find missing business logic's or any other bugs with out disturbing your friends and colleagues :) This technique was found as more effective for any programmer to identify issues in their code .Hope you all learnt a new debugging techn

How to create Immutable Class In Java

          How to create Immutable Class In Java Hi all, its been a long time . Was really busy with work :).Got some time now to learn new things again .Today I am going to explain you all how to create immutable class in java.First of all what is immutable ? Immutable means can't be changed once created.  Immutable Class: Immutable classes are the one which cant be extended by any other sub class and should not able to change the value of any mutable and immutable variable inside the class, should not allow the methods to get override. Properties of Immutable Class: Let me tell you the properties an immutable class should hold. Class should be final  All the variable inside the class should be  private final  All the method should be final  Don't create any setter methods  Create a constructor to initialize all the variables Provide a public get method for all the variables, for mutable object clone and return the copy  of the  object . e.g Collec

Handling Custom Object With Java Collections

Image
Hi all, This post is mainly to explain the need of hashcode() and equals() function in java. Why thus all the Wrapper classes have hashcode() and equals() method implementation and they are known as good key for Hashmap?Let me explain it here with custom object example because in all the wrapper class you will be having hashcode() and equals() method implementation by default I am going to have Employee object as a key in Hashmap,when you create your own custom object as a key for Hashmap we need override both hashcode() and equals()  method . This is used to maintain unique property in Hashmap key . Employee class with hashcode and equals method implementation /**  *  * @author Saradha M  * @since 1.0  */ public class Employee { private int empId; private String name; /** * @param empId * @param name * @author Saradha M * @since 1.0 */ public Employee(int empId, String name) { super(); this.empId = empId; this.name = name; } /*