C # comparison with Java

Source: Internet
Author: User

 


Since the emergence of the Internet, Java has become the first choice for many developers. many C ++ developers moved to the Java developer team in a short period of time. java has successfully developed and implemented many high-quality multi-threaded animations, games, and distributed applications. more importantly, the Java language is completely platform independent.

Java programs called Apllets (small applications) must pass security authentication before being downloaded to the local computer. This prevents any viruses from penetrating users' computers. many new improvements, such as swing package, Java2D API, and network software package (java. net) was added to this language after the initial Java Development Kit was released. since Sun released Java, many of its competitors have developed alternatives to this popular language, and some companies have even started two years ago.

Now a company that does not need to be introduced-Microsoft has released a new one called Microsoft. NET technology .. the main language of the NET family is C # or C-sharp. this language is inherited from Java/C ++. from my six months of technical experience in C #, I think C # is more or less similar to Java. however, many functions of C ++, such as operator overloading (which has been removed in Java), still exist in C.

Java programs can be run on any platform where the Java Virtual Machine or JVM is installed. however.. NET program platform requires that the Universal Language Runtime library or CLR be installed. it is all.. NET language. so one. NET language can call another.. NET language. further, if you have learned a language like C #, you can easily learn another one. NET language because all. NET Language follows what Microsoft calls.. NET Framework (Architecture ). this architecture includes compiling and installing robust.. NET application library. use. NET, you can use ASP. NET programming on the server, which is very similar to servlets in JAVA.

Like Applets in Java, C # introduces the concepts of WinForms and WebForms. with WinForms, you can design Windows-based applications and use WebForms to develop Web applications. you can either program in C # Or use Visual Studio. NET. it contains Visual C #. with Visual C #, you can easily write C # applications.

When we use Visual C ++ for programming, WinForms is almost a win32 program. it is possible to develop these programs using C ++. however, VC ++ provides us with a wizard to simplify our development process. now Visual C # is doing the same job. therefore, if you are already a programmer of VC ++, you 'd better try VC #.


Comparison between Java programs and C # programs

We should compare the differences between programs written in Java and C #. We will discuss the main differences between the two programs.

Hello Java program

Class Hello {// class declaration
Public static void main (String args []) {// main method, entry point
System. out. println ("Hello Java"); // output Hello Java to the console
}
}

Hello C # Program

Using System; // call the System namespace
Class Hello {// class declaration
Public static void Main () {// main method, entry point
Console. writeLine ("Hello C #"); // output Hello C # To the console #
}
}

In Java, the lang software package is automatically introduced. there is no need to introduce this package in a simple program. but in C #, we have to call the System namespace in all programs. remember that the console is a class in the System namespace. run the above programs and view their output results.


Main Method
Java: You may write a Java program without the main method, as long as this class is used as the parent class, but the program can run only when the class contains the correct Main method.

C #: it is impossible to compile C # source program without the correct Main method. If the main method is missing, the compiler will display an error message: the program filename.exe has no entry point defined.


Inheritance
Both Java and C # do not support multi-inheritance and both provide the interface concept as a substitute for multi-inheritance. however, C # includes more advanced content in the interface. at the end of this article, please find out the content entitled new features.


Operator and control flow statement
All operators such as arithmetic, logic, auto-increment, and auto-subtraction in Java can be found in C. in Java, control flow statements such as if, else, if-else, for, do-while, and while are all supported by C. however, C # adds the popular goto statements in C ++.


Exception Handling
In C #, you can use try, catch, finally, and throws statements to handle runtime errors (usually called exceptions ). the exception handling process in C # is almost identical to Java except for some small differences. C # System. the Exception namespace is the base class of all Exception classes.

Multithreading
Multi-threaded applications in C # are much easier than Java. We can use the Monitor and Mutex synchronization threads.

New Features
Indexing, attributes, and proxies are new concepts in C. the index is almost the same as the vector in Java. A complete discussion of its new features is beyond our scope. but I will try to explain them elsewhere on this website. C # introduces the concept of Operator Overloading not available in Java. however, both Java and C # support method overloading.

Let's go back to the discussion of the interface. We can verify whether the methods included in the interface are implemented using the is and as operators. we can avoid name conflicts when implementing interfaces. you can even combine the two interfaces into one and implement the Composite Interface in the class, as shown in the following code:
Using System;
Public interface First {
Void ();
Void B ();
}
Public interface Second {
Void C ();
}
Public interface Combined: First, Second {}

Class Combineimple: Combined {
// Here is the program code
// Main method
}}

C # also displays their error codes when displaying compilation errors. you can search for SDK-related online documents to find content related to this error code and find out the cause of this error.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.