Pair-Programming is in my opinion one of the simplest, enjoyable and productive activities in software development but for some reason seems to be one of the hardest practices to be accepted and adopted in many organisations. But why is that?
>>> Pair Programming Antipatterns <<<
Thursday, October 14, 2021
Pair Programming Antipatterns
Saturday, September 11, 2021
What are the prerequisites to successfully implement Trunk Based development?
Recently I wrote an interesting article on Javing's medium page to talk about what are the prerequisites of trunk based development. Click here to find out more:
https://medium.com/javarevisited/prerequisites-for-trunk-based-development-b60e5912e844
Thursday, June 18, 2020
Javing is now on Medium too.
Dear readers of Javing. Recently I decided to publishing also on medium. Don't worry I will never stop publishing here but the reason I decided to expand to the also popular medium platform is because it would increase the visibility of my company. I would kindly ask you if you are a regular reader of Javing, to please follow Javing also on medium. This is the link to the Javing profile on medium: https://javing-uk.medium.com/ once you get there you should see the follow option.
Also I would like to thank you all for reading my articles during all this years and I am looking forward to continue Javing for many more years.
Warm regards to everyone.
Also I would like to thank you all for reading my articles during all this years and I am looking forward to continue Javing for many more years.
Warm regards to everyone.
Saturday, June 13, 2020
Sunday, June 7, 2020
Ubuntu aliases backup
Just some of the aliases I use more freequently. I thought to back them up here in a blogpost.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | # alias management alias a='alias' alias ae='nano ~/.bashrc' alias s='source ~/.bashrc' #docker alias dR='ds;dr;dp;dip;dri;dl' alias dc='docker-compose up -d --build' alias de='sudo dockerd &' alias di='docker images -a' alias dip='docker images purge' alias dl='docker ps -s -a' alias dn='docker network create' alias dp='docker system prune --volumes && docker network prune' alias dpa='docker ps -a' alias dps='docker ps -s' alias dr='docker rm $(docker ps -a -q)' alias dri='docker rmi -f $(docker images -a -q)' alias ds='docker stop $(docker ps -a -q)' alias dst='docker start' alias gdc='g;dc' alias gx='./gradlew build -x test' # gradle and maven alias g='./gradlew clean build --rerun-tasks --no-build-cache' alias gt='./gradlew -q tasks' alias mci='mvn clean install' alias mc='mvn clean' alias mcp='mvn clean package' # java alias homej11='export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/;echo $"JAVA_HOME set to:";echo $JAVA_HOME;s' alias homej8='export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/;echo $"JAVA_HOME set to:";echo $JAVA_HOME;s' alias j11='sudo update-java-alternatives -s java-1.11.0-openjdk-amd64;jv;homej11' alias j8='sudo update-java-alternatives -s java-1.8.0-openjdk-amd64;jv;homej8' alias jv='java -version' # other alias l='ls -CF' alias la='ls -A' alias ll='ls -alF' alias w='cd ~/workspace' |
Saturday, May 23, 2020
docker-compose: setup of spring boot app and it's dependant services
In this video I show how to create an image of a spring boot app that was previously built with gradle and use that image alongside all the other services it depends on. Docker compose is a very useful tool that can help us reduce the complexity of configuring services to be run on docker.
Wednesday, March 25, 2020
How to use JOOQ in a Spring boot application
For more information about the Flyway tool, see this blog post:
http://javing.blogspot.com/2019/01/database-migrations-using-flyway.html
Tuesday, March 24, 2020
Monday, March 9, 2020
Test creation order
Just digging into some old papers today, I found this old note. I think I did screenshot this long ago from a video by Sandro Mancuso.
1. Class name: The class name is post fixed with Should. This is a pattern that was introduced by Sandro in his lectures. Since tests are probably already in the test package, we don't need to know post fix them with the word test, this class name is more BDD friendly and serves as good documentation.
2. Method name: Is concise and it explains what it does without revealing implementation detail. The words are separated with underscore so that it is easier to read than camel case in a first glance.
3. Assertion written first: By writing the assertion first we reduce the risk of introducing assumptions and over engineer. It helps keeping the code minimal and growing it progressively.
4. Action: Once e have our assertion we will write the action. This maybe seems counter intuitive
but as you will notice, as we are writing the assertion and the action, the code is not compiling, this will force us to code the minimum required to make the test compile.
5. Setup: The last step is to add the setup. With this approach we forced our brain to focus on the behaviour and not on the state. This focus on behaviour is the key for growing the code gradually. Thinking on state first rather than behaviour can lead to assumptions and missed requirements.
This is a very interesting approach which has a lot of benefits. What do you think?
Friday, February 28, 2020
Intro to Apache Kafka with Spring
In this application I am creating a simple java micro service that consumes from a kafka topic.
This implementation uses the spring-kafka framework. The code for this example can be found here: https://github.com/SFRJ/offerskafka
Labels:
consumer,
event driven,
events,
java,
kafka,
kafka basics,
microservice.,
producer,
spring,
spring-kafka
Sunday, February 23, 2020
IntelliJ ultimate embedded http client
Did you know that IntelliJ ultimate has an embedded http client that you can use to sent requests to your app? There's no need for external tools like curl or postman, you can just use IntelliJ's endpoints tab. Also this requests can be saved as http files and be used on tests.
Tuesday, February 18, 2020
Kafka F.A.Q
In here a few questions around Kafka that may appear on interviews. As I will collect more, I will add them to this post. Other Java related interview questions, can be found here:
http://javing.blogspot.com/2018/12/java-developer-interview-questions.html
In the context of Kafka, what does back pressure mean?
It means that a slow consumer should be capable of handling throughput coming from a fast producer.
Do you know any solution(other than increasing partitions) to deal with consumers back pressure?
- Increasing partitions
- The consumer signals to the producers that they are sending the data to fast(reactive streams can do this)
- Buffering
Name one advantage and one disadvantage of Kafka?
advantage: using Kafka can reduce the amount of integrations needed in a large ecosystem of applications. This reduction of integrations often results operational cost savings for the company.
disadvantages
disadvantage: order in which events arrived in a multiple partitions scenario is not guaranteed. Using timestamps can help consumers understand the order. If the cluster is being distributed across different time-zones, the event may also need to carry some sort of unique identifier so that alongside the timestamp, the consumer can understand the order.
Can race conditions happen in Kafka and how can we prevent them?
Race conditions with Kafka consumers can happen and one of the main reasons is that in multi partition scenarios, the order of the events is not guaranteed. In order to guarantee ordering timestamps and/or unique identifiers is needed.
http://javing.blogspot.com/2018/12/java-developer-interview-questions.html
In the context of Kafka, what does back pressure mean?
It means that a slow consumer should be capable of handling throughput coming from a fast producer.
Do you know any solution(other than increasing partitions) to deal with consumers back pressure?
- Increasing partitions
- The consumer signals to the producers that they are sending the data to fast(reactive streams can do this)
- Buffering
Name one advantage and one disadvantage of Kafka?
advantage: using Kafka can reduce the amount of integrations needed in a large ecosystem of applications. This reduction of integrations often results operational cost savings for the company.
disadvantages
disadvantage: order in which events arrived in a multiple partitions scenario is not guaranteed. Using timestamps can help consumers understand the order. If the cluster is being distributed across different time-zones, the event may also need to carry some sort of unique identifier so that alongside the timestamp, the consumer can understand the order.
Can race conditions happen in Kafka and how can we prevent them?
Race conditions with Kafka consumers can happen and one of the main reasons is that in multi partition scenarios, the order of the events is not guaranteed. In order to guarantee ordering timestamps and/or unique identifiers is needed.
Saturday, February 15, 2020
Restful app demo and explanation (recruitment code challenge)
Today I did a code challenge that a recruiter gave me. Is for a vacancy at a London company.
I thought to record a demo explaining the code that i implemented and some of my thoughts, just to have here for future reference. I uploaded the code to this repo: https://github.com/SFRJ/offers
In the requirements it says to publish in github, so if I am allowed to publish in github, maybe I am allowed to also publish on the blog and on youtube :)
Here the demo:
bonus using vavr(formerly javaslang)
The exercise said that I could choose any tool I like, I was thinking in doing vavr but since is not so well known maybe the reviewers don't like it. But just for myself I decided to modify the code to use vavr and upload it in a separate repository on github(https://github.com/SFRJ/offersvavr). This a very short video with some of the changes i did to introduce vavr:
The exercise said that I could choose any tool I like, I was thinking in doing vavr but since is not so well known maybe the reviewers don't like it. But just for myself I decided to modify the code to use vavr and upload it in a separate repository on github(https://github.com/SFRJ/offersvavr). This a very short video with some of the changes i did to introduce vavr:
Update(morning after)
When I was uploading the video in youtube i was just previewing and I noticed there was a little bug. I added tests for it and fixed it. Interesting, this situation made me thing about the importance of QA(Quality Assurance). I did not write automated acceptance tests but AAT are basically programmatic quality assurance. Maybe with AAT I woulda catch that but earlier. Doing the technique used to bring QA before code implementation is called ATDD(Acceptance Test Driven Development). Link to article written in this blog some time back on the topic:
I just noticed that in the video I didn't explain that I refactored that overridden cancel method I was talking about at the end, since that method extraction was not really needed if I call again the repository in both get and cancel methods.
Tuesday, February 11, 2020
Design Decisions
I was practising a Kata I haven't done in a while because I wanted to add a recording to the new Page I created dedicated to TDD Katas. The Kata in question was the Roman Numerals Kata (From Roman to Arabic).
After doing the Kata I ended up with this implementation:

