Hello World in “C” languages


//Hello World in C#
class HelloWorld
{
    static void Main()
    {
        System.Console.WriteLine(“Hello, World!”);
    }
}
// Hello World in C++ (pre-ISO)
#include <iostream.h>
main()
{
    cout << “Hello World!” << endl;
    return 0;
}


C++-CLI
// Hello World in C++/CLI for .NET
using namespace System;
void main()
{
    Console::WriteLine(“Hello World”);
}
ANSI C

/* Hello World in C, Ansi-style */

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  puts("Hello World!");
  return EXIT_SUCCESS;

}
/* Hello World in Objective-C.
** Since the standard implementation is identical to K&R C,
** a version that says hello to a set of people passed on
** the command line is shown here.
*/

#include <stdio.h>

#include <objpak.h>
int main(int argc,char **argv)
{
    id set = [Set new];
    argv++;while (–argc) [set add:[String str:*argv++]];
    [set do:{ :each | printf(“hello, %s!\n”,[each str]); }];
    return 0;
}

C-OpenGL
/* “Hello World” in C using OGL – Open Graphics Library */
#include <GL/glut.h>
#define font GLUT_BITMAP_HELVETICA_18
#define tx “Hello World!”
void text(void)
{
 char *p, tex[] = tx;
 p = tex;
 glColor3d(1.0, 1.0, 0.0);
 glRasterPos2d(-.5, 0.);
 while(*p) glutBitmapCharacter(font, *p++);
}
void display()
{
 glClear(GL_COLOR_BUFFER_BIT);
 text();
 glFlush();
}
void reshape(int width, int height)
{
 glViewport(0, 0, width, height);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glOrtho(-1, 1, -1, 1, -1, 1);
 glMatrixMode(GL_MODELVIEW);
 display();
}
int main(int argc, char **argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 glutInitWindowPosition(50, 50);
 glutInitWindowSize(500, 500);
 glutCreateWindow(“Hello World OpenGL”);
 glClearColor(0,0,0,0);
 glutDisplayFunc(display);
 glutReshapeFunc(reshape);
 glutMainLoop();
 return 0;
}

Hello World in Web Languages


<?php
  // Hello World in PHP
  echo ‘Hello World!’;
?>

<?
// Hello World in PHP + GD library
header(“Content-type: image/gif”);
$rscImage    = imagecreatetruecolor(80, 25);
$intFontC    = imagecolorallocate($rscImage, 255, 255, 255);
$intBGC        = imagecolorallocate($rscImage, 0, 0, 0);
imagestring($rscImage, 2, 5, 5, “Hello World!”, $intFontC);
imagegif($rscImage);
imagedestroy($rscImage);
?>

HTML
<HTML>
<!-- Hello World in HTML -->
<HEAD>
<TITLE>Hello World!</TITLE>
</HEAD>
<BODY>
Hello World!
</BODY>
</HTML>
ASP-C#
<% @ Page Language=”C#” %>
<% =”Hello World!” %>

Hello World for Microsoft ASP (in JavaScript)
<%@ language=”javascript” %>
<html><body>
<%
Response.Write(‘Hello World!’);
%>
</body></html>

ASP.NET
<%= “Hello World!” %>

Hello World in Visual Languages


REM Hello World in Visual Basic for Windows
VERSION 2.00
Begin Form Form1
   Caption         =   “Form1”
   ClientHeight    =   6096
   ClientLeft      =   936
   ClientTop       =   1572
   ClientWidth     =   6468
   Height          =   6540
   Left            =   876
   LinkTopic       =   “Form1”
   ScaleHeight     =   6096
   ScaleWidth      =   6468
   Top             =   1188
   Width           =   6588
   Begin Label Label1
      Caption         =   “Hello World!”
      Height          =   372
      Left            =   2760
      TabIndex        =   0
      Top             =   2880
      Width           =   972
   End
End
Option Explicit

‘Hello World in Visual Basic .NET (VB.NET)
Imports System.Console
Class HelloWorld
    Public Shared Sub Main()
        WriteLine(“Hello, world!”)
    End Sub
End Class

‘ Hello World in Visual Basic 6
Private Sub Form_Load()
Print “Hello World”
End Sub

Hello World in Java Languages


// Hello World in Java
class HelloWorld {
  static public void main( String args[] ) {
    System.out.println( “Hello World!” );
  }
}

// Hello World on a mobile Java device
package helloworld;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloWorld extends MIDlet {
  public HelloWorld()
  {
    Form form = new Form(“Hello World”);
    form.append(“Hello world!”);
    Display.getDisplay(this).setCurrent(form);
  }
  protected void pauseApp() {  }
  protected void startApp() throws
    javax.microedition.midlet.MIDletStateChangeException {  }
  protected void destroyApp(boolean parm1) throws
    javax.microedition.midlet.MIDletStateChangeException {  }
}

<!– Hello World for Java Server Pages –>
<%@ page language=’java’ %>
<%=”Hello World!” %>

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
//
// Hello World Java Servlet
//
public class HelloWorld extends HttpServlet {
public void service(HttpServletRequest request,
HttpServletResponse response)
throws IOException {
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“<html><body>”);
out.println(“Hello World!”);
out.println(“</body></html>”);
}
}

// Hello World in Java using Swing GUI
class HelloWorldSwing {
  static public void main(String args[]) {
    javax.swing.JOptionPane.showMessageDialog(null,”Hello world!”);
  }
}

<html>
<body>
<script language=”JavaScript” type=”text/javascript”>
// Hello World in JavaScript
document.write(‘Hello World’);
</script>
</body>
</html>

Hello World in Scripting Languages

;;; Hello World in Common Lisp
(defun helloworld ()
  (print “Hello World!”)
)

;;; Hello World in Emacs Lisp.
(defun hello-world()
  “Display the string hello world.”
  (interactive)
  (message “hello world”))

# Hello World in Lua
print “Hello world”

{Hello World in Pascal}
program HelloWorld(output);
begin
  WriteLn(‘Hello World!’);
end.

{ Hello World in Borland Pascal 7 for MS-Windows}
PROGRAM HelloWorld;
USES
  WinCRT;
BEGIN
  InitWinCRT;
  WriteLn(‘Hello World!’);
  ReadLn;
  DoneWinCRT;
END.

# Hello World in Python
print “Hello World”

# Hello World for the Unix shells (sh, ksh, csh, bash, …)
echo ‘Hello World!’

# Hello world in perl
print “Hello World!\n”;