This article discusses the similarities and differences between Java and C # in order to let Java developers master some of the knowledge involved when migrating to. NET. The main similarities between Java and C # are:
|
java and C # are all derived from C + +, and there are some features of C + +. |
|
|
|
java byte code is passed by called Ja VA virtual Machine (JVM) application execution. Similarly, compiled C # programs are executed by the common language runtime (Common Language Runtime, CLR). |
|
except for some minor differences, in C # Exception handling is very similar to Java. C # uses Try...catch constructs to handle run-time errors (also known as exceptions), which is exactly the same as in Java. The System.Exception class is the base class for all C # exception classes. |
|
as Java, C # is a strong class Type check programming language. The compiler is able to detect type errors that may cause problems at run time. |
|
as Java, C # provides automatic garbage collection, which allows programmers to avoid tracking allocated resources. |
|
java and C # both support a single relay Commitment and multiple interface implementations. |
Now let's take a look at the important differences covered in this article:
• |
The C # language introduces new language constructs, such as foreach, indexers, properties, delegates, operator overloads, and other language constructs. We'll discuss these constructs in more detail later in this article. |
Source File Conventions
We need to know that the two languages differ in the file naming conventions and structures of the source program:
File naming
The naming convention for files that contain C # classes is somewhat different from Java. First, in Java, the extension of all source files is. java. Each source file contains a top-level public class declaration, and the class name must match the file name. In other words, a class named Customer with a public scope declaration must be defined in a source file that has a name Customer.java.
The C # source code is represented by the. cs extension. Unlike Java, a source file can contain multiple top-level public class declarations, and file names do not need to match any class names.