This is fine, the solution worked but I just didn't like that those two nested loops seemed a bit of a lot of complexity. Probably not the best solution from the point of view of performance. I wanted to try something else. So I deleted that code and without deleting the tests I wrote this:

To me this seemed a bit better and probably faster. Optimisations are something that we should always postpone. Remember the saying?
After doing the Kata I ended up with this implementation:

This is fine, the solution worked but I just didn't like that those two nested loops seemed a bit of a lot of complexity. Probably not the best solution from the point of view of performance. I wanted to try something else. So I deleted that code and without deleting the tests I wrote this:

To me this seemed a bit better and probably faster. Optimisations are something that we should always postpone. Remember the saying?
Make it run, then make it nice, then make it fast.
Early optimisations can lead to unwanted over-engineering and some other problems. TDD teaches us that we need to grow our code gradually. But then how can we just refactor to something completely different than what we just got?
Once we have written all our tests and we are happy with our refactoring, the tests will act as our documentation, so even if we were to delete all the code and just leave the tests, we could recreate the code. So that is what I did initially to create that second implementation.
Once we have written all our tests and we are happy with our refactoring, the tests will act as our documentation, so even if we were to delete all the code and just leave the tests, we could recreate the code. So that is what I did initially to create that second implementation.
After observing the new implementation and compare it to the previous one, I decided to TDD to see if I could get to the code in the second implementation. I discovered that at the point where I was doing the refactoring after making the test for number 6 pass, here was the place where I could make a design decision and choose not to extract an enum and instead try something else.
This time the Kata has once more proven that TDD is not just capable of making safer code but also drive the design even when we are looking for a faster solution than the one we have.
Here the video for that Kata:
This time the Kata has once more proven that TDD is not just capable of making safer code but also drive the design even when we are looking for a faster solution than the one we have.
Here the video for that Kata:
Sunday, February 9, 2020
Javing.uk launched company website
Recently my company which has the same name as this blog launched it's website under the domain:
https://www.javing.uk/
In the following weeks I will be re-organising a bit the content of the blog and also it's look and feel so that it is more aligned with the company colours and font. I will continue to blog as I often do with the only difference that this blog will now be the official blog of www.javing.uk
https://www.javing.uk/
In the following weeks I will be re-organising a bit the content of the blog and also it's look and feel so that it is more aligned with the company colours and font. I will continue to blog as I often do with the only difference that this blog will now be the official blog of www.javing.uk
Saturday, February 8, 2020
TDD Katas
I am planning to re-organise some of the content of the blog. From now own TDD Katas will no longer be posted as blog posts, instead they will be added to the page "TDD Katas" on this blog under the following url: http://javing.blogspot.com/p/tdd_9.html
Saturday, November 9, 2019
Switch between Java versions using an alias in ubuntu
If you work in a micro-services environment or other type of back end distributed system, it is not rare to see applications running with different versions of Java. In this blog post I am going to show, how you can setup your linux/ubuntu development machine to quickly switch between Java versions.
Let's start by assuming, you don't have any Java installed. We are going to first install 2 versions of Java; openjdk 8 and openjdk 11.
To do so open a terminal and just type this command to install openjdk8:
The installation process should be straight forward, just choose the 'Y' option when prompted.
Once is completed, check the java version
Now let's install openjdk 11
Check the version again
Now you have 2 versions of the JDK installed. You can see all the java versions you have by running this command:
If you want you can ls into the jvm directory
Note that there are some useful simlinks that you could use to refer to the version you want when configuring. But for the scope of this blog I will be using directly the folder names.
A way to manually change the java versions is to just run this:
To change the version of the compiler you can use the same command but with javac instead
But also that's not all, the JAVA_HOME environment variable also needs to be configured. This environment variable is often used by the IDE and other Java technologies tools so it needs to be configured. As you can now see, if you wanted to quickly switch version, this would actually still be slow. Now I am going to explain how to complete the setup for q quick switch between java versions.
Make sure to create the JAVA_HOME variable configured system wide. If is not there make sure you edit that file and you add it.
Notice that I didn't wire the JAVA_HOME into the PATH in there, the reson is because i like to do that in my local .bashrc file. In this file also I have maven, aliases and other things that I think is better not to open system wide.
All we need now, is some aliases that can help us switch between java versions and at the same time configure the JAVA_HOME variable. Add this to the .bashrc files
Note that the command update-java-alternatives will update both the compiler and the jvm versions, in my config I am using the directory name rather than the simlink. to test this just type in the terminal the aliases j8 or j11 to switch between jdk's.
Usage example:
Now, you are all set and ready for Javing! ;)
Let's start by assuming, you don't have any Java installed. We are going to first install 2 versions of Java; openjdk 8 and openjdk 11.
To do so open a terminal and just type this command to install openjdk8:
sudo apt install openjdk-8-jdk
The installation process should be straight forward, just choose the 'Y' option when prompted.
Once is completed, check the java version
java -versionopenjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.10.1-b03) OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
Now let's install openjdk 11
sudo apt install openjdk-11-jdk
Check the version again
java -versionopenjdk version "11.0.3" 2019-04-16 OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.10.1) OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.10.1, mixed mode, sharing)
Now you have 2 versions of the JDK installed. You can see all the java versions you have by running this command:
update-java-alternatives --listjava-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64 java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
If you want you can ls into the jvm directory
ls -l
lrwxrwxrwx 1 root root 25 Sep 20 2018 default-java -> java-1.11.0-openjdk-amd64
lrwxrwxrwx 1 root root 21 Apr 23 2019 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64
drwxr-xr-x 9 root root 4096 Nov 9 08:49 java-11-openjdk-amd64
lrwxrwxrwx 1 root root 20 Jan 14 2019 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64
drwxr-xr-x 7 root root 4096 Nov 9 10:13 java-8-openjdk-amd64
lrwxrwxrwx 1 root root 25 Sep 20 2018 default-java -> java-1.11.0-openjdk-amd64
lrwxrwxrwx 1 root root 21 Apr 23 2019 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64
drwxr-xr-x 9 root root 4096 Nov 9 08:49 java-11-openjdk-amd64
lrwxrwxrwx 1 root root 20 Jan 14 2019 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64
drwxr-xr-x 7 root root 4096 Nov 9 10:13 java-8-openjdk-amd64
Note that there are some useful simlinks that you could use to refer to the version you want when configuring. But for the scope of this blog I will be using directly the folder names.
A way to manually change the java versions is to just run this:
sudo update-alternatives --config java [sudo] password for computername: There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode * 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode Press <enter> to keep the current choice[*], or type selection number:
To change the version of the compiler you can use the same command but with javac instead
sudo update-alternatives --config javac There are 2 choices for the alternative javac (providing /usr/bin/javac). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode * 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode Press <enter> to keep the current choice[*], or type selection number:
But also that's not all, the JAVA_HOME environment variable also needs to be configured. This environment variable is often used by the IDE and other Java technologies tools so it needs to be configured. As you can now see, if you wanted to quickly switch version, this would actually still be slow. Now I am going to explain how to complete the setup for q quick switch between java versions.
Make sure to create the JAVA_HOME variable configured system wide. If is not there make sure you edit that file and you add it.
cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/"
Notice that I didn't wire the JAVA_HOME into the PATH in there, the reson is because i like to do that in my local .bashrc file. In this file also I have maven, aliases and other things that I think is better not to open system wide.
cat ~/.bashrc export M2_HOME=/home/javing/maven export M2=$M2_HOME/bin export PATH=$JAVA_HOME/bin:$M2:$PATH
All we need now, is some aliases that can help us switch between java versions and at the same time configure the JAVA_HOME variable. Add this to the .bashrc files
#My aliases alias jv='java -version' alias j8='sudo update-java-alternatives -s java-1.8.0-openjdk-amd64;jv;homej8' alias j11='sudo update-java-alternatives -s java-1.11.0-openjdk-amd64;jv;homej11' alias homej8='export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/;echo $"JAVA_HOME set to:";echo $JAVA_HOME;s' alias homej11='export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/;echo $"JAVA_HOME set to:";echo $JAVA_HOME;s' alias s='source ~/.bashrc'
Note that the command update-java-alternatives will update both the compiler and the jvm versions, in my config I am using the directory name rather than the simlink. to test this just type in the terminal the aliases j8 or j11 to switch between jdk's.
Usage example:
j11 openjdk version "11.0.3" 2019-04-16 OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.10.1) OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.10.1, mixed mode, sharing) JAVA_HOME set to: /usr/lib/jvm/java-11-openjdk-amd64/bin/
Now, you are all set and ready for Javing! ;)
Labels:
configurations,
development environment,
java,
java 11,
java 8,
jdk,
jre,
linux,
ubuntu
Docker container unhealthy
The other day I was just starting all my docker instances by running docker-compose up -d like I often do, but it started failing telling me that some of the containers were unhealthy.
After running docker logs "0ab31508826c" to see what was going on in the container, I noticed this:

initdb: could not create directory "/var/lib/postgresql/data/pg_xlog": No space left on device
So went to the docker preferences page using the docker GUI to try to find the memory allocation in the disk settings
So there I say that the Disk image size was close to the max. One option was to increase it but I didn't want to do that because it would take unnecessarily more resources from my laptop. I think 64GB is more than enough. So what I just had to do was to delete that file called Docker.raw
results-db is up-to-date
Starting db cnlts_main-db_1 ...
Starting db cnlts_main-db_1 ... done
ERROR: for cnlts-db-flyway Container "0ab31508826c" is unhealthy.
ERROR: Encountered errors while bringing up the project.
After running docker logs "0ab31508826c" to see what was going on in the container, I noticed this:

initdb: could not create directory "/var/lib/postgresql/data/pg_xlog": No space left on device
So went to the docker preferences page using the docker GUI to try to find the memory allocation in the disk settings
The path to that file was written in the gui. I just had to go to that directory and delete it.
rm /Users/<username>/Library/Containers/com.docker.docker/Data/vms/0/Docker.raw
Sunday, September 1, 2019
Easy versioning explanation
Major: for incompatible API changes,
Minor: for backwards compatible functionality
Patch: for backwards compatible bug fixes.
pre-release label and metadata: optional extensions.
Source: https://semver.org/
Source: https://semver.org/
Sunday, June 16, 2019
Enhance your functional java experience with VAVR
In this video I briefly show some features that Vavr has and Java-8 doesn't.
Code examples: https://github.com/SFRJ/vavrExamples
Code examples: https://github.com/SFRJ/vavrExamples
Labels:
example,
functional programming,
java,
javaslang,
vavr
Subscribe to:
Posts (Atom)



