我只想澄清一件事。这不是哪个更好的问题,这部分我留给别人讨论。我不在乎。 我在面试时被问到过这个问题,我想多了解一点可能会有用。

以下是我能想到的:

Java is "platform independent". Well nowadays you could say there is the Mono project so C# could be considered too but I believe it is a bit exaggerating. Why? Well, when a new release of Java is done it is simultaneously available on all platforms it supports, on the other hand how many features of C# 3.0 are still missing in the Mono implementation? Or is it really CLR vs. JRE that we should compare here? Java doesn't support events and delegates. As far as I know. In Java all methods are virtual Development tools: I believe there isn't such a tool yet as Visual Studio. Especially if you've worked with team editions you'll know what I mean.

请补充其他你认为相关的。

更新: 我突然想到,Java在类、方法等上没有自定义属性。真的是这样吗?


当前回答

以下是Dare Obasanjo关于c#和Java之间差异的深度参考。在两者之间切换时,我总是会参考这篇文章。

http://www.25hoursaday.com/CsharpVsJava.html

其他回答

另一个很好的资源是http://www.javacamp.org/javavscsharp/ 本网站列举了许多例子,说明了这两种编程语言之间的几乎所有差异。

关于属性,Java有注释,它的工作方式几乎相同。

c#具有自动属性,这非常方便,它们也有助于保持你的代码更简洁,至少当你的getter和setter中没有自定义逻辑时是这样。

请通过下面给出的链接 msdn.microsoft.com/en-us/library/ms836794.aspx 它涵盖了c#和java之间的相似点和不同点

以下是Dare Obasanjo关于c#和Java之间差异的深度参考。在两者之间切换时,我总是会参考这篇文章。

http://www.25hoursaday.com/CsharpVsJava.html

比较Java 7和c# 3

(这里没有提到Java 7的一些特性,但是所有版本的c#相对于Java 1-6使用语句的优势已经被删除了。)

并非所有的总结都是正确的:

在Java中,方法默认是虚拟的,但你可以将它们设为final。(在c#中,它们默认是密封的,但你可以将它们设为虚拟的。) Java有很多ide,有免费的(如Eclipse、Netbeans),也有商业的(如IntelliJ IDEA)。

除此之外(以及你的总结中已经提到的内容):

Generics are completely different between the two; Java generics are just a compile-time "trick" (but a useful one at that). In C# and .NET generics are maintained at execution time too, and work for value types as well as reference types, keeping the appropriate efficiency (e.g. a List<byte> as a byte[] backing it, rather than an array of boxed bytes.) C# doesn't have checked exceptions Java doesn't allow the creation of user-defined value types Java doesn't have operator and conversion overloading Java doesn't have iterator blocks for simple implemetation of iterators Java doesn't have anything like LINQ Partly due to not having delegates, Java doesn't have anything quite like anonymous methods and lambda expressions. Anonymous inner classes usually fill these roles, but clunkily. Java doesn't have expression trees C# doesn't have anonymous inner classes C# doesn't have Java's inner classes at all, in fact - all nested classes in C# are like Java's static nested classes Java doesn't have static classes (which don't have any instance constructors, and can't be used for variables, parameters etc) Java doesn't have any equivalent to the C# 3.0 anonymous types Java doesn't have implicitly typed local variables Java doesn't have extension methods Java doesn't have object and collection initializer expressions The access modifiers are somewhat different - in Java there's (currently) no direct equivalent of an assembly, so no idea of "internal" visibility; in C# there's no equivalent to the "default" visibility in Java which takes account of namespace (and inheritance) The order of initialization in Java and C# is subtly different (C# executes variable initializers before the chained call to the base type's constructor) Java doesn't have properties as part of the language; they're a convention of get/set/is methods Java doesn't have the equivalent of "unsafe" code Interop is easier in C# (and .NET in general) than Java's JNI Java and C# have somewhat different ideas of enums. Java's are much more object-oriented. Java has no preprocessor directives (#define, #if etc in C#). Java has no equivalent of C#'s ref and out for passing parameters by reference Java has no equivalent of partial types C# interfaces cannot declare fields Java has no unsigned integer types Java has no language support for a decimal type. (java.math.BigDecimal provides something like System.Decimal - with differences - but there's no language support) Java has no equivalent of nullable value types Boxing in Java uses predefined (but "normal") reference types with particular operations on them. Boxing in C# and .NET is a more transparent affair, with a reference type being created for boxing by the CLR for any value type.

这不是详尽的,但它涵盖了我能想到的一切。