Posts

Showing posts from September, 2022

Java 13 Features

This post is the introduction of commonly used Java 13 features.  Switch expressions: This is still in Preview stage in Java 13 version. The main difference about switch expressions in Java 12 and Java 13 is the introduction of Yeild in Java 13.  Yeild is used to differentiate between Switch statements (Java 11 or less) and Switch expressions (Java 12 or more).  Primarily the new Switch expressions eliminates the need of break statement and also multiple case statements.  Eliminating the break statement reduces lot of verbosity and no need for developers to remember it whenever they use switch. Accidentally if developers forget about adding break statement, it introduces bugs and deviate application to meet business requirements. So using Switch expressions improves efficiency of the code and increases productivity.  Earlier multiple case statements introduced lot of boilerplate code. But with introduction of Switch expressions, we can simply group the related t...

Java 12 features

There are some interesting and useful features available in Java 12. However some are in Preview stage, not for production use. All Preview features are labelled accordingly. Compact Number Formatting Java 12 comes with number formatter the CompactNumberFormat. It was designed to represent number in shorter form based on patterns provided by given locale. NumberFormat shortNumber = NumberFormat.getCompatcNumberInstance(new Locale("en", "US"), NumberFormat.Style.SHORT); shortNumber.format(1000); output: 10k Try what output you get when you try Style.LONG. Teeing Collector in Stream API Collector<T, ?, R> teeing(Collector<? super T, ?, R1> downstream1, Collector<? super T, ?, R2> downstream2, BiFunction<? super R1, ? super R2, R> merger) Every element is processed by both the downstream collectors and their results are passed to merger function. The example of teeing collector is shown below If we want to calculate average from set of num...

How to deploy Spring boot application to JBOSS application server

How to deploy Spring boot application to JBOSS application server Create a spring boot application Open pom.xml and add the below dependency. As you see we added spring-boot-starter-tomcat and set the scope to provided. This is to compile web related components. Make sure the packaging is WAR. <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> <!-- Make sure that you changed the packaging to war --> <packaging>war</packaging> Extend SpringBootServletInitializer class in your Spring boot main class and override the configure method. @SpringBootApplication @EnableSwagger2 public class SpringBootDemoApplication extends SpringBootServletInitializer {   @Override   protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){     return builder.so...

Embedded Tomcat Server configuration in Spring boot application

To modify the default configuration of Spring boot embedded Tomcat server, we can make use of below properties ·        Server.port=80 If you wish to change the port number ·        Server.address=my_custom_ip   IP address where the server would listen ·        By default spring boot provides standard error web page. This page is called white label. It’s enabled by default but if we want to disable it using Server.error.whitelabel.enabled=false ·        Default path of whitelabel is /error but it can be customized using Server.error.path=/user-error ·        To limit the number of simultaneous requests made to the server, use server.tomcat.threads.max=200 ·        Server connection timeout using server.connection-timeout=5s ·        Define max size of request head...