15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

542<br />

The Structure of a Java/C# Program<br />

The Structure of a Java/C# Program<br />

Java <strong>for</strong>ces object-oriented <strong>programming</strong> on you whether you like it or not.<br />

Every Java program consists of a class, such as<br />

class programname<br />

{<br />

public static void main(String args[])<br />

{<br />

System.out.println(“This is a simple Java program.”);<br />

}<br />

}<br />

Because Java relies on object-oriented <strong>programming</strong>, a Java program looks<br />

more complicated than it should. Basically, the main program is considered<br />

a class that has a single main function. To print something, the preceding<br />

program uses a println command, which is accessed through the System<br />

class. Because Java <strong>for</strong>ces object-oriented thinking on you, Java programs<br />

consist of multiple classes.<br />

Like Java, C# also <strong>for</strong>ces object-oriented thinking on every program you<br />

write.<br />

using System;<br />

class MyClass<br />

{_static void Main()<br />

{_Console.WriteLine(“This is a simple C# program.”);<br />

}<br />

}<br />

Creating Comments<br />

To write a comment in Java/C#, you have two choices. First, you can use the<br />

double slash character so that anything that appears to the right of the character<br />

is a comment, such as<br />

using System;_<br />

class MyClass _// This is a C# comment<br />

{_static void Main() _<br />

{_Console.WriteLine(“This is a simple C# program.”);_<br />

}<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!