====== Hello World Examples ====== ===== php ===== 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. ==== simple ==== ==== with functions and variables ==== ===== ASP.NET ===== Hello World - ASP.NET

Hello World!

The time is now:

===== html ===== HTML by itself does not have functions or variables. It is a tagged language most commonly used to display a web page. ==== simple ==== Hello World Example

Hello World Example

Hello World!

===== c ===== C is a procedural, structured language that does not have objects. C is extended by other languages, such as C++ and Objective-C. ==== simple ==== #include int main(){ printf("Hello World!\n"); return 0; } ==== with functions and variables ==== #include const char * myString; void printMyString(){ printf("%s\n",myString); return; } int main(int argc, char **argv){ myString = "Hello World!"; printMyString(); return 0; } ===== objective-c ===== Objective-C is an extension of c, so a simple version will not be shown here. ==== with functions and variables ==== #import #import @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; } ===== cpp ===== * At least on the Mac platform, use g++ instead of gcc to compile because it already has the C++ standard libraries linked. ==== simple ==== #include int main() { std::cout << "Hello World!\n"; return 0; } ==== with classes, functions, and variables ==== #include #include using namespace std; // or type std:cout everywhere class Hello { public: Hello(const char * userString); // Constructor ~Hello(); // Destructor void printMsg(); private: string privateString; // private variable }; Hello::Hello(const char * userString) { privateString = userString; } Hello::~Hello() { // do nothing special } void Hello::printMsg() { cout << privateString; } int main() { Hello HelloInstance("Hello World!\n"); // create a new instance HelloInstance.printMsg(); return 0; } ===== java ===== ==== simple ==== public class HelloWorld{ public static void main(String args[]){ System.out.println("Hello World!"); } } ==== with methods and variables ==== 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(); } } ===== javascript ===== ===== perl ===== ==== simple ==== #!/usr/bin/perl print "Hello World!\n"; ==== with functions and variables ==== #!/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; # it is commented out here because it will # fail since the variable below requires # an explicit package name (such as my) $myString = "Hello World!"; # $myString is a global variable sub printMyString { # sub is used to define a subroutine, or # function in perl; print $myString . "\n"; # 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 . "\n"; # this statement is using the private # $myString above; } printMyString(); # call a subroutine printLocalString(); # call a subroutine