A Simple Hello World using Java

This is an example of a simple hello world using Java.

interface Printer {
    void print(Message message);    

class Message {
    private String message;
    public Message(String message) {
        this.message = message;    
    public void print(Printer printer) {
    public String toString() {
        return message;   

abstract class AbstractPrinterFactory {
    public static AbstractPrinterFactory getFactory(){
        return new SystemOutPrinterFactory();   
    public abstract Printer getPrinter();    

class SystemOutPrinterFactory extends AbstractPrinterFactory {
    public Printer getPrinter() {
        return new SystemOutPrinter();   

class SystemOutPrinter implements Printer {
    public void print(Message message) {

public class HelloWorld {
    public static void main(String[] args) {
        Message message = new Message("Hello, World!");
        AbstractPrinterFactory factory = AbstractPrinterFactory.getFactory();
        Printer printer = factory.getPrinter(); 

Just for fun (H)

No Comments

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked