22
\$\begingroup\$

Create a window that says hello world inside and nothing else. You can not have any ok or cancel buttons inside. It must be just a plain window that says hello world. I do not care about the contents of the window frame or how the window looks, but inside it must say hello world only.

Example:
enter image description here

Shortest code wins.

EDIT: I am sorry Johannes Kuhn the window has to actually stay there, it may not close right away. I didn't think of this scenario and as such didn't account for this.

EDIT 2: We currently have 3 tied answers (20 characters). Any suggestions of who should be the winner is welcome.

\$\endgroup\$
  • 1
    \$\begingroup\$ Does the window have to be large enough to display the text when it pops up, or is it okay to require the user to resize the window? \$\endgroup\$ – Iszi Nov 26 '13 at 19:55
  • \$\begingroup\$ It doesn't have to be large enough to display the text, it just has to be a window, meaning just be this container looking thing that has text and does not close until it is told to. \$\endgroup\$ – Quillion Nov 26 '13 at 20:00
  • \$\begingroup\$ I can make it as short as Sven's, but with OK and Cancel buttons :( \$\endgroup\$ – Teresa e Junior Nov 27 '13 at 8:27
  • \$\begingroup\$ Looks like there's a Bash answer at 19 now. \$\endgroup\$ – Iszi Nov 27 '13 at 15:31
  • 2
    \$\begingroup\$ Can I do a VB 6 solution with a label with "Hello World"? 0 code solution? \$\endgroup\$ – Cruncher Nov 27 '13 at 16:41

47 Answers 47

2
\$\begingroup\$

C#, 93

u̶s̶i̶n̶g̶ ̶S̶y̶s̶t̶e̶m̶;̶c̶l̶a̶s̶s̶ ̶P̶r̶o̶g̶r̶a̶m̶{̶s̶t̶a̶t̶i̶c̶ ̶v̶o̶i̶d̶ ̶M̶a̶i̶n̶(̶)̶{̶C̶o̶n̶s̶o̶l̶e̶.̶O̶u̶t̶.̶W̶r̶i̶t̶e̶(̶"̶h̶e̶l̶l̶o̶ ̶w̶o̶r̶l̶d̶"̶)̶;̶C̶o̶n̶s̶o̶l̶e̶.̶R̶e̶a̶d̶K̶e̶y̶(̶)̶;̶}̶}̶

If you didn't need the screen to stay open, it'll be 81:

using System;class Program{static void Main(){Console.Out.Write("hello world");}}

As per shaming comment (so obvious, yet overlooked):

using System;class A{static void Main(){Console.Out.Write("hello world");Console.ReadKey();}}

Nice catch :)

