C # developers learn Java, what are the biggest differences that can be overlooke…

For c# developers that are staring out to learn Java, are there any big underlying differences between the two languages that should be pointed out?

Maybe some people may assume things to be the same, but there are some import aspects that shouldn’t be overlooked? (or you can really screw up!)

Maybe in terms of OOP constructs, the way GC works, references, deployment related, etc.

A few gotchas off the top of my head:

  • Java doesn’t have custom value types (structs) so don’t bother looking for them
  • Java enums are very different to the “named numbers” approach of C#; they’re more OO. They can be used to great effect, if you’re careful.
  • byte
    is signed in Java (unfortunately)
  • In C#, instance variable initializers run before
    the base class constructor does; in Java they run after
    it does (i.e. just before the constructor body in “this” class)
  • In C# methods are sealed by default. In Java they’re virtual by default.
  • The default access modifier in C# is always “the most restrictive access available in the current context”; in Java it’s “package” access. (It’s worth reading up on the particular access modifiers in Java.)
  • Nested types in Java and C# work somewhat differently; in particular they have different access restrictions, and unless you declare the nested type to be static
    it will have an implicit reference to an instance of the containing class.
Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » C # developers learn Java, what are the biggest differences that can be overlooke…

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录