什么是C#和Java之间的主要区别? [英] What are major differences between C# and Java?

查看:129
本文介绍了什么是C#和Java之间的主要区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想澄清一件事。这不是一个问题,关于哪一个更好,这部分我留给别人来讨论。我不关心它。
我一直在问我面试这个问题,我想了解多一点可能是有用的。

I just want to clarify one thing. This is not a question on which one is better, that part I leave to someone else to discuss. I don't care about it. I've been asked this question on my job interview and I thought it might be useful to learn a bit more.

这是我能想出的:


  • Java是平台无关。那么现在你可以说还有就是项目,所以C#可以考虑太多,但
    我相信这是一个有点夸张。为什么?那么,当Java的新版本做它是它支持所有平台上同步发售,而另一方面有多少C#3.0的功能在单执行仍然下落不明?或者是不是真的 CLR 主场迎战的 JRE 中,我们应该比较吗?

  • Java不支持事件和委托。据我所知。

  • 在Java的所有的方法都是虚拟

  • 开发工具:我相信没有作为Visual Studio中这样的工具呢。特别是如果你已经与团队合作的版本,你会明白我的意思。

  • 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.

请添加其他您认为是相关的。

Please add others you think are relevant.

更新:
只是突然了我的心,Java没有像定制的类,方法等属性还是没有呢?

Update: Just popped up my mind, Java doesn't have something like custom attributes on classes, methods etc. Or does it?

推荐答案

对比的Java 7和C#3

(Java 7中的某些功能不再赘述,但使用C#对Java 1-6所有版本的语句的优势已被删除。)

(Some features of Java 7 aren't mentioned here, but the using statement advantage of all versions of C# over Java 1-6 has been removed.)

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

Not all of your summary is correct:


  • 在Java方法是虚拟的默认的,但你可以让他们最终决定。 (在C#中他们在默认情况下密封的,但你可以让他们虚拟的。)

  • 有很多的IDE的Java,无论是免费的(如Eclipse中,Netbeans的)和商业(例如IntelliJ IDEA的)

  • In Java methods are virtual by default but you can make them final. (In C# they're sealed by default, but you can make them virtual.)
  • There are plenty of IDEs for Java, both free (e.g. Eclipse, Netbeans) and commercial (e.g. IntelliJ IDEA)

除此之外,(什么在你总结的话):

Beyond that (and what's in your summary already):


  • 泛型两者之间完全不同的; Java泛型是只是一个编译时的绝招(但在那一个有用的)。在C#和.NET泛型是维持在执行时也和值类型和引用类型的工作,保持适当的效率(如列表<字节> 作为字节[] 支持它,而不是盒装的字节数组。)

  • C#不检查了异常

  • Java不允许用户定义的值类型的创建

  • Java没有运营商和转换重载

  • Java没有对迭代器的简单实现
  • 迭代器块
  • Java没有像LINQ什么

  • 部分原因是由于没有代表,Java没有什么很喜欢匿名方法和lambda前pressions。匿名内部类通常填补这些角色,但clunkily。

  • Java没有前pression树木

  • C#不具有匿名内部类

  • C#不具备Java的内部课程可言,其实 - 所有嵌套类C#像Java的静态嵌套类

  • Java没有静态类(不具有的实例构造函数,并且不能用于变量,参数等)

  • Java没有任何等同于C#3.0匿名类型

  • Java没有隐式类型的局部变量

  • Java没有扩展方法

  • Java没有对象和集合初始化前pressions

  • 访问修饰符有所不同 - 在Java中有(目前)的装配没有直接等价的,所以没有内部的知名度理念;在C#中有没有相当于Java中的默认可见其考虑命名空间(和继承)的

  • 在Java和C#初始化的顺序是微妙的不同(C#中的链接调用基类的构造函数之前执行变量初始化)

  • Java不具有作为语言的一部分;他们获取的约定/设置/是方法

  • Java没有不安​​全code
  • 相当于
  • 互操作是在C#比Java的JNI
  • 更容易(和.NET一般)
  • Java和C#有枚举有些不同的想法。 Java的是更面向对象的。

  • Java没有preprocessor指令(#定义,#如果等在C#)。

  • 的Java没有类似的C#的 REF 退出通过引用传递参数

  • 的Java没有等效部分类型

  • C#接口不能声明字段

  • Java没有无符号整型

  • Java有一个十进制类型没有的语言的支持。 (java.math.BigDecimal中提供的东西的的System.Decimal - 有差异 - 但有没有语言支持)

  • Java没有相当于空值类型的

  • 拳击在Java中使用predefined(但正常)引用类型与他们特定的操作。拳击在C#和.NET是一个更透明的事情,由CLR任何值类型的拳击正在创建引用类型。

  • 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.

这并不详尽,但它涵盖了所有我能想到的副手的。

This is not exhaustive, but it covers everything I can think of off-hand.

这篇关于什么是C#和Java之间的主要区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