Console Application Development (C# vs Java)
This page is specific to:.NET Framework Version:
2.03.03.5
Visual C# Language Concepts
Console Application Development (C# vs Java)

Console applications read and write to and from the standard input and output (I/O) without any graphical user interface. The anatomy of a console application is similar in Java and C#, and similar classes are used for console I/O.

While the details of the classes and their method signatures might vary, C# and Java use similar concepts to perform a console I/O operation. Both C# and Java have the concept of a main entry point for the console application and associated console read and write methods. In C#, this is Main, and in Java, it is main.

Java "Hello World" Example

In the Java example code that follows, a static void main() routine accepts a String reference to the application's arguments. The main routine then prints a line to the console.

/*  A Java Hello World Console Application */
public class Hello {
    public static void main (String args[]) {
        System.out.println ("Hello World");
    }
}
C# "Hello World" Example

In the C# example code that follows, a static void Main() routine accepts a string reference to the application's arguments. The Main routine then writes a line to the console.

// A C# Hello World Console Application.
public class Hello
{
    static void Main()
    {
        System.Console.WriteLine("Hello World");
    }
}


Compiling the Code

If you are using Visual C#, you can compile and run the code in a single step by pressing F5. If you are using the command line and your file is named "Hello.cs," you invoke the C# compiler like this:

csc Hello.cs

For More Information

For more information about creating a console application, see Creating Console Applications (Visual C#).

For more information about .NET Framework console classes, see:

See Also

Concepts

Other Resources

© 2010 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View