docs:programming:hello_world_examples

This is an old revision of the document!


Hello World Examples

PHP can be embedded into an html file, and interpreted at runtime for dynamic web page content. It can also be executed at the command line by using the php program.

plan with functions and variables
<?php
	echo "Hello World!";
?>
<?php
	$myString = "Hello World!";

	function printMyString(){
		global $myString;
		echo $myString;
	}

	printMyString();
?>

HTML by itself does not have functions or variables. It is a tagged language most commonly used to display a web page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Hello World Example</title>

</head>
<body>
	<h1>Hello World Example</h1>
	<p>Hello World!</p>
</body>
</html>

C is a procedural, structured language that does not have objects. C is extended by other languages, such as C++ and Objective-C.

plain with functions and variables
#include <stdio.h>

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

const char * myString;

void printMyString(){
	printf("%s\n",myString);
	return;
}

int main(){
        myString = "Hello World!";
        printMyString();
        return 0;
}

Objective-C is an extension of c, so a plain version will not be shown here.

with functions and variables
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>

@interface Hello:NSObject{
	NSString *myString;
}
-(void)printMyString;
@end

@implementation Hello

-(void)printMyString{
    myString = [NSString stringWithString:@"Hello World!"];
    NSLog(myString);
}
@end

int main( int argc, const char *argv[] ) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];	
    Hello *h = [[Hello alloc] init];
    [h printMyString];
	[pool release];
    return 0;
}
plain with functions and variables
public class HelloWorld{
        public static void main(String args[]){
                System.out.println("Hello World!");
        }
}
public class HelloWorldVar{

        private String myString = "Hello World!";

        private void printMyString(){
                System.out.println(myString);
        }

        public static void main(String args[]){
                HelloWorldVar hw = new HelloWorldVar();
                hw.printMyString();
        }
}
plain with functions and variables
#!/usr/bin/perl

print "Hello World!\n";
#!/usr/bin/perl -w               # the 'w' tells perl to inform you of any
                                 # warnings encountered

use strict;                      # tell perl to impose strict verification,
                                 # and output additional warnings

$myString = "Hello World!";      # $myString is a global variable

sub printMyString {              # sub is used to define a subroutine, or
                                 # function in perl;

  print $myString;               # this instance of $myString references
                                 # the global $myString variable;
}

sub printLocalString {
  my $myString = "Hello Moon!";  # the my operator marks this instance of
                                 # $myString as private;

  print $myString;               # this statement is using the private
                                 # $myString above;
}

printMyString();                 # call a subroutine

printLocalString();              # call a subroutine
  • docs/programming/hello_world_examples.1159082522.txt.gz
  • Last modified: 2008/08/03 00:25
  • (external edit)