\$\endgroup\$
  • \$\begingroup\$ I don't know C# much. Can you write using System.Console;? I think that would save you 6 chars \$\endgroup\$ – Cruncher Nov 27 '13 at 13:58
  • \$\begingroup\$ Nope ... tried that :) (I'm not THAT simpleminded :) \$\endgroup\$ – Noctis Nov 27 '13 at 22:22
  • \$\begingroup\$ Does the class really need to be called Program? \$\endgroup\$ – Rees Mar 30 '14 at 15:33
  • \$\begingroup\$ What is Console.Out? This ain't Java. \$\endgroup\$ – NoOneIsHere Sep 27 '16 at 3:49
  • \$\begingroup\$ @NoOneIsHere it's a dark incantation taken from here . beware the demons you might summon when using it \$\endgroup\$ – Noctis Sep 27 '16 at 5:09
2
\$\begingroup\$

Windows batch file, 18

@set/p=Hello World

Save as a batch file, and run by double clicking. Looks just how you'd expect.

Screenshot of script output

\$\endgroup\$
2
\$\begingroup\$

FLTK, 57 characters

Function{}{}{Fl_Window{}{}{Fl_Box{}{label{Hello World}}}}

Ungolfed:

Function {} {} {
    Fl_Window {} {} {
        Fl_Box {} {
            label {Hello World}
        }
    }
}

Sample output:

Hello World displayed in a FLTK window

\$\endgroup\$
2
\$\begingroup\$

Quomplex, 11

Hello World

When no output (*) is defined, Quomplex outputs the program's source code.

\$\endgroup\$
1
\$\begingroup\$

Groovy, 77

import javax.swing.*
f=new JFrame()
f.add(new JLabel("Hello World"))
f.show()

Note: the window will be super tiny and you'll need to resize it to view the text.

\$\endgroup\$
  • \$\begingroup\$ Why don't you resize the window after it is produced, and then add the picture of it to your posting? \$\endgroup\$ – DavidC Nov 26 '13 at 22:59
  • 1
    \$\begingroup\$ import java.awt.*; and f=new Frame() and new Label I think can trim this quite a bit \$\endgroup\$ – Cruncher Nov 28 '13 at 18:03
1
\$\begingroup\$

APLX, 44

'A' ⎕WI 'New' 'Document' 'text' 'Hello World'

You could probably get it down from there.

\$\endgroup\$
1
\$\begingroup\$

Java - 157

using DrawString

Ungolfed:

import java.awt.*;
class A extends Frame {
    public static void main(String[]a){
        new A().show();
    }
    public void paint(Graphics g)
    {
        g.drawString("Hello World",9,50);
    }
}

Golfed:

import java.awt.*;class A extends Frame{public static void main(String[]a){new A().show();}public void paint(Graphics g){g.drawString("Hello World",9,50);}}
\$\endgroup\$
  • \$\begingroup\$ You could save a character by changing the 50 to 9, although that would make it non-centered. \$\endgroup\$ – AJMansfield Nov 27 '13 at 0:50
  • \$\begingroup\$ @AJMansfield Obviously I've tried that. The problem is not centring but that you actually cannot see it at all no matter how much you resize the window. 0, 0 lives at the very top left of the window, not top left of the content (which is asinine). I suppose if your OS has no title bar on the window then I can save a char. \$\endgroup\$ – Cruncher Nov 27 '13 at 13:52
1
\$\begingroup\$

JavaScript, 32

open('javascript:"Hello World"')
\$\endgroup\$
1
\$\begingroup\$

Python: 20 characters

input("Hello World")

Technically would be correct right? If you save it to a script and don't call it from a shell. Meh, I think the best python solution has been given already.

\$\endgroup\$
1
\$\begingroup\$

C# 87

Ungolfed:

using s = System.Console;
class C
{
    static void Main()
    {
        s.Write("Hello World");
        s.Read();
    }
}

Golfed:

using s = System.Console;class C{static void Main(){s.Write("Hello World");s.Read();}}

Window will stay open until user inputs a carriage return

\$\endgroup\$
  • \$\begingroup\$ you can write using s=System.Console; to save 2 bytes (I think, I'm not a C# programmer lol) \$\endgroup\$ – Sagittarius Sep 11 at 16:53
1
\$\begingroup\$

C+xcb+Cairo 2540 (82 lines)

Not exactly short. :) This is literally the PNG hello world from the Cairo docs, with just enough xcb to open a window and find the parameters needed to register the window with Cairo.

//xcr.c
//cc -o xcr $(pkg-config --cflags --libs cairo xcb xcb-icccm) xcr.c -lcairo -lxcb -lxcb-icccm
#include <stdlib.h>
#include <string.h>
#include <cairo.h>
#include <cairo-xcb.h>
#include <xcb/xcb.h>
#include <xcb/xcb_image.h>
#include <xcb/xcb_aux.h>
#include <xcb/xcb_icccm.h>

int main (int argc, char *argv[])
{
    int width = 300, height = 400;
    int scrno;
    xcb_screen_t *scr;
    xcb_connection_t *connection;
    xcb_screen_iterator_t iter;
    xcb_drawable_t win;
    unsigned int white;
    xcb_visualtype_t *visual_type;
    xcb_depth_iterator_t depth_iter;

    connection = xcb_connect(NULL,&scrno);
    iter = xcb_setup_roots_iterator(xcb_get_setup(connection));
    for (; iter.rem; --scrno, xcb_screen_next(&iter))
        if (scrno == 0)
        {
            scr = iter.data;
            break;
        }
    win = xcb_generate_id(connection);
    white = scr->white_pixel;
    xcb_create_window(connection, XCB_COPY_FROM_PARENT,
            win, scr->root,
            0, 0,
            width, height,
            5,
            XCB_WINDOW_CLASS_INPUT_OUTPUT,
            scr->root_visual,
            XCB_CW_BACK_PIXEL,
            &white);
    xcb_icccm_set_wm_name(connection, win, XCB_ATOM_STRING, 8, strlen("xcr"), "xcr");
    xcb_map_window(connection, win);
    xcb_flush(connection);

    depth_iter = xcb_screen_allowed_depths_iterator(scr);
    for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
        xcb_visualtype_iterator_t visual_iter;

        visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
        for (; visual_iter.rem; xcb_visualtype_next(&visual_iter)) {
            if (scr->root_visual == visual_iter.data->visual_id) {
                visual_type = visual_iter.data;
                goto visual_found;
            }
        }
    }
visual_found: ;

    {
        cairo_surface_t *surface =
            cairo_xcb_surface_create (connection, win, visual_type, width, height);
        cairo_t *cr = cairo_create (surface);

        cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
        cairo_set_font_size (cr, 32.0);
        cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
        cairo_move_to (cr, 10.0, 50.0);
        cairo_show_text (cr, "Hello, world");

        cairo_surface_flush(surface);
        xcb_flush(connection);

        sleep(100);

        cairo_destroy (cr);
        //cairo_surface_write_to_png (surface, "hello.png");
        cairo_surface_destroy (surface);
    }

    xcb_disconnect(connection);
    return 0;
}
\$\endgroup\$
0
\$\begingroup\$

