JAVA and C # comparison (if your resume is mentioned in C # and JAVA, how to answer interview?)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_43170213/article/details/100010903

A, C # and java which is better?

Then, the following analyze C # and java in the end what similarities and differences. Comparison of C # and Java, known as same 10% plus 90% of the difference.
The whole is more similar? It is an object-oriented language

Second, the comparison function from

Compared to that 10% JAVA and C3 was very different, you will find a wide variety of C # properties much more. More well-known: Trust, property, real generic, indexer, class initialization, a class division, operator overloading, struct, unsafe codes, IDissposable, etc. In addition, .net framework 3.5 is also added a long list compiled by the pure characteristics is provided.

Commission, this can be the biggest advantage of C # to Java. Although Java interfaces can rely on anonymous inner classes implement these features as delegate functions, but to a lot of trouble if it comes to the sum of N cases delegate instance, then a simple C # inside the "+" sign on in Java only with FilterChain, InterceptorStack this concept.

The real generic, this is a major advantage of C #, and Java pseudo-generics is a major failing. But Java's long for compatibility reasons had to use fake generic implementation. If generics are not available in time jdk1.5, but jdk1.4, and collection framework with the launch, I think it will be a true generic implementation.

Indexer, with this many containers can be directly used [] to take the elements, I feel pretty good, better than nothing, trick compiler. Class initializer, lazy typical characteristics. Each with at most can save the next two lines of code, but also a little trick compiler. Partial class (partial class), solely for that a lot of graphic designer and old people's code vs.net of conflict and come up with is more stuff, but also a little trick compiler.

Operator overloading, are used not by much, use Shique is particularly useful. struct, things on the stack, freeing memory that is super fast, but need to use this occasion, probably using the C ++ programming. unsafe code something purely to increase the complexity of the language. Moving like a man, look at this not willing to throw, that is not willing to throw, and finally got the bottles have moved away. IDisposable, implement this interface, with the using block, very powerful, can finally grasp the object as destroyed like C ++.

Then talk about Java than C # features:

Anonymous inner classes: one thing really extremely convenient, and also a lot of Java design patterns are related.

Dynamic Agent: Java inside to achieve AOP, easy; C # to achieve AOP, it is relatively difficult, had to use those dynamic IL under Assamble namespace generation tool or use interceptors. This is the dynamic proxy role.

I hope one day you can have a C # anonymous inner classes and dynamic agency, become better. Java can also hope to have delegates, and so.

Third, from Comparison

Similarity:

  Java和C#都是一门面向对象的语言,Java更多地借鉴了C++的优点,而摒弃了它的一些不太容易被人掌握的知识点(有些不能说是缺点),并且增加了一些自己的特点,而C#则是更多地借鉴了Java的优点,而增加了一些自己的特点。也就是说Java站在C++的肩膀上,而C#站在了Java的肩膀上。



  跨平台特性
  跨平台特性的最大优点就是只要有相应的运行环境,同一个编译好的程序就能在上面运行,而不需要重新编译程序,它的缺点就是不能针对特定平台,所以不能充分利用平台特性,因而在性能上会有所降低,幸运的是现在的硬件比以前大大提高,这部分的降低在绝大部分情况下可以不用考虑。而且Java和C#都有自动垃圾回收机制,运行时环境可以自动清理不再使用的内存,减少了手动释放内存的风险。


  Java的跨平台特性建立在可以跨越多个不同种类的操作系统平台,比如Windows、Linux、Unix等,但是需要注意的是不是说Java能在所有的系统上都能跨平台,必须实现在该操作系统上的Java运行时环境JRE才行,也就是说假如今天有人开发了一个前所未有的系统,这时候Java程序是不能在上面运行的——因为还没有针对这个操作系统的Java虚拟机(JVM),好在在当今绝大部分操作系统上都有针对该系统的JVM,所以它能“一次编译,到处运行”。


  C#的跨平台则是建立跨Windows平台的基础上的(有一个针对非Windows的.net运行环境,不过好像还不是太好),不像以前Windows95下的程序到WindowsXP下就不能运行,或者WindowsXP下的程序到Windows95下也不能运行(这种情况居多),现在呢,只要安装一个.net framework(也就是.net程序的运行时环境),在Windows2003下编写的.net程序不用重新编译就能在Windows98下运行,只要这台安装Windows98的机子安装了.net程序的运行时环境。


  语法特性
  Java抛弃了指针,使用了包(package)的概念,导入包使用import语句,在Java中有几种非面向对象的数据类型,那就是byte、char、short、int、long、float、double这几种数据类型,在方法中传递时仅仅是传递它们的值,为了方便一些集合类的操作(它们存储的是对象类型),又增加了它们的包装类Byte、Char、Short、Integer、Long、Float、Double。在Java中存在属性的概念,这些都是通过setXXX()、getXXX()来设置。


  C#没有完全抛弃指针(在unsafe状态下还可以操作指针),对于类的管理采用了名称空间(namespace)的概念,并且还使用了out、ref等关键字,便于从一个方法返回多个结果,在C#中不仅存在属性,还有索引器等比较方便的特性。


  生成文档doc文档
  在利用程序中的特殊注释生成api文档方面,两种语言都有不错的表现,不过C#更胜一筹,它能利用注释在输入类成员时提示,便于程序员不用去看程序源码而知道程序的大概用途,而Java这方面没有。


  IDE(集成开发环境)方面
  Java的IDE是非常多,从庞大的Jbuilder到小巧的Jcreator,还有可以扩充的Eclipse,可以说Java的IDE的数量是非常多的。 C#的IDE不多,除了微软自己的VS.NET之外,好像还有Borland的C#Builder,除此之外,广为认知好像不多。


  性能方面
  Java采用了字节码(bytecode),而C#则采用了MSIL,它们的性能都是介于解释型语言和生成本地机器代码之间的,在一些测试中,C#的性能略高于Java,可能Java的字节码要适用多个系统多个平台的缘故吧。


  企业开发方面
  由于Java出现的时间长的缘故,并且还能跨平台,采用EJB等解决方案,所以目前绝大部分网站都是基于J2EE开发的(大部分都是J2EE+MySQL+Apache+Linux,都是免费的)。
  C#做的大型网站,它也有针对EJB的Net Remoting技术,由于它限制了必须(IIS+Windows),所以大型的网站不是太多,不过随着时间的推移,可能会有更多的网站采用asp.net技术。毕竟微软的东西一向傻瓜化,门槛低,能够吸引一些初级编程人员到这个行列中来。而且微软的asp.net采用了代码和页面分离技术,的确能方便编程人员。

IV Summary

I remember seen online quote that went something like this, Linux is like professional camera, shooting out depends on your photography; while Windows is like a fool camera, will be able to take pictures as long as you press the shutter. I think Java is like Linux, add a button, a label you need to specify the style, place where you need to specify; and C # will continue to uphold the Windows features, fool, easy to operate, easy to use. So, it is different and no better, see you understand and use them.

Guess you like

Origin blog.csdn.net/qq_43170213/article/details/100010903