Entering the era of rapid information development, the information industry is not developing and growing. In the field of software development, the Java language and the C# language are both unique and have been gradually improved and widely used. The Java language and the C# language are both object-oriented languages. But there are still certain differences between Java programs and C# programs. Entering the era of rapid information development, the information industry is not developing and growing. In the field of software development, the Java language and the C# language are both unique and have been gradually improved and widely used. The Java language and the C# language are both object-oriented languages. But there are still certain differences between Java programs and C# programs.
Below are examples of programs in the two languages.
1. Basic programs of Java language:
Import java.util.*;
Package HelloJava{
Public class Message{
Public static void main(String [] args){
System.out.println("Welcome to the Java world");
}
}
}
2.Basic programs of C# language:
Using System;
Using System.Collection.Generic;
Using System.Text;
Namespace HelloAccp{
Class Program{
Static void Main(string [] args){
Console.WriteLine("Hello Accp.NET");
Console.ReadLine();
}
}
}
Based on these two basic programs, let's distinguish the differences between Java language programs and C# language programs.
1. Import the keywords of the package.
In Java, if you import other packages, you should use the import keyword, while in C#, use the using keyword to refer to other namespaces, but both have the same effect.
2. Namespace keywords.
Namespace is the way to organize code in C#, and package is used in Java. Their function is to put some closely related codes in the same namespace, greatly improving management and usage efficiency. .
3. Class keyword.
In both Java and C#, the class keyword is used to represent a class, and any code written should be contained in a class. Classes must be included in a namespace or package, but the difference is that in Java, the class name must be the same as the name of the source file, while C# does not require it.
4. Differences in Main methods.
The Main() method in C# and the main() method in Java have the same function, and they are both the first steps in program running. However, in Java, the first letter of the main() method is lowercase and there is only one way of writing it, while in C#, the first letter of the Main() method must be capitalized and there are four ways of writing it. They are:
Static void Main(string [] args){}
static void Main(){}
Static int Main(string [] args){}
static int Main(){}
5. Input and output methods.
The output methods in Java are: System.out.println(); and another System.out.println (value to be output);
The input method is: create a Scanner object, such as Scanner sa = new Scanner(); and then use the object point method. Such as String name = sa.nextString();
The output methods in C# are: Console.WriteLine(); and Console.WriteLine (the value to be output); and a method unique to C#, Console.WriteLine ("format string", variable list);
The input method is: string name = Console.ReadLine();
The above are the differences that I have summarized in my study. Maybe there are loopholes, so I will give you a reference. I hope everyone will study these two languages well and explore their knowledge together.