C # language vs. Java language programs

Source: Internet
Author: User
Tags readline

Entering the 21st century, the information industry has grown rapidly, in software development, the Java language and C # language are independently, has been gradually improved and widely used, the Java language and C # language is an object-oriented language, but Java programs and C # programs still have a certain difference.

The following are examples of programs in both languages.

The basic program of 1.Java language:

Import java.util.*;
Package HelloJava{
Public class Message{
Public static void main(String [] args){
System.out.println(“欢迎来到Java世界”);
}
}
}

The basic program of 2.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 between the Java language Program and the C # language program.

A The keyword to import the package.

In Java, if you import other packages, you should use the Import keyword, and in C #, you use the Using keyword to refer to other namespaces, but they work the same way.

Two Keyword for the namespace.

Namespace (namespaces) are the way to organize your code in C #, and package (packages) are used in Java, and their role is to put tightly related code in the same namespace, greatly improving management and efficiency.

Three class keyword.

In both Java and C #, class keywords are used to represent classes, and any code that is written should be contained within a class. class to be included in a namespace or package, but in Java, the class name must be the same as the name of the source file, and C # is not required.

Four The main method is different.

The main () method in C # is the same as the main () method in Java, and is the first step in running the program. In Java, however, the main () method is lowercase and has only one way of writing, while the main () method in C # must be capitalized and has four different characters. respectively:

Static void Main(string [] args){}
static void Main(){}
Static int Main(string [] args){}
static int Main(){}

Five Input and Output methods.

The output method in Java is: System.out.println () and another System.out.println (the value to be output);

The input method is: Create the Scanner object, such as Scanner sa = new Scanner (), and then use the object Point method. such as String name = Sa.nextstring ();

The output method in C # is: Console.WriteLine (); and Console.WriteLine (value to output); A method unique to C # Console.WriteLine ("Format string", List of variables);

The Input method is: string name = Console.ReadLine ();

Above is the difference which I summed up in the study, perhaps has the loophole to give everybody to make a reference, hoped that everybody studies these two languages well, together explores them the knowledge.

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.