Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

What else apart from these should a Java developer learning C# keep in mind?

 
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been a java developer who has now started learning C#. Below are some of my learning in C# :



C# is not platform independent like Java and can only work on Windows.
In C# instead of creating Jar like java we create a dll.
In C# we use the inbuilt IIS server of OS instead of tomcat/JBoss etc.
C# has method names in Pascal case unlike camel case in Java.


What else apart from these should a Java developer learning C# keep in mind?
 
Rancher
Posts: 86
7
Mac Mac OS X Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Platform.NET FrameworkMono(Framework Clone).NET Core
WindowsYes. Some versions are OS componentsYesYes
MacNoYesYes
LinuxNoYesYes



C# is platform independent. Microsoft makes .NET Framework on windows, Mono is the .NET Framework on Mac, Linux, and mobile. If you use .NET Core(This is preferred moving forward), it is cross platform. They removed concepts that were Windows centric and moved them into their own packages. .NET Framework is a shared component installed at the machine level. .NET Core does not use shared libraries. So you are deploying exactly the runtime you compiled it on. .NET Core is driven entirely by the package management system to bring in runtime components.


In Java, each class is compiled to a separate file, which are then gathered into a JAR. In .NET a Project is compiled into a DLL. You can then bundle 1 or more dlls into a NuGet package(NuGet is the packaged manager for .NET) which will also manage dependencies. So a Maven package is analogous to a NuGet package. A Project compiling to a DLL is equivalent to a Jar for a single library. But a jar is a more flexible unit of deploy since you can include any arbitrary java code in it.

In the Windows space, IIS is the web server. IIS, supporting .NET framework, is setup as AppPool(the executable) and AppDomain(the isolation container).
If you are running .NET Core, on any platform, it is just a binary module. You can plug it into IIS or Apache like you would any other mobile.



Something else to keep in mind, on C# they have Properties as the method of implementing getters and setters.

If you have a simple getter/setter, it will also support access restrictions.

This automatically creates private backing variable. The "Property" construct is an outgrowth of a legacy of COM. It would understand that a function called "get_Name()" and "set_Name" were related. So properties are just functions under the hood, and you can create custom backing code if you want.


Many things in C# are done with Delegates where Java would use objects. Delegates are a top-level language feature. Events, Lambdas, LINQ are just forms of delegates. You start threads and use Tasks(Promises) using delegates. Think of a delegate as a type-safe function pointer. If you want to do composition it is generally preferred to use generics and delegates instead of a bunch of objects.
 
Bartender
Posts: 1200
38
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill's very good explanation apart, let me suggest something I learnt at my expense: C#'s syntax is really similar to Java's, but under the hood they are really two different beasts, and such  similarity could be deceiving.
Years ago I approached C# for the first time wrongly believing that, more or less, understanding deeply C# would be easy, given the pretty similar language syntax. I was wrong. Syntax is similar, underlying semantic is really different.
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. This information is useful to someone who is beginning to learn C# after doing Java for many years.
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another difference which I have seen is that C# does not have concept of checkered exception and for the same reason does not have throws keyword.
 
Bill Crim
Rancher
Posts: 86
7
Mac Mac OS X Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:C# does not have concept of checkered exception


I laughed at "checkered exception". I have often been frustrated with checked exceptions in Java, and I have to say your description is better.
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for that typo. Another differences which I want to add are. C# has internal modifier for class which is not there in Java. C# has out parameter which is not there in Java. C# has Using statement which is not there in Java.  
 
Marshal
Posts: 66266
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:. . . . C# has out parameter which is not there in Java.

Does that mean it supports pass by reference?

C# has Using statement which is not there in Java.  

Isn't that the equivalent of import...?
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am taking about the Using statement not the Using keyword. E. G  Using the Using statement removes the need for closing the sql connection in a finally block.
 
Saloon Keeper
Posts: 10785
231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Does that mean it supports pass by reference?


Yes. You can use the 'ref' keyword to use normal pass-by-reference, or the 'out' keyword to indicate that the method must treat the parameter as uninitialized, and assign it a definite value before it returns.

Monica Shiralkar wrote:C# has Using statement which is not there in Java.


Incorrect. Since Java 7 there is try-with-resources, which pretty much does the same thing as using in C#.

C#

Java
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for correction.
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In C# we can have method inside method. This is not there in Java.
 
Stephan van Hulst
Saloon Keeper
Posts: 10785
231
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java on the other hand you can write method local types and anonymous classes. And both languages allow you to assign a lambda expression to a variable of a functional interface (Java) or a delegate type (C#).
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After using C# since some months and worked for years on Java, I felt that the most significant feature in C# which does not have equivalent in Java is LINQ. Other things are present in different ways on both languages but LINQ is only in C#.  
 
Stephan van Hulst
Saloon Keeper
Posts: 10785
231
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you figure? Pretty much anything you can do with LINQ you can do with streams in Java.

I think a much bigger and more interesting feature in C# is that you can use LINQ to build expression trees that are compiled at runtime against the system you want to run them on. For instance, I can write SQL queries in LINQ, which are compiled and executed on the database end, rather than in the application server.
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Apart from the difference you said I think Streams are tied to Lambda expression (to make use of streams you need to use lambda expressions) but for using LINQ you may or may not use lambda expressions.
 
Stephan van Hulst
Saloon Keeper
Posts: 10785
231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You keep using the phrase "lambda expression" in places where it's not the only applicable concept. I can write Stream operations without using a single lambda expression. Are you using lambda expression as a catch all phrase for "functions"? Why?

If by "LINQ expressions without using lambda expressions" you mean "query syntax", then that really isn't such an interesting difference. Query syntax in C# is really just syntactic sugar for "method syntax", something that Java supports on streams as well.

As I said in my previous post, much MUCH more interesting is that LINQ expressions in C# can yield expression trees rather than function objects. An expression tree is really a "piece of code" that you can treat as an object. You can even modify it, and perform operations such as "insert a statement between these two lines of code" or "change the return type of this piece of code", or as I already alluded to "compile and run this piece of code on this remote system". Frameworks like Entity Framework or Moq make excellent use of this capability.
 
Stephan van Hulst
Saloon Keeper
Posts: 10785
231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Features in C# I gratefully make use of and wish were available in Java are pattern matching and inline variable declaration:

Pattern matching:

Inline variable declaration:

Other really cool features are anonymous types and tuple-like deconstruction:

Anonymous types:

(Or in query syntax:)

Tuple deconstruction:
 
Stephan van Hulst
Saloon Keeper
Posts: 10785
231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally, I think the most important difference between the two languages for me is that in C# generic type information is available at runtime. That means I can do stuff like this:
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I will read more about Java Streams and clear that.
 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something which a Java developer has to most commonly keep in mind while working on C# with respect to  the coding standards, is that the methods (which we so commonly create)  are not camelCase like Java but are PascalCase. I used to do this mistake and correct it because of the Java habbit.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!