Thursday, 22 May 2025

Migrating from a .NET developer role to a Java developer role

Hello Everyone,

 I worked as a .NET full stack developer for almost 15 years, but recently I started working on Java technology so Migrating from a .NET developer role to a Java developer role involves both technical and mindset shifts.


 Here's a structured guide to help you make the transition smoothly


1. Understand the Core Differences

Both Java and C# are the same, but there are some core differences
Aspect.NETJava
Primary LanguageC#Java
RuntimeCLR (Common Language Runtime)JVM (Java Virtual Machine)
Framework.NET Framework / .NET CoreSpring, Jakarta EE, etc.
IDEVisual StudioIntelliJ IDEA, Eclipse, VS Code
Build ToolsMSBuildMaven, Gradle

2. Learn Java Syntax and Ecosystem

Since C# and Java are syntactically similar, the learning curve is manageable.  I focused on:

  • Java syntax and conventions
  • Exception handling
  • Collections framework
  • Java 8+ features (Streams, Lambdas, Optional, etc.)
  • Memory management and garbage collection

๐Ÿงฐ 3. Get Comfortable with Java Tools

I started working with the following tools

  • IDE: IntelliJ IDEA 
  • Build Tools: Maven or Gradle
  • Dependency Management: Understand pom.xml (Maven) or build.gradle
  • Testing: JUnit, Mockito

๐ŸŒ 4. Learn Java Frameworks

I started learning below frameworks

  • Spring Boot: For building REST APIs and microservices
  • Spring Data JPA: For database access
  • Spring Security: For authentication and authorization

๐Ÿ—ƒ️ 5. Database and ORM

I know Entity Framework in .NET, so I learned:

  • JPA (Java Persistence API)
  • Hibernate (most popular JPA implementation)

๐Ÿงช 6. Practice with Projects

I build small projects like:

  • A RESTful API with Spring Boot
  • A CRUD application using Spring Data JPA
  • A microservice with Spring Cloud

๐Ÿ“ฆ 7. Understand Java Deployment

I had good knowledge of .NET Core Deployment so I learned
  • WAR vs JAR files
  • Running Java apps with java -jar
  • Dockerizing Java applications

๐Ÿ“ˆ 8. Explore Advanced Topics (Optional)

  • Reactive programming with Spring WebFlux
  • Kafka or RabbitMQ for messaging
  • Kubernetes for deployment

It took me almost 2 months to learn Java from .NET, but it was a good experience.

Don’t forget to leave your feedback and comments below!

Regards

Sujeet Bhujbal

--------------------------------------------------------------------------------

Blog: www.sujeetbhujbal.com 

CodeProject:-https://www.codeproject.com/Members/SujitBhujbal

CsharpCorner:-http://www.c-sharpcorner.com/Authors/sujit9923/sujit-bhujbal.aspx

Linkedin :-http://in.linkedin.com/in/sujitbhujbal  

Medium: - https://medium.com/@SujeetBhujbal

------------------------------------------------------------------------------





Thursday, 30 January 2025

How to register multiple implementations of the same interface

 In a recent project, I faced an issue while registering multiple implementations of the same interface in .NET CORE. I found different solutions for multiple implementations of the same interface in .NET CORE


I faced an issue with the below. I have 3 classes with 1 interface


public interface IService { }
public class ServiceA : IService { }
public class ServiceB : IService { } 
public class ServiceC : IService { }


 In ASP.NET Core, how do I register these services and resolve them at runtime based on some key?



Solution 1: Use of Microsoft.Extensions.DependencyInjection.


Register your services as:


services.AddSingleton<IService, ServiceA>();

services.AddSingleton<IService, ServiceB>();

services.AddSingleton<IService, ServiceC>();



Then resolve with a little of Linq:


var services = serviceProvider.GetServices<IService>();

var serviceB = services.First(o => o.GetType() == typeof(ServiceB));

or


var serviceZ = services.First(o => o.Name.Equals("Z"));



Solution 2:   use of inheritance


Create a separate interface derived from the Base interface for each class.  create individual interfaces that inherit from IService, implement the inherited interfaces in your IService implementations, and register the inherited interfaces rather than the base.

In this way  we can have as many copies of the interface as we want and we can pick suitable names for each of them. And we have the benefit of type safety


public interface IService 

{

}


public interface IServiceA: IService

{}


public interface IServiceB: IService

{}


public interface IServiceC: IService

{}


public class ServiceA: IServiceA 

{}


public class ServiceB: IServiceB

{}


public class ServiceC: IServiceC

{}



Container:


container.Register<IServiceA, ServiceA>();

container.Register<IServiceB, ServiceB>();

container.Register<IServiceC, ServiceC>();




Solution 3 : Use of .NET CORE 8  Keyed DI services


Keyed DI services

Keyed dependency injection (DI) services provides a means for registering and retrieving DI services using keys. By using keys, you can scope how you register and consume services. These are some of the new APIs:


 Don’t forget to leave your feedback and comments below!

Regards

Sujeet Bhujbal

--------------------------------------------------------------------------------

Blog: www.sujeetbhujbal.com 

CodeProject:-https://www.codeproject.com/Members/SujitBhujbal

CsharpCorner:-http://www.c-sharpcorner.com/Authors/sujit9923/sujit-bhujbal.aspx

Linkedin :-http://in.linkedin.com/in/sujitbhujbal  

Medium: - https://medium.com/@SujeetBhujbal

------------------------------------------------------------------------------