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

C# Programming Guide

Main() and Command-Line Arguments (C# Programming Guide)

Other Resources

C# for Java Developers