PureBasic

Console Window - 42 bytes

OpenConsole()
Print("Hello World")
Input()

If console windows are not allowed, and actual GUI windows are required:

GUI Window - 96 bytes

OpenWindow(0,0,0,99,99,"")
TextGadget(0,0,0,99,99,"Hello World")
While WindowEvent()<>13116:Wend
\$\endgroup\$
0
\$\begingroup\$

Windows command shell, 24 characters

Runs as is from command line or by saving to .cmd or .bat file.

start echo "Hello World"
\$\endgroup\$
0
\$\begingroup\$

Lua + LÖVE: 57 characters

function love.draw()love.graphics.print("Hello World")end

Sample run:

bash-4.3$ ls -l
total 4
-rw-rw-r-- 1 manatwork manatwork 57 Aug  2 13:16 main.lua

bash-4.3$ love .

Sample output:

Hello World displayed in a LÖVE window

\$\endgroup\$
-1
\$\begingroup\$

HTML Application, 11

Hello World

Save the file as something.hta and run it. Unlike HTML viewed in a browser, an HTML Application does not add any extra chrome (e.g. adress bar) to the window.

helloworld.hta

\$\endgroup\$
  • \$\begingroup\$ I'd say this is about as valid as the "HTML" answer with the same code. \$\endgroup\$ – Iszi Nov 27 '13 at 17:14
  • \$\begingroup\$ I know it feels that way, so I had to disguise it in my powershell and command prompt answers :) But seriously, this does what it's supposed to do, only in HTA you do the GUI in HTML, just like you'd use XAML in a WPF application. It just happens that in HTML you don't need print, echo, or quotation marks to output a string. I wonder if it would be "more valid" if I wrote <script>document.write("Hello World")</script>. \$\endgroup\$ – Danko Durbić Nov 28 '13 at 13:27
-2
\$\begingroup\$

Javascript:

alert("hello world inside and nothing else")

With a slight bend of the rules ;)

\$\endgroup\$
-3
\$\begingroup\$

JavaScript - 20

alert("Hello World")
\$\endgroup\$
  • \$\begingroup\$ This also has "OK" i it... \$\endgroup\$ – dav_i Nov 27 '13 at 11:03
  • 4
    \$\begingroup\$ Yeah this one doesn't meet the requirements, sorry. \$\endgroup\$ – Timtech Nov 27 '13 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.