The Artima Developer Community
Sponsored Link

C# Answers Forum
Advice needed for Java to C# transition

2 replies on 1 page. Most recent reply: Feb 17, 2004 7:56 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Advice needed for Java to C# transition Posted: Feb 15, 2004 4:38 PM
Reply to this message Reply
Advertisement
I'm at a hobbyist level with Java. I write stuff for my own use, and to help with my real profession (I teach high school math). I plan on learning C# (again, for the fun of it as a hobbyist, not a professional developer) and I'm curious what kind of problems that I should be on the look out for.

When I made the transition from BASIC, the biggest difficulty, naturally, was switching from a procedural approach to the OOP paradigm. But I feel fairly comfortable with OOP now, so that aspect of C# shouldn't be a problem. Are there any pitfalls specifically related to the transition from Java to C# that I should be aware of?

Thanks
tom


David Vydra

Posts: 60
Nickname: dvydra
Registered: Feb, 2004

Re: Advice needed for Java to C# transition Posted: Feb 16, 2004 10:28 PM
Reply to this message Reply
I would read the interviews with Anders Hejlsberg on this site. One of the major differences is that in Java methods are 'virtual' (can be overrided) by default and in C# they are not. C# also has value types and autoboxing. So for example in java you can write:

Integer i = new Integer(10);
assertSame(i,i); //is true

but in c#

int i = 10;
assertSame(i,i); //false

assertSame(Object expected, Object actual) {
return i==i;
}

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Advice needed for Java to C# transition Posted: Feb 17, 2004 7:56 PM
Reply to this message Reply
The transition is not too tough. As mentioned already, you need to be more explicit in your declarations, using virtual and override keywords, for concepts that are implicit (or default behavior, as it were) in Java.

Also, you won't be using inner classes as you did in Java, particularly anonymous ones. C# does have an inner class but it is only of the static variety and I don't think it is very idiomatic to use it much (I think I did use it once early on when I started with C#, but that was probably because I was using a Java idiom -- today I would probably solve that same problem differently (I'll have to go back and look at that...)). Instead of inner classes, you'll be using delegates and events in C#.

Overall, C# has more bells and whistles, but you can get by without learning everything from the get-go and your Java knowledge will stand you in good stead.

Flat View: This topic has 2 replies on 1 page
Topic: need ur complete code in c Previous Topic   Next Topic Topic: Screensavers of two monitors?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use