Mockito when-then vs do-when
Stacktraceguru
by stacktraceguru@gmail.com
2y ago
Writing unit test is very important for better software quality. For unit tests Mockito is one of the most common choices of developers. Mockito providers different way to mock methods, like do…when and when..then. Most of the time we face the question to use when-then vs do-when. We will see all the differences in detail. In Mockito we can mock methods in 2 different ways, Using when-then syntax eg: when(..).thenReturn() or when(..).thenAnswer(…) Using do-when syntax eg: doReturn(..).when() DatabaseService service = Mockito.mock(DatabaseService.class); when(service.isConnected()).thenRetur ..read more
Visit website
Compile and run java9 module program: part2
Stacktraceguru
by stacktraceguru@gmail.com
3y ago
In the previous post we saw baiscs about java 9 modules like, what is module, how to create module project, module descriptor file and so on. In this blog we will learn how to compile and run java9 module program. Recommended read: Java 9 module details: part 1 Table of content Hello world Java 9 module example Compile and run without using modules New argument options added in java 9 Different ways to compile and run modules Java9 Module example for hello world Before going further let’s take an example of hello world module, Let’s dive deeper with an example, for better understanding we wi ..read more
Visit website
Java 9 Modules: part 1
Stacktraceguru
by stacktraceguru@gmail.com
3y ago
In this blog we will go through one of the most important features of java 9, which is ‘Modules’ aka ‘Java Platform Module System (JPMS)’. We will understand everything about JPMS like, what is module? How it helps to add modules? and How to create and use module? Even if you don’t know anything about module don’t worry we got it covered. If you are scared of this new word(‘Modules’), don’t worry once you understand it, it will be very easy. Difference between JDK8 and JDK9 We all know that JRE is the most important part of JDK. But, since java 9, JDK does not contain ..read more
Visit website
Run method on Spring Boot startup
Stacktraceguru
by admin
3y ago
While developing a spring boot application, sometimes we need to run a method or a piece of code at startup. This code can be anything ranging from, logging certain information to setting up database, cron jobs etc. We cannot just put this code in constructor, because required variables or servies may not be initialized yet. This could lead to null pointers or some other exceptions. Why do we need to run code at spring boot startup? We need to run method at application startup for many reasons like, Logging important things or message saying application is started Processing d ..read more
Visit website
Spring boot tutorial
Stacktraceguru
by admin
3y ago
For every Java developer Hibernate, Spring are everyday terms. Although recently there was an addition to this list of ‘Spring-boot’. Now-a-days Spring Boot is one of the most used open source framework. Hence if you are a java developer you must know about spring boot. In this tutorial we will cover srping boot features in detials. Spring-boot can be used to create stand-alone and web enterprise applications with minimal effort. The most important part of this framework is that it makes development very convenient by removing lengthy, repetitive boilerplate code and common configura ..read more
Visit website
Spring boot data jpa-Query for nested object
Stacktraceguru
by admin
3y ago
Nowadays spring boot and spring data are widely used frameworks. If you are building web application in java, spring boot is the first choice. If you have Database then spring data JPA is best choice. In spring boot spring data is the default implementation for database interaction. Spring boot using spring data JPA even creates nested object query from method name. Therefore, if you are using spring boot or spring data JPA, you must know how queries are created specially if you have nested object structure.  Introduction Spring data JPA provides repository abstraction and reduces th ..read more
Visit website
Spring Boot Data JPA- beginner guide
Stacktraceguru
by admin
3y ago
Databases form an integral part of computer applications. With it comes considerable amount of database operations and the corresponding code. For huge applications which have large number of tables/entities, these operations or the code is repeated and duplicated to a large extent. Eventually a programmer would like to reduce this duplicate code. Spring framework took up the challenge and provided us with a solution in the form of Spring Data JPA. Spring Data is one of the most useful feature released by Spring team. JPA stands for Java Persistence API. Spring Data JPA provides repository abs ..read more
Visit website
Different ways to remove Spaces from String In Java
Stacktraceguru
by admin
4y ago
String manipulation is done most often while programming. Like removing spaces in or around the string text. This also known as ‘strip’ping off spaces in the string. So up till now we are all aware of the different ways to remove spaces from string in java, namely trim, replaceAll. However, java 11 has made some new additions to these with methods like, strip, stripLeading , stripTrailing. Majority of the times, we just use the trim method for removing spaces. We never stop and think is there may be a better way to suit our need? Sure, tri ..read more
Visit website
Spring boot custom banner generation
Stacktraceguru
by admin
4y ago
Whenever we start a Spring Boot application a text message shown below is displayed . This is called as a banner. Now, wouldn’t it be wonderful if we could create a custom banner which is specific to our Spring Boot application and use it instead of default Spring Boot banner. There are many ways to generate and use spring boot custom banner. We will cover following topics in detail, Custom spring boot banner generator and generation Configure spring boot application to use custom banner Disable spring boot banner 1. Custom spring boot banner generator and generation For showing the custom ..read more
Visit website
Factory design Pattern in Java – with examples
Stacktraceguru
by admin
4y ago
Factory design pattern is the most commonly used design pattern in today’s programming world. Let’s have the study of this pattern on our agenda here. In this blog we will understand what is the Factory design pattern? When can it be used? What are the advantages and the drawbacks of using this pattern? But, the crucial thing that we learn here today is how to implement the factory design pattern in Java. We will use examples to clarify the concepts of this pattern. At the end of this session, we will achieve 2 goals:  Be able to analyze our requirement or code and decide whether we can ..read more
Visit website

Follow Stacktraceguru on FeedSpot

Continue with Google
Continue with Apple
OR