Moving From the Full-stack JS World to the Java Galaxy ⚡⚡

Hi in this blog I will write about my experience as a Full-stack developer with Java technology as I mentioned in the title “The Java Galaxy “, I will present my different steps of evolution of my small knowledge about this cool technology.

My Beginning 🚲 :

  • When I was a student and while learning to program I got advice form a coach to learn the JS frameworks and tools like Nodejs, Angularjs, He said “Don’t Follow the JEE stack, the JS Avenger will take the whole development world and it will be the trend number one
  • So my experience started with Angularjs/Express, moving after to Angular 2, React native (Thanks to Anouar who advises me to switch to RN), JWT, Token Authentication, Cross-platform mobile development,(I still remember my old days and my passion for programming )

My Steps With Java (Spring boot framework)

While the first professional experience I was recruited as Js Developer should have the required skills (React, Redux, GraphQL, Nodejs, etc ), But after some time I heard the project was leaved

so I need to adapt as a Spring/Angular Developer with the main stack of the enterprise

In my beginning, I was always scared from trying with the spring boot and the Java world, while seeing our teammates’ seniors code and knowledge about it I feel like nothing

Learning RoadMap 🚗:

I just set a Roadmap to learn and practice some spring boot tips and tricks, I’m so thankful for my colleagues Wali, Bilel, Khaled, And Amir who are always advising me about the best resources to learn from, tips that I should do in my free time

Top Ressources to follow :

Things learned until Now :

So after more than one year of experience with Java development, I feel like I learned a lot of things and always still needed to learn!

Spring boot Annotations ✂️ 📐:

— REST API — :

— Service Layer — :

— Repository — :

— Config — :

— Data models — :

Mapstruct:

Mapstrcut is a java library which provides us the automatic mapping between two java Beans, the most use cases are “Entity To DTO Conversion”, all that you have to do is to define an interface that extends EntityMapper

Auditing Entity 🔍 🔎 :

A generic class to keep track of who created or changed an entity and the point in time this happened.

The Design Patterns ⚒ 🛠 ⛏:

  • The Builder pattern :

The Builder pattern is a creational pattern used to created and initialize objects that solve the problem of Too many constructor arguments and Incorrect object state.

Recommended Project structure 📓 📕 📗 📘 📙 📔 :

  • web/rest: for your REST API controllers layer
  • service: your business logic layer
  • repository: the data access object layer
  • domain: your entities layer
  • dto: define your DTO classes
  • config: your configuration (cors config, swagger config, database config, Thymeleaf Config, etc.)
  • security: your security layer will handle the authorisation ad the authentification layer

JAVA 8 Features practiced ✏️ :

The Optional : class which is supposed to cure NullPointerExceptions.

that offers many advantages like :

  • No more NullPointer Exceptions
  • Null checks are not required
  • No more Boilerplate code

Stream API : Stream is a new abstract layer introduced in Java 8. Using stream, you can process data in a declarative way similar to SQL statements. For example, consider the following SQL statement.

Example Map operation:

Cools things are done with Spring Boot ✌️ :

Scheduled Tasks :

I have implemented a task which requires a scheduled job and persisting data, i really like it, how to handle exceptions, during job execution and how to confirm that your job is correctly done

Custom Annotations :

Another cool thing I liked is the Custom annotation implementation,

the use cases were for Enum Type validation and

- make a custom annotation for the APIS audit (to track each post and update HTTP query with simple annotation in the controller Layer “@EventCaptor”)

Aspect-oriented programming :

Custom Mongodb Queries:

With “mongoOperations” provide for us how to define custom queries like mongodb queries whil solves many problems for us

Example of implementation:

Code Refactoring ⛏ :

I’m currently learning the Java By Comparison book and it’s really a very interesting book for those who want to learn how to improve their code quality and learn best practices of it, things captured until now

Variables && Functions Naming conventions

Avoid unnecessary comparison

Avoid negations

Simplify your Boolean Expressions

DRY: Don’t Repeat yourself

Favor For each Over For loops

Format Over Concatenation (Strings)

Enums Over Integer Constants

Conclusion ✍️:

In conclusion, I just created a repository in GitHub called learning-spring-boot to try and practise the spring boot modules different tips and tricks and to growth more

Happy Reading 🙂

<script>alert('try your best')</script>