Blog Archives

♦ Ensuring code quality in Java Q&As

Q1. How do you ensure code quality in your application? A1. Code quality means writing readable, maintainable and robust code, that conforms as much as possible to the style-guideline that is used, and that has as little as possible defects.…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in Code Quality, Coding, FAQs Code Quality, member-paid

♥ 30+ Java Code Review Checklist Items

This Java code review checklist is not only useful during code reviews, but also to answer an important Java job interview question, Q. How would you go about evaluating code quality of others’ work? You also learn a lot from

Posted in Code Quality, Coding, FAQs Code Quality

♥ Selenium and Web Driver Interview Questions and Answers

Q1. What is Selenium? A1. Selenium is a suite of tools for browser automation (i.e. automated Web testing). It is composed of Selenium IDE: A tool for recording and playing back. This is a Fire-fox plugin. WebDriver and RC provide

Posted in Automation Testing Q&A

♥ Unit Testing Data Access Logic in Java

Most interviewers like Java candidates those who are passionate and experienced about writing unit tests. Any non trivial Java application will be making calls to database tables. So, here are a few questions and answers testing your ability to write

Posted in Data Access Unit Testing Tagged with:

♦ 5 Java unit testing interview Questions and Answers

Q1 Why use mock objects in unit testing? A1 Unit testing is widely accepted as a “best practice” for software development. When you write an object, you must also provide an automated test class containing methods by calling its various…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in Best Practice, FAQs Code Quality, member-paid, Unit Testing Q&A

♦ 8+ JMeter performance testing interview Q&As

Performance testing is an important process of any software development. You can bring this up yourself to many open-ended questions like — Tell me about yourself? What are some of your recent accomplishments that you are proud of? Setting up…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in FAQs Code Quality, JMeter, JMeter Tutorial, member-paid, Performance, Performance Testing Q&A

01: JUnit with Mockito step by step

Step 1: Create a simple maven project say “code-quality” Step 2: Import into eclipse. #1. Validator code & unit testing Step 3: Validator interface & implementation Step 4: Write a unit test to test the “ValidatorImpl.java”. Run as junit test.

Posted in JUnit Mockito Spring

01: jvisualvm to sample Java heap memory

Java does not have a sizeof operator like C++ does. Java uses automatic memory management known as the Garbage Collection, hence it is not that important to evaluate size of various objects. But, for the purpose of learning & fixing

Posted in jvisualvm profiling, JVM, Memory Management

02: jvisualvm to detect memory leak – a quick tutorial style Java demo

This is a companion post to 8 Java Memory Management Interview Q&A demonstrating a memory leak scenario step by step with jvisualvm, which is a free profiling tool that gets shipped with JDK. Step 1: Code that causes memory leak

Posted in jvisualvm profiling, JVM, Memory Management

02: Unit testing with JUnit, Mockito & Spring

Step 1: Create a simple Maven project from a command-line. Just press enter for all the prompts. Step 2: Import the above “simple-mocking-test” in the file system into eclipse. File –> Import –> “Existing Maven Projects” and then select the

Posted in JUnit Mockito Spring

03: jvisualvm to debug deadlocks in Java applications

This extends JConsole for debugging deadlocks in Java applications, using jvisualvm that gets shipped with your JDK. Step 1: Java code that creates a dead lock situation by a) thread-0 holding on to lock1 and waiting for the lock2, b)…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in Concurrency, Java Debugging, jvisualvm profiling, member-paid

03: Mockito to fully mock the DAO layer

This extends Part 1: Unit testing with JUnit, Mockito & Spring by mocking the DAO layer with the Mockito framework. Step 1: Service and DAO layer interfaces and implementations Service Layer DAO Layer This layer will be mocked by Mockito…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in JUnit Mockito Spring, member-paid

04: Mockito partially mocking with @Spy

This extends Part 2: Mockito to fully mock the DAO layer by modifying the service layer to demonstrate partial mocking with “Mockito.spy”. In the “SimpleServiceImpl” we are interested in only testing the method “processUser(int id)” and want to mock the…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in JUnit Mockito Spring, member-paid

05: Mockito & PowerMock partially mocking private methods with @Spy

This extends Part 3: Mockito partially mocking with @Spy by making the method “processUser(int id)” as a private method. Mockito framework cannot mock “private” methods, hence the “PowerMock” framework is added to the pom.xml file Step 1: Add “PowerMock” libraries…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in JUnit Mockito Spring, member-paid

06: Mockito & PowerMock for mocking static methods

This extends Part 4: Mockito & PowerMock for partially mocking private methods to mock “static” methods. How to use both Spring JUnit and PowerMock runners? By using the “@PowerMockRunnerDelegate” from the “powermock-module-junit4” jar. So, need to use compatible “Mockito” and

Posted in JUnit Mockito Spring

Integration Unit testing Spring Transaction Management

This is an integration testing that tests Spring transaction through service, and DAO layers all the way up to the embedded database like HSQLDB or H2. After commit or rollback, the number of records in the table are verified. The…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, Testing Spring TXN Mgr

Jacoco for unit test coverage with SonarQube tutorial

