"Hello World!" -- the standard introduction.

In C

After including the standard input/output library, you put everything in a main() function. The printf() function is one of the ones included with stdio.h. A return value of 0 indicates that the program should exit.

This file would be compiled into an executable, and then run in a console environment.

#include <stdio.h>
int main()
{
printf("Hello, World!");
return 0;
}


In C++

After importing the standard input/output stream, you put you code inside a main() function. It sends the specified string to the standard output stream. A return code of 0 exits the program.

This code would be compiled to an executable and run in a console environment.

#include <iostream>

int main()
{
std::cout << "Hello, World!";
return 0;
}


In HTML

The server sends the file to the browser, which interprets the HTML code.

<html>
<head>
<title>PHP Test<title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>


In Java

First making it public, so that it can exist in any scope, a class is created that contains the main() method. It too is made to exist in any scope, to have no object, and to have no return value. It has an argument, an empty array of strings. The code inside the main() method calls the System class's out variable, which has as a method println() -- "print line" -- adding the specified string and a newline.

This code would be saved as a .java file and displayed in a console.

public class HelloWorld
{
public static void main(String[] args) {
System.out.println("Hello World!");
}
}


In JavaScript

After a blank page loads, the JavaScript is run, and an alert box is created.

JavaScript runs on the user's browser, not on the server.

<html>
<head>
<title>JavaScript Test</title>
</head>
<body>
<script type="text/javascript">alert("Hello, World!");</script>
</body>
</html>


In PHP

The echo command returns the specified HTML. The server resolves the PHP code before it tries to resolve the HTML code. It knows to do so if the file has the .php extension.

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World!</p>'; ?>
</body>
</html>


In Python

This code would be saved with a .py extension and viewed in a console environment.

print("Hello world!")

There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki