5 Reasons why Java developers love Angular!
Tags: angular, java
Published: 2022-07-21 21:12:37

---
title: 5 Reasons why Java developers love Angular!
published: true
description: Here are five reasons why Java developers love Angular. The list is not exhausted but merely an observation from my own experience.
tags: angular, java
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wstpkj222i73sp3c10bc.jpeg
# Use a ratio of 100:42 for best results.
canonical_url: https://nixamani5.medium.com/5-reasons-why-java-developers-love-angular-68401d3e40ee
---

Here are five reasons why Java developers love Angular. The list is not exhausted but merely an observation from my own experience.

Note this article is not against other front-end frameworks like Vue, React, or Svelte; however a reflection on my encounters using Angular with Java.

![Angular Java logo](https://miro.medium.com/max/120/0*i44DgzsGtqAtjS8P)

![Angular Java cover image](https://miro.medium.com/max/1274/0*kOwMHSMU2L8EE6Kf.jpeg)

**1) Dependency Injection**

If you have been around the Java ecosystem (Spring Boot, JAX-RS) you must have at least heard of Inversion of control or DI dependency injection.

_\`In_ [_software engineering_](https://en.wikipedia.org/wiki/Software_engineering)_,_ **_dependency injection_** _is a technique whereby one object (or static method) supplies the dependencies of another object. A dependency is an object that can be used (a_ [_service_](https://en.wikipedia.org/wiki/Service_(systems_architecture))_)\`._

What the hell that mean? Consider a Hero component in angular hero.component.ts the component needs data to display, consider using an API to fetch the data. Can’t we directly call the API from the component? We could but should we?

We use an abstraction layer like a service heroes.service.ts to provide us the data the service could call actual API or Mock some data. The hero component is responsible display the result rather than fetch it. The service provides data to the component. Thus the service is a `Dependency`on the component to use the service component needs to `Inject`it.

But why do we need to Inject service? Can’t we create an object of the service to use it? Since the framework is responsible to Inject the service it is easy to `unit`test the component by injecting a mock service. Mock service returns desired data from the service and test component in isolation rather than relying on service to test the component.

_\`Mocking is primarily used in unit testing. An object under test may have dependencies on other (complex) objects. To isolate the behavior of the object you want to replace the other objects with mocks that simulate the behavior of the real objects. This is useful if the real objects are impractical to incorporate into the unit test._

_In short, mocking is creating objects that simulate the behavior of real objects.\`_

Most of these Angular concepts are out there in Java be it Dependency injection, Unit testing with JUnit and Mockito, MVC.

**2) MVC Architecture**

Yes, you heard it right! Both Angular & Java have MVC Model View Controller design pattern. If you have any familiarity and awareness with MVC from either Java or C# you will quickly appreciate & recognize the patterns and fall in love with them in the Angular.  
To quickly compare patterns Both Angular and Java have Classes and Interfaces to represent the Model, Controller is like a component in the Angular and An API endpoint in Java. Both of them use services and Dependency injection to fetch data.

**3) Typescript**

Did you know when Angular 2 was to be released the Google had planned to create a separate language for Angular? But They collaborated with Microsoft to integrate Typescript with Angular!

For a competent Java developer, TypeScript syntax is relatively straightforward. Like Java, TypeScript syntax has mechanisms to define enums, iterative loops, methods, classes, interfaces, and constructors. None of these topics are foreign to anyone who has knowledge of the javac utility. But while the key concepts are all the same, the TypeScript syntax is decidedly different. (This can make transitioning from Java to TypeScript a frustrating experience, as tasks once simple in Java can trigger esoteric errors when you compile the corresponding TypeScript).

**4) Similar Syntax and Feel**

Both TypeScript and Java embrace the concept of a class in order to implement object-oriented concepts. Similarities between the two include the fact that classes can have methods, constructors, and variables, although each of these items is declared in a slightly different way. The following example shows the difference between declaring a simple Java class and a simple TypeScript class

![Angular java dependency injection example](https://miro.medium.com/max/120/0*2Fy5fVBOGeNsIjk_)

![Angular java dependency injection example](https://miro.medium.com/max/1040/0*Sn4m3GUcli17NEMc.jpg)

What is take away? Classes, Interface in Java, Angular (Typescript) looks very identical and very similar. Having a background experience in one of the languages will immensely help you understand another one.

**5) Type Support and Checking**

With Angular, you have no choice but to use Typescript features out of the box! So you don’t have to worry about passing the wrong argument type to the function pass a `string`to a `number` expecting function typescript will tell you right away! Type checking is underestimated with Java since you cannot even imagine passing a string to a number expecting argument in Java. That is not the case with Javascript. Typescript fills the gap by extending javascript and is the superset of Javascript and adds type support similar to that of Java. Having Type support is very powerful and meaningful it saves a lot of time when debugging.

That is it for now. Of course, The reasons state are merely a reflection of my experiences and why I believe one of the reasons Java developers tend to like Angular and stay with it.

> _\[1\]: A quick intro to Dependency Injection: what it is, and when to use it_
> 
> [_https://www.freecodecamp.org/news/a-quick-intro-to-dependency-injection-what-it-is-and-when-to-use-it-7578c84fa88f/_](https://www.freecodecamp.org/news/a-quick-intro-to-dependency-injection-what-it-is-and-when-to-use-it-7578c84fa88f/)
> 
> _\[2\]: What Java developers need to know about TypeScript syntax_
> 
> [_https://www.theserverside.com/tutorial/What-Java-developers-need-to-know-about-TypeScript-syntax#:~:text=Java%20has%20methods%2C%20while%20TypeScript,t%20have%20typed%20method%20parameters_](https://www.theserverside.com/tutorial/What-Java-developers-need-to-know-about-TypeScript-syntax#:~:text=Java%20has%20methods%2C%20while%20TypeScript,t%20have%20typed%20method%20parameters)_._
> 
> _\[3\]: What is Mocking?_
> 
> [_https://stackoverflow.com/questions/2665812/what-is-mocking_](https://stackoverflow.com/questions/2665812/what-is-mocking)