This tutorial extends SonarQube with Maven Tutorial – Code Quality for Java developers to use Jacoco for tracking unit test coverage. Jacoco is the default code coverage tool that gets shipped with SonarQube. SonarQube can also be configured to use

Posted in Code Coverage

Java BDD (Behavior Driven Development) interview Q&A

Q1. What is BDD? A1. BDD is principally an idea about how software development should be managed by both business interests and technical insight. Test-driven development focuses on the developer’s opinion on how parts of the software should work. Behavior-driven…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in BDD Testing, member-paid, SDLC

jBehave and BDD example

To appreciate jBehave, let’s look at a better example here. This example is about a science formula   Speed = distance / Time. So, given  distance and time, calculate speed given speed and time, calculate distance given speed and distance,…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in BDD Testing, member-paid

jBehave and jUnit for BDD

This extends the jBehave — Behavioural Driven Development (BDD) Q&A to use the same example with jUnit testing. Step 1:  Make sure that you have both jUnit and jBehave in your pom.xml file. Step 2: Refer to Behavioural Driven Development (BDD)…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in BDD Testing, member-paid

jBehave with tabular story data

This extends the previous jBehave and BDD tutorials. The story is in a tabular format as shown below. This is an industrial strength example. Step 1: The story file  which supplies a list of transactions as an input (i.e. via…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in BDD Testing, member-paid

JMeter for performance testing REST services with BeanShell

This post extends 8 JMeter Performance testing Interview Q&As to cover JSON HTTP post. Now a days, a single page interactive web sites are very popular, and they post JSON based data back to the server to create a new…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in JMeter, JMeter Tutorial, member-paid, Performance, Performance Testing Q&A

JUnit with Hamcrest

Q1. What is Hamcrest, and what is its purpose? A1. HAMCREST is an anagram for MATCHER. The purpose is to match the assertions the BDD (Behavior Driven Development) style. In short, reads better like English statements. So, Instead of: with

Posted in Unit Testing Q&A

Maven and Cobertura Tutorial

Cobertura is a free code coverage tool, which calculates the percentage of Java code accessed by unit tests. Step 1: The pom.xml file with the relevant reporting plugins. The properties also shown to set the coverage percentage and to skip

Posted in Code Coverage, Productivity Tools Tutorial

Part #3: JPA Hibernate Spring Maven Eclipse Tutorial – testing data access with HSQLDB

This tutorial focuses on testing data access logic with spring-test and hsqldb. This extends Part #2: JPA Hibernate Spring Maven Eclipse Tutorial – JPA configs and repository Testing the mapping of entities managed by hibernate and wiring up of JPA,…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in Data Access Unit Testing, JPA-Hibernate-Spring Tutorial, member-paid

Spring Boot in unit testing – 6 things you must know

Q1. What are some of the libraries required for unit testing Spring based Java applications? A1. Spring Test — integration test support for Spring applications. 1. JUnit — for unit testing Java applications. 2. Hamcrest — is a library of…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, Unit Testing Q&A

Spring Controller Unit Testing

This Spring controller unit test is based on HATEOAS RESTFul Service with Spring tutorial. The request URL and JSON response content are shown below. REQUEST URL: http://localhost:8080/simpleSpring/greeting?name=John RESPONSE JSON: {“content”:”Hello, John!”,”links”:[{“rel”:”self”,”href”:”http://localhost:8080/simpleSpring/greeting?name=John”}]} REQUEST URL: http://localhost:8080/simpleSpring/greeting RESPONSE JSON:{“content”:”Hello, World!”,”links”:[{“rel”:”self”,”href”:”http://localhost:8080/simpleSpring/greeting?name=World”}]} The first step

Posted in JUnit Mockito Web

Unit Test Hibernate – DAO Layer with JPA, Spring & HSQLDB

This post extends the previous one on “Unit Test Hibernate – DAO Layer with Spring & HSQLDB“. The changes are 1. Add “persistence-jpa.xml” to src/main/resources. 2. Modify the “entityManagerFactory()” method in the “SimpleConfig.java”. persistence-jpa.xml entityManagerFactory() change

Posted in Data Access Unit Testing

Unit Test Hibernate – DAO Layer with Spring & HSQLDB

Step 1: The pom.xml file with test jars, Spring jars, and hibernate jars Step 2: The HSQL DB schema and data scripts in the src/test/resources folder. sql/schema.sql sql/data.sql Step 3: The Spring configuration for the unit tests in the src/test/java

Posted in Data Access Unit Testing

Unit Testing Servlet filter with Mockito

This assumes that you have gone through the basic JUnit & Mockito tutorials. Here is test class to “Unit Testing Servlet Filter”. The “HttpServletRequest“, “HttpServletResponse“, “FilterChain“, etc are mocked with Mockito. The Spring also provides classes like “MockHttpServletRequest“, etc. Here

Posted in JUnit Mockito Web

Unit testing Spring Transaction Management

Unit testing Spring transaction management –> i.e. commit & rollback scenarios as shown below. On a separate post, will do an integration test for the Spring transaction manager. The test class defines the transactional boundaries. Transaction Commit scenario Transaction Rolback…...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

30-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home
Posted in member-paid, Testing Spring TXN Mgr

Brush-up or learn the basics that will fast-track your career

open all | close all

100+ Java Tutorials by topics

open all | close all