Comparison of various 'hello world' programs
A simple programming tute / comparison for newbies by MrLeachy

This tute is aimed at newbies to programming and to give a comparison of what
some of the very simple procedures look like in 3 programming languages i've used,
namely Java C++ and Visual Basic.

if you've done programming before this might still be good reading but i will assume youre completly new to it the background behind the hello world program is just to make a simple first program to print or display the text "hello world" or something similar on the screen

here is a version of this written in visual basic:


Option Compare Database - this part im not so sure about, it was in every program i wrote in vb
so im not sure what it does, we were just told to leave it alone

Option Explicit - this says that all variables must be declared to be used, mainly use to avoid compile and logic problems

Sub hw() - start of the 'subroutine' ie progra

Debug.Print "Hello World!" - this prints out the text hello world in a dos like window in visual basic

MsgBox "Hello world!" - this displays hello world in a message box

End Sub - this is the end of this part of the program, in this case the whole program :-)


here is a hello world program written in C++


this first part is a block comment, any text between /* and */ is ignored by the compiler

* Hello World program *

these are header import lines, used to import non default packages into your program
#include <iostream.h>

this is the main function, every C++ program needs one of these unless it is in a seperate file (i think)
main() {
this line is a cout statement pronounced see-out, it simply prints a line of text in a dos window if you compiled your program ina dos or unix prompt
cout << "Hello world\n";

this line returns a value or 0 to the system, meaning the program terminated normally
return 0;

this closing brace signifies the end of the main function, it corresponds to the opening one at the top


and here is a hello world program written in Java:


this statemnt imports the swing packages for java - they provide GUI window components
import javax.swing.*;

this starts the 'class' Helloworld, dont worry about the public bit as its too in depth to explain in this tute
public class Helloworld {

this starts the main function, almost every java class needs one except for applets and user written modules that are in sperate files, just put this in every application you write unless youre more advanced and know what youre doing (i dont yet)
public static void main (String args[]) {

this line prints hello world on your dos or unix command window
System.out.println("Hello world");

this line displays hello world in a java message box, you need to put null at the start but im not sure why yet
JOptionPane.showMessageDialog(null, "Hello world");

tell the system the program terminated normally here

end of the main method
end of the class


hope that this tute has given some of our programming newbies an insight into some of the more common languages out there and that some people find this tute useful :-)


again i apologise for the formatting, the attached file is much easier to read