r/javahelp • u/Cell-i-Zenit • Feb 04 '20
Switching from C# to Java
Hi,
can you give me a list of things i should be aware of in the java world? Like really important libraries, concepts etc?
The thing is i know C# really well, but i dont know what i dont know in the java world, so i cant really look it up.
26
Upvotes
33
u/Northeastpaw Feb 04 '20
So I'm a Java developer who went the other way to C# for a time. Here are some notable differences:
No properties. Getters and setters have to be coded yourself or generated by an IDE (or hacked in via some black magic called Project Lombok).
No reference types. Everything in Java is passed by value. However, even though object references are passed by value, the passed in references will still point at the correct object so things work pretty transparently. You can't swap references in a method and see that reflected back in the calling method but that's a very niche use case anyway.
No out parameters. I never understood the use for them anyway.
Huge ecosystem. Coming from Java to C# it felt like there was a dearth of high quality C# libraries and frameworks. The amount of really good stuff in Java can feel overwhelming, but that's complaining about being spoiled.
You will definitely want to bookmark the standard library javadocs. Find out what frameworks and libraries the team you're moving to is using and bookmark the reference documentation for all of them.
Common equivalents for C# frameworks/libraries/tools:
Entity framework -> JPA. Hibernate is the most common JPA implementation but there's also EclipseLink, OpenJPA, DataNucleus. Raw DB access is done through JDBC.
Visual Studio -> Eclipse, IntelliJ, NetBeans. There's a lot of love for IntelliJ. Eclipse is really entrenched and has a lot of plugins for common frameworks. I personally prefer Eclipse but IntelliJ is very cool.
MSBuild/NuGet -> Maven or Gradle. Both handle dependency resolution and pull dependencies from Maven Central. Maven builds are written in XML and are very declarative; if you find yourself struggling with a complex Maven build then you're not thinking declaratively enough. Gradle has declarative elements but allows you to script parts of your build. Gradle has been adopted by Android as its build system so if you're working with Android, learn Gradle.
IIS -> Apache Tomcat, Wildfly, many others. Java application servers package lots of enterprise components like messaging, transactions, and dependency injection with a web container. Note that Apache Tomcat is just a servlet container which means it handles the web part but doesn't provide any of the rest. Tomcat is often paired with another framework called Spring which can provide those enterprise features, albeit in a slightly different way than JavaEE.