Java OOP program to repeat a number of “Hello World” or other user defined string.

class helloOBJ
    Integer count;
    String Greeting;
    helloOBJ() {
        count = 10;
        Greeting = "Hello World.";
    void assignGreeting(String s) {
        if(s!="") Greeting = s;
    void assignCount(Integer i) {
        if(i>0) count = i;
    public void run() {
        for(Integer i=1; i<=count; i++)
            System.out.printf("[%04d] %s\n", i, Greeting);

class helloAPP
    public static void main(String[] args)

        Integer pramCount = args.length;
        helloOBJ myObj = new helloOBJ();

        try {
            if(pramCount>=1) {
                Integer j = Integer.parseInt( args[0] );
                myObj.assignCount( j );
                myObj.assignGreeting( args[1] );
        } catch (Exception e) {
            System.out.println("An error occured, check arguments.");



helloAPP [count [custom string]]

Hello World C++ with Objects

Ok… this is a “Hello World” program in C++ using objects. It illustrates a number of aspects of object oriented programming in C++ allowing you to get a quickstart into C++ programming. First there is the #include directives which tells C++ that the program uses two libraries, iostream and string (actually they specify the header files that define the libraries to be used). “iostream” provides input/output to streams, in this case we are sending a stream to the console. “string” is a string type library that provide a string datatype that is not native to the base C++, this allows us to manipulate strings in an easy manner.

#include <iostream.h>
#include <string.h>
using namespace std;

class oHello
    string hstr;
    void print();

    hstr = "Hello World\n";


void oHello::print()
    cout << hstr;

>int main()
    oHello myObject;
    return 0;

Class oHello is defined as having three methods, oHello method is the constructor that is executed when the object is created, ~oHello is the destructor that is executed when the program destroys the object (in this case, when the program terminates), lastly there is print which sends hstr to the output stream. These are declared as public so that they can be accessed from other modules in the program that are not members of the oHello object class. “hstr” is private to the class and only the class methods can access this data. It is of type string, the object string that was defined in the string class library.

The oHello method does one thing, assign hstr the value of “Hello World\n”. “\n” means add a carriage return to the end of the string. Now, when any member methods access hstr it would contain the value “Hello World\n”.

The print method contains the instruction cout << hstr, this calls the hstr object using the << method which directs it to send the value it contains to the cout stream class, which as stated earlier sends the data to the output stream.

Now that all the objects are defined… we can use them in the main() function which is automatically executed when the program is run. First we create an instance of the oHello object, called myObject. Next we call the print method of the myObject object, which prints “Hello World\n” to the output stream (in this case the console). Lastly since main() is a function it must return something before terminating, so we return the value zero.

Hello World ooREXX

Ok, as my previous post showed how to write a routine oriented hello world program in gforth, I now explain a hello world program using objects in object oriented rexx (ooRexx).

    Object Oriented Hello World in REXX

myobject = .hello~new

::class hello
 ::method init
 expose hellostring
    hellostring = "Hello World"
 ::method print
 expose hellostring
    say hellostring

Like all rexx programs, the main() like section is the beginning lines of the program. The object definitions begin after the main instruction sequence. In this case we have one object called “hello”

::class hello

It contains two methods, a constructor and general purpose method named “print”. Both objects share a variable common to the object called “hellostring”, which contains the string we want the object to print. It is initially set by the constructor to the value “Hello World”. The print method does only one thing, to print the value of the variable “hellostring” to the console.

So, here we have an illustration of using objects, methods, constructors and internal data passing between objects in a rexx program. (Note, I am not going into the details of what is object oriented programming, as if you reading this you should have already studied what is object oriented programming).

The beginning part of the program does two things, create an object named “myobject” of the type “hello” and initialize it. The second instruction calls the “print” method.

Pretty simple.