当前位置:首页 > 服务端 > Java And C# Compared(转载自c#helpe)

Java And C# Compared(转载自c#helpe)

Ever since the advent of the internet, Java has been the target for many developers.
Many C++ developers migrated to Java within a short period of time. Many high quality multithreaded animations, games, distributed applications are being developed and implemented successfully. Moreover the Java language is completely Platform Independent. 

Java Programs called Applets are verified for security in user's machine before downloading, thus ruling out the possibility for any viruses creeping into the user's machine. Many new advancements like swing package, Java2D API, Networking packages (java. net) have been built into the language after the initial release of Java Development Kit. Since Java is from Sun Microsystems many of its rival companies have started creating an alternative to this hot programming language, some two years back. 

Now a company which needs no further introduction, Microsoft have come up with a technology called Microsoft. NET. One of the prime languages in the .NET family is C# or C-sharp. This language was derived from Java/C++. Technically from my experience with C# for over six months, I am of the opinion that C# is more or less similar to Java. But many of the features of C++ like operator overloading (which was removed from Java) are there in C#.

Java programs will run on any platform having Java Virtual Machine or JVM installed on it. But .Net programs targets platforms having Common Language Runtime or CLR. This is the runtime which is being used by all the .Net languages for the execution. Thus one .Net language can call the modules and functions written in another .Net Language. Further if you learn a language like C#, then it is very easy to learn other .Net languages because all .Net languages follow what Microsoft calls .Net Framework. This Framework includes all the necessary class libraries to build and deploy robust .Net applications. With .Net you can perform server side programming via ASP.Net, much like servlets in Java. 

Like Applets in Java, C# introduces WinForms and WebForms. With WinForms you can design and develop windows based applications and with WebForms you can develop applications for the Web. This can be achieved either through code with C# or by using development environment tools like Visual Studio.Net. It includes Visual C# with which you can build C# applications very easily and with minimum effort. 

WinForms is almost similar to win32 applications which we develop using Visual C++.
It is possible to develop these applications using C++. But VC++ simplifies our development effort by providing us with wizards. Now Visual C# is also doing the same work. So if you are already a VC++ developer, it will be better for you to try out VC#. 

Comparing a Java program with C# program.
It is worth to compare a program written in Java with that of C#. We will then discuss the major differences involved in both programs. 

Hello Java Program
class Hello { // class declaration
public static void main(String args[]) { // main method, entry point
System.out.println("Hello Java"); // prints Hello Java to the console
}
}
Hello C# Program
using System; // System namespace called
class Hello   { // class declaration
public static void Main () { // main method, entry point
console.writeLine("Hello C#"); // prints Hello C# to the console
}
}
In Java, the lang package is automatically imported. It is not necessary to import this package in simple programs. But in C# we have to call the namespace System in all programs. Please note that console is a class under the System namespace. Try out the above program and observe the output.
Other Notable Differences
Main Method
Java:
It is possible to compile a Java program without a main method, provided that class is used as a super class. However the program will execute only when there is a valid main method in the class. 
C#: It is not possible to compile a C# source file without a valid main method. If it is absent, then the compiler will show an error message like program 'filename.exe' does not have an entry point defined.

Inheritance
Both Java and C# doesn't supports multiple inheritance and provides interfaces as an alternative to it. However C# covers much more advanced issues in interfaces. Please check out the topic titled New Additions given at the end of this article. 
 
Operators and control flow statements:
All operators like Arithmetic, logical, increment and decrement etc available in Java are supported by C#. Moreover control flow statements like if, else, if-else, for, do-while, while etc included with Java  are also available in C#. However C# reintroduces the popular GoTo statement found in C++. 

Exception Handling:
You can handle runtime errors also called as Exceptions in C# by making use of try, catch, finally, throws clauses. Exception handling in C# is almost same as in Java except some minor differences. System.Exception namespace is the base class of all the exception classes in C#. 

Multithreading:
The application of Multithreading in C# is much more simplified, than in Java. We can synchronize  threads by making use of the Monitor and Mutex classes. 

New Additions
The concept of Indexers, Attributes and Delegates are new to C#. Indexers are almost similar to Vectors in Java. A complete discussion related to these new concepts are beyond the scope of our discussion. However I will try to explain these at an another occasion through this site. C# introduces the concept of operator overloading, which was not present in Java.
However both Java and C# supports Method overloading and Method overriding.

Coming back to interfaces, we can verify whether the methods included within an interface are implemented by using is and as operators. There are ways to avoid name ambiguity while implementing the interface methods. You can even combine two interfaces into one and implement that combined interface in a class like the following piece of code

using System;
public interface First {
void A();
void B();
}
public interface Second {
void C();
}
public interface Combined: First, Second { }

class Combineimple: Combined {
// statements goes here
// main method goes here

} }

Further C# compiler shows the compile time error messages along with their error numbers. You can search the online documentation that comes with the SDK for the error number to study the cause of the error in detail.

作者:mozer
来源链接:https://www.cnblogs.com/mozer/archive/2010/06/28/1766556.html

版权声明:
1、Java侠(https://www.javaxia.com)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaxia.com/server/124589.html

标签: No compiler
分享给朋友:

“Java And C# Compared(转载自c#helpe)” 的相关文章

软件工程复习要点2022年05月17日 14:38:01
中间件RabbitMQ2022年05月23日 16:45:42
如何学习一门语言2022年05月23日 21:03:30
Tomcat服务器目录结构2022年05月28日 22:49:58
Go语言为并发而生2022年05月30日 22:50:08
Struts2 和 OGNL2022年05月30日 23:11:17