D55 Logo

Learning Java

June 14, 2024
May 10, 2024
min read

By Huw Roberts, D55 Senior Software Engineer

Java from a .NET perspective 

Java like C# is a 3rd generation language, and just like C#, Java has its origins in C++, and C previous to that. I have worked with all 4 in my time.

There are lots of similarities between the languages meaning that going from one to the other is easier than you think. Java like C# is an object orientated language, with control statements, loops and flows very similar to C#.

The C# community is HUGE with lots of people moving the language forward, building tools and services, and offering lots of help. The Java community is much smaller, and often if you are coming from a vocal community such as the .NET community, the Java community can feel a little enclosed and answers can be difficult to come by. The other big difference is that in C# a major release comes out every November and the community as a whole really welcomes the new arrival. In the Java world, things are far more understated.

There is an expectation in the Java community that "everyone should know this", to most questions, and it can feel like an uphill struggle to pick up the language, to understand the frameworks, how to talk to databases, how to consume other services, how to test etc. This blog post will hopefully guide you through everything that you need to know to get you going, and for you to enjoy your "Learning Java" journey.


The Java Development Kit (JDK) 

When we write applications with Java, as a starting point we need a JDK. This is equivalent to the SDKs that come with .NET.

Different to .NET where there is 1 installer application that installs all components, in Java we need to install different parts from different locations.

There are many JDKs out there, and many different versions too. Having worked with the JDK from Eclipse Temurin last year and this, this is the one I'm going to recommend. I currently have version 17 LTS installed locally. You can download the JDK here:
Eclipse Temurin JDK (https://adoptium.net/en-GB/temurin/archive/)

Eclipse Temurin do offer a JRE image for Docker too, and that I can recommend too. Slightly off topic, but that can be found here:
Eclipse Temurin JRE for Docker (https://hub.docker.com/_/eclipse-temurin/)


Maven: Compiling, Building, Testing and Packaging Java projects 

In .NET we have MS Build. In Node we have NPM. In Java, with Spring, there is a choice of either Gradle or Maven. My preference is Maven as it's just easier to use, and integrates easily into most IDE, especially the 2 I'm recommending in this blog post.

To find more information about Maven, do look here:
Apache Maven (https://maven.apache.org/what-is-maven.html)

Before you can use Maven, you need to download and install it. Go here:
Download Maven (https://maven.apache.org/download.cgi)


Integrated Development Environments (IDE) 

There are lots of IDEs out there, but my favourite 2 are IntelliJ by JetBrains and Visual Studio Code.

To find more information about IntelliJ by JetBrains, do look here:
IntelliJ by JetBrains (https://www.jetbrains.com/idea/)

To find more information about using Java with Visual Studio Code, do look here:
Java with Visual Studio Code (https://code.visualstudio.com/docs/java/java-tutorial)

I have used both, and enjoyed working in Java with both too. I do a lot of work with Angular in Visual Studio Code, so for that reason alone, I choose IntelliJ as a result for pure Java development.


Learning the Java language itself 

For a deep dive into Java itself do check this up-to-date tutorial out:
Java Tutorial by Geeks for Geeks (https://www.geeksforgeeks.org/java/)

This tutorial goes into the fundamentals of the language: types, variables, classes and objects, I/O, flow-control statements, operators, arrays etc. It's everything you need to know about the language itself. This should be a bookmark/favourite if you are learning Java.


Spring: Java's biggest answer to .NET 

Spring is equivalent to .NET, and it's one of the core Java frameworks and most used core Java frameworks out there. Unlike .NET, there is more than 1 core Java framework, which can get confusing. For this blog post, I will only mention Spring.

More information about Spring can be found here:
Spring by VMware Tanzu (https://spring.io/)

To build Web Applications with Spring, do check this out:
Web Applications with Spring (https://spring.io/web-applications)

To build Microservices with Spring, do check this out:
Microservices with Spring (https://spring.io/microservices)


Building a Web API with Spring Boot and Spring Web 

How do we get started with building our own Web API using Spring Boot? The YouTube video I used as a refresher back in 2023 was this really well put together video by blondiebytes:

The YouTube video can be found here: Learn Spring Boot in 10 minutes | Spring Boot REST API Tutorial (https://www.youtube.com/watch?v=YDRNMAJo0MA) 

You can find more about blondiebytes here:
BlondieBytes (https://www.youtube.com/@blondiebytes)

The Spring Initializer that's mentioned in the video, can be found here:
Spring Initializer (https://start.spring.io/)

An alternative starting point for building an API can be found here:
Building a RESTful Web Service (https://spring.io/guides/gs/rest-service)


Talking to a MySQL database from Java 

Once we have an understanding of how to put a Web API together, the next item that most of us will want to know is how to do we interact with a database.

An excellent YouTube video showing how to create a MySQL database with tables and data, then building a Spring Boot Web API to interrogate that database, and building CRUD services can be found here:

The YouTube video can be found here: Fetch all data in Mysql database using Spring Boot and Postman tutorial | REST API (https://www.youtube.com/watch?v=1UL8Qj-3kKc) 

This is a must watch by United Top Tech. United Top Tech's YouTube channel can be found here:
United Top Tech (https://www.youtube.com/@unitedtoptech6288)

If you are new to MySQL, MySQL is a great Relational Database Management System (RDBMS), that is offered as a service on most cloud providers.

For Amazon Web Services (AWS), check out this great YouTube video: 

The YouTube video can be found here: How to Create a MySQL Database on AWS for FREE! (https://www.youtube.com/watch?v=KVKDT1cmYLs) 

Additional information about the AWS MySQL offering through RDS can be found here:
Amazon RDS for MySQL (https://aws.amazon.com/rds/mysql/)


What about SQL Server? 

Code Java come to our rescue here, with this great YouTube video showing how we can talk to SQL Server from Spring Boot: 

The YouTube video can be found here: Spring Boot Connect to Microsoft SQL Server Example (https://www.youtube.com/watch?v=giG2aNKkoR0) 

Code Java's YouTube channel can be found here:
Code Java (https://www.youtube.com/@CodeJava)

The supporting article for this YouTube explanation can be found here:
Spring Boot Connect to Microsoft SQL Server Examples (https://www.codejava.net/frameworks/spring-boot/connect-to-microsoft-sql-server-examples)


Testing: JUnit 

Most of us who come from a .NET perspective, are well aware of MS Test and NUnit. NUnit comes from JUnit, although the latest version of NUnit is a completely rewritten framework. However, if you've done NUnit, getting to grips with JUnit is very straightforward.

A quick guide comparing JUnit and NUnit can be found here, and this is really helpful:
JUnit vs NUnit: Framework Comparison (https://www.browserstack.com/guide/junit-vs-nunit)

2 YouTube videos that I have found helpful in this area are:

A quick introduction to JUnit: 

The YouTube video can be found here: Java Unit Testing setup in IntelliJ: A Quick Guide (https://www.youtube.com/watch?v=Zi67qUHbq-c) 

Random Code's YouTube channel can be found here:
Random Code (https://www.youtube.com/@Randomcode_0)

And, a more in depth video on JUnit by Coding with John: 

The YouTube video can be found here: Java Unit Testing with JUnit - Tutorial - How to Create And Use Unit Tests (https://www.youtube.com/watch?v=vZm0lHciFsQ) 

Coding with John's YouTube channel can be found here:
Coding with John (https://www.youtube.com/@CodingWithJohn)

The Coding with John YouTube channel is a goldmine of Java videos. Highly recommended!


Testing: What about mocking frameworks? 

The easiest mocking framework I have used with Java is Mockito. This is very similar to using Moq in .NET. I especially like this framework because using the verify function I can both show the happy path, and also making sure that the code has not taken a different path.

The documentation for Mockito can be found here:
Mockito: A mocking framework for Java (https://site.mockito.org/)

A YouTube video showing how to get going with Mockito can be found below:

The YouTube video can be found here: 02 Mockito - Using with IntelliJ (https://www.youtube.com/watch?v=SvSr8bK6F94) 

Computer Science Education's YouTube channel can be found here:
Computer Science Education (https://www.youtube.com/@stephanieallencs)


Bonus: Using Apache Kafka with Java Spring Boot 

Apache Kafka is an "open-source distributed event streaming platform" which I have used this year, and it's surprisingly easy to set up and use. Most seasoned developers and engineers have used some kind of messaging system such as RabbitMQ or AWS SQS in the past. Rather than queues and messages, Apache Kafka deals with topics and messages instead.

A great explanation from Devtiro, of how to use Apache Kafka with a Spring Boot Web API, can be found here: 

The YouTube video can be found here: Stream Big Data: How to use Kafka with Spring Boot (https://www.youtube.com/watch?v=QngHCFFsa00) 

Devtiro's YouTube channel can be found here:
Devtiro (https://www.youtube.com/@devtiro)

More information about Apache Kafka can be found here:
Introducing Apache Kafka (https://kafka.apache.org/intro)


Bonus: Spring Boot with Angular 

A great full length, and very detailed example of how we can use Spring Boot with Angular can be found here:
Building a Full-Stack Web Application with Angular 15 and Spring Boot 3 from SCRATCH (2023) (https://medium.com/@attia.imeed/building-a-full-stack-web-application-with-angular-15-and-spring-boot-3-from-scratch-2023-df12c1e01233)


Other Useful Links 

Getting started with Java 


Java Language 


Learn All About Spring 


OpenAPI 3.0 Specification