21
\$\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

13
\$\begingroup\$

bash 20 19 chars

Thanks @manatwork for the useless space after -p!

read -pHello\ World

In action:

echo 'read -pHello\ World' >/tmp/helloworld.sh
chmod +x /tmp/helloworld.sh

Than double click from file manager:

enter image description here

And see:

enter image description here

Having as default shell.

19 16

As question stand for only Hello World and Nothing else, the window have to stay but nothing like print text only once or so on, I think this match requirement too!

yes Hello\ World

There is only 16 chars.

echo >/tmp/helloworld.sh 'yes Hello\ World'

With same procedure this give:

enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Seems like GNOME to me. \$\endgroup\$ – Pierre Arlaud Nov 27 '13 at 14:01
  • 2
    \$\begingroup\$ I think the "choose run in terminal" part should count as, at the very least, 1 byte. Similar to the rules about options passed to interpreters when running some codegolf solution. \$\endgroup\$ – Bakuriu Nov 28 '13 at 16:31
  • 1
    \$\begingroup\$ @Bakuriu Depending on personal usages, you could configure you window manager to not ask and run alway under some shell or terminal of your choice... (I think it's default under MS-Window) \$\endgroup\$ – F. Hauri Nov 28 '13 at 17:55
  • 2
    \$\begingroup\$ @Bakuriu like installing HQ9+ interpreter, adding .hq9+ as mime capacity: running HQ9+ in a terminal windows. So the challenge could be dropped to 1 byte. This answer was based on previous answers, using batch or powershell and running an OS which use this kind of trick by default. \$\endgroup\$ – F. Hauri Nov 28 '13 at 19:26
  • 3
    \$\begingroup\$ @JohannesKuhn Are you crazy! There is no more than 2°C outer! It's too cold!! \$\endgroup\$ – F. Hauri Dec 3 '13 at 21:48
23
\$\begingroup\$

Windows Command Prompt, 26

echo Hello World>.hta&.hta

enter image description here

\$\endgroup\$
  • \$\begingroup\$ This is awesome. Bonus points for spawning two windows? \$\endgroup\$ – Gusdor Nov 27 '13 at 11:44
  • \$\begingroup\$ @Gusdor What do you mean? I only see one spawned window here. \$\endgroup\$ – Iszi Nov 27 '13 at 15:09
  • \$\begingroup\$ @Iszi I made the assumption that the batch file was run from desktop, not typed. Whoops! \$\endgroup\$ – Gusdor Nov 27 '13 at 15:25
  • \$\begingroup\$ @Gusdor I think that's why he called it "Windows Command Prompt" instead of "Batch". Otherwise, it'd lose to Johannes' answer anyway. \$\endgroup\$ – Iszi Nov 27 '13 at 15:31
  • 1
    \$\begingroup\$ @Iszi: This opens a new window, so it doesn’t matter whether the command is echoed in a different one… \$\endgroup\$ – Ry- Nov 29 '13 at 0:39
15
\$\begingroup\$

R, 23

plot(1,m="Hello World")

This opens a plot window.

\$\endgroup\$
  • \$\begingroup\$ +1. You can shorten sub= into s= thanks to partial matching however. \$\endgroup\$ – plannapus Nov 26 '13 at 17:50
  • \$\begingroup\$ @plannapus Thanks, good idea! I modified my code. \$\endgroup\$ – Sven Hohenstein Nov 26 '13 at 18:21
  • \$\begingroup\$ Sven, this doesn't print "hello world inside and nothing else" :) I was participating in a similar challenge and it had to be done differently, see codegolf.stackexchange.com/a/19807/2800 \$\endgroup\$ – Tomas Feb 2 '14 at 17:56
  • 1
    \$\begingroup\$ @Tomas This challenge is different. From the question: "I do not care about the contents of the window frame". \$\endgroup\$ – Sven Hohenstein Feb 2 '14 at 20:35
  • \$\begingroup\$ Well, but this is not about the frame, but also the text - axis label "index", the numbers etc.. \$\endgroup\$ – Tomas Feb 2 '14 at 21:17
14
\$\begingroup\$

Dyalog APL (20)

⎕SM←'Hello World'1 1

Picture: Picture

\$\endgroup\$
  • 1
    \$\begingroup\$ Special characters!?! HAXXX! \$\endgroup\$ – AJMansfield Nov 27 '13 at 0:11
11
\$\begingroup\$

Powershell, 23

'Hello World'>.hta;.hta

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Nice! Beats my "real" solution, and is only 3 characters longer than the shortcut method. Though, it's arguable that this isn't really much better than just using Hello World alone and calling it HTML - since that's almost exactly what you've done. You've just used PowerShell to build and execute it. \$\endgroup\$ – Iszi Nov 27 '13 at 15:05
11
\$\begingroup\$

HTML (kinda), 17

data:,Hello World

Paste that into your browser's address bar.

Javascript, 25

open("data:,Hello World")

This uses your browser's window.open and a data uri.

A Data URIs's mime-type and charset default to text/plain;charset=US-ASCII when omitted.

Javascript, 19

eval($("s").text())

This one only works when this answer is the top (or accepted) answer and it is run on THIS stackoverflow page (via your JavaScript console). :-)

open("data:,Hello World");

\$\endgroup\$
  • \$\begingroup\$ Funny trick. But sadly it depends on the ordering of the posts, which may vary. \$\endgroup\$ – manatwork Nov 27 '13 at 15:21
  • 1
    \$\begingroup\$ Well, it'll work as long as it is the accepted answer (and the Question doesn't have an "<s>") \$\endgroup\$ – David Murdoch Nov 27 '13 at 15:25
  • \$\begingroup\$ Lol. I have to upvote for your optimism. \$\endgroup\$ – manatwork Nov 27 '13 at 15:27
  • \$\begingroup\$ Can you explain how this will work please? I am using chrome and have tried running it on the console, but I get Unexpected token ILLEGAL. Do you have to be top answer for this to work? \$\endgroup\$ – Quillion Nov 27 '13 at 21:13
  • \$\begingroup\$ Yes, it needs to be the top answer for it to work. OR I could just edit the question itself to include the required <s>open("data:,Hello World");</s> HTML, but that might be cheating a little bit too much. :-p \$\endgroup\$ – David Murdoch Nov 27 '13 at 21:36
9
\$\begingroup\$

Matlab, 30 27 20

title('Hello World')

Are plot windows allowed? It does not have any buttons inside.

\$\endgroup\$
  • \$\begingroup\$ Yeah plot window is fine :) as long as it is window, I do not care \$\endgroup\$ – Quillion Nov 26 '13 at 16:05
  • \$\begingroup\$ figure('name','Hello World') is shorter \$\endgroup\$ – magu_ Nov 27 '13 at 7:31
  • \$\begingroup\$ @magu_ Good idea. But I suppose it's against the rule "a window that says hello world inside". \$\endgroup\$ – Sven Hohenstein Nov 27 '13 at 8:10
  • 1
    \$\begingroup\$ @SvenHohenstein Hm, maybe. To say at least something usefull: you don't need the (1) necessarly. Making the code 3 characters smaller. \$\endgroup\$ – magu_ Nov 27 '13 at 8:23
  • 1
    \$\begingroup\$ You don't actually need figure; \$\endgroup\$ – Torbjørn T. Nov 27 '13 at 23:26
8
\$\begingroup\$

Java, 117 chars

import java.awt.*;class C{public static void main(String[]a){new Frame(){{add(new Label("Hello World"));show();}};}}

With formatting:

import java.awt.*;

class C {
    public static void main(String[] a) {
        new Frame() {
            {
                add(new Label("Hello World"));
                show();
            }
        };
    }
}

We can avoid having to explicitly declare a variable by using initializer blocks inside an anonymous subclass of Frame. Interestingly, using awt, it's just as many characters to import java.awt.*; as it is to just fully qualify both classnames.

\$\endgroup\$
  • 8
    \$\begingroup\$ You can call args whatever you want; a is sufficient. \$\endgroup\$ – daniero Nov 26 '13 at 20:19
  • \$\begingroup\$ @daniero thanks for the suggestion, pretty silly of me to miss that :) \$\endgroup\$ – swilliams Nov 28 '13 at 7:20
  • 1
    \$\begingroup\$ s/class/enum/ \$\endgroup\$ – Thomas Eding Nov 28 '13 at 7:38
  • \$\begingroup\$ like @ThomasEding hints replacing the class by enum shaves off one byte \$\endgroup\$ – masterX244 Mar 14 '14 at 9:48
  • \$\begingroup\$ @masterX244 That won't be syntactically correct unless a semicolon is added before the public static... to end the list of enum constants... see stackoverflow.com/questions/7318011/…. In either case you end up with the same number of characters. \$\endgroup\$ – swilliams Mar 16 '14 at 20:27
7
\$\begingroup\$

Mathematica 29 27 25

With 1 byte saved thanks to CatsAreFluffy.

DialogInput@"hello world"

hello world

\$\endgroup\$
  • \$\begingroup\$ CreateDialog is shorter. \$\endgroup\$ – alephalpha Nov 27 '13 at 3:10
  • \$\begingroup\$ Thanks. I thought CreateDialog would insert an OK button. \$\endgroup\$ – DavidC Nov 27 '13 at 3:57
  • \$\begingroup\$ DialogInput is 1 byte shorter \$\endgroup\$ – CalculatorFeline Feb 28 '16 at 5:57
  • \$\begingroup\$ Yes, thanks, and the curly braces are also unnecessary. \$\endgroup\$ – DavidC Feb 28 '16 at 13:17
5
\$\begingroup\$

Shell, 32

xmessage -buttons '' Hello World
\$\endgroup\$
  • 1
    \$\begingroup\$ There is a 1 character shorter way: xterm -e 'read -p Hello\ World'. \$\endgroup\$ – manatwork Nov 26 '13 at 15:29
  • \$\begingroup\$ Mine would have been way shorter if I didn't have to -buttons '' :( \$\endgroup\$ – Hasturkun Nov 26 '13 at 15:31
  • \$\begingroup\$ @Hasturkun I agree, but I had to add get rid of the buttons requirement because javascript would win with their alert or some other shortcut like that, and I felt that it would be too unfair and too plain especially to some other languages. \$\endgroup\$ – Quillion Nov 26 '13 at 15:42
  • \$\begingroup\$ @Hasturkun, without the no button restriction your xmessage Hello World solution counts only 20 characters, but then Windows cmd would beat you with msg * Hello World of just 17 characters. So be grateful for the restriction. :) \$\endgroup\$ – manatwork Nov 26 '13 at 15:52
5
\$\begingroup\$

Ruby with Shoes, 28

Shoes.app{para'Hello World'}

Result:

screenshot

\$\endgroup\$
5
\$\begingroup\$

Python 2/3, 54 characters

Capitalize the t in tkinter to make it work on Python 2.

__import__("tkinter").Label(text="Hello World").pack()
\$\endgroup\$
  • \$\begingroup\$ when I try that i get: AttributeError: Label instance has no attribute 'show'. However __import__("Tkinter").Label(text="Hello World").pack() gives me the desired effect. \$\endgroup\$ – plannapus Nov 27 '13 at 8:03
  • \$\begingroup\$ @plannapus Actually I had copied a previous version with that error, not the correct one. Thanks. \$\endgroup\$ – Ramchandra Apte Nov 27 '13 at 8:04
4
\$\begingroup\$

Windows Batch, 23

@pause|echo Hello World
  • Opens a black window that shows Hello World, nothing else.
  • Now the windows stays open
  • There are no buttons in the window.
\$\endgroup\$
  • 2
    \$\begingroup\$ Requirement is: create a window not force window manager to create a window \$\endgroup\$ – F. Hauri Nov 26 '13 at 19:36
  • 4
    \$\begingroup\$ @F.Hauri Ok, I'll look how to write a window manager. Until someone post that, consider all posts as violation of your requirement. \$\endgroup\$ – Johannes Kuhn Nov 26 '13 at 19:37
  • 1
    \$\begingroup\$ As the op states, it doesn't matter how the window looks. If it is a plot window or a shell window, who cares? \$\endgroup\$ – Johannes Kuhn Nov 26 '13 at 20:04
  • 5
    \$\begingroup\$ I absolutely agree :) now this is absolutely acceptable because it is a window and it does say hello world :) well done I love it \$\endgroup\$ – Quillion Nov 26 '13 at 20:05
  • 1
    \$\begingroup\$ @JohannesKuhn PowerShell can still beat it. Edit coming up. \$\endgroup\$ – Iszi Nov 26 '13 at 22:08
4
\$\begingroup\$

Rebol 2, 29

view layout[txt{Hello World}]

enter image description here

\$\endgroup\$
4
\$\begingroup\$

ExtJS (Javascript) 44

new Ext.Window({html:'Hello world',}).show()

new Ext.Window({html:'Hello world',}).show()
<link rel="stylesheet" type="text/css"
  href="http://dev.sencha.com/deploy/dev/resources/css/ext-all.css"/>
<script type='text/javascript'
  src="http://dev.sencha.com/deploy/dev/adapter/ext/ext-base.js"></script>
<script type='text/javascript'
  src="http://dev.sencha.com/deploy/dev/ext-all.js"></script>

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

Tcl/Tk, 34

pack [label .l -text Hello\ World]
\$\endgroup\$
3
\$\begingroup\$

AutoHotkey, 26

GUI,Add,Text,,Hello World!
\$\endgroup\$
3
\$\begingroup\$

AutoIt v3, 32

ToolTip("Hello World")
Sleep(9^9)
\$\endgroup\$
  • \$\begingroup\$ Wouldn't MsgBox(0,"","Hello World") be shorter? It's 26 characters. \$\endgroup\$ – Mr. Llama Dec 3 '13 at 16:05
  • \$\begingroup\$ The requirements are to have no Ok or Cancel buttons within the window. The code you suggest has an OK button. :( \$\endgroup\$ – Chris Dec 3 '13 at 18:18
  • \$\begingroup\$ Ah balls, I missed that requirement. \$\endgroup\$ – Mr. Llama Dec 5 '13 at 17:16
3
\$\begingroup\$

HTML, 11

Hello World

Screenshot:

HTML Hello World

I guess this shouldn't count, but I think it would be interesting to see such an answer here.

\$\endgroup\$
  • 3
    \$\begingroup\$ I agree it shouldn't count. The same can be accomplished by loading a simple TXT file in the browser. \$\endgroup\$ – Iszi Nov 27 '13 at 5:12
  • \$\begingroup\$ Your count is off, that's 20 characters. \$\endgroup\$ – jmoreno Nov 27 '13 at 5:18
  • 2
    \$\begingroup\$ @Iszi without HTML tags, this is really just getting rendered as a plain text file. I would argue that you can't even call it an html submission without <html> </html> \$\endgroup\$ – Cruncher Nov 27 '13 at 13:54
  • \$\begingroup\$ @Cruncher Google Chrome actually adds an HTML skeleton including a <pre> which contains the file's contents (you can use Chrome dev tools for verifying this behavior). \$\endgroup\$ – ComFreek Nov 27 '13 at 16:30
  • 1
    \$\begingroup\$ @Cruncher Well, maybe if you're using IE6, but in any modern browser, you can omit the <html> tags, as well as the <body> and <head> tags, and the browser will automatically fill out the "skeleton". For example, try <div style="background:#ff0">Hello</div> in a modern browser, and it will universally render "hello" with a yellow background. \$\endgroup\$ – Braden Best Feb 11 '14 at 5:09
3
\$\begingroup\$

PowerShell: 162 124 114 or 20


The Long Way Around

($t=($a='New-Object Windows.Forms')+".Label"|iex).Text='Hello World';($x=iex $a".Form").Controls.Add($t);$x.Show()

Since PowerShell really doesn't have any built-in GUI functionality, I'm having a hard time coming up with anything shorter than this which I feel really fits the original spirit of the challenge. (Or, at least, fits within the parameters several of us have assumed were implied.)

enter image description here

Changes from original:

  • Removed window size definition. Apparently, it's optional and the default is plenty large enough.
  • Incorporated changes provided by SpellingD in comments. Note: The window which spawns will hang - you'll need to kill PowerShell via Task Manager.

Alternative 20-Character Approach

Removing some assumed-implied requirements, we can also meet this challenge a-la Johannes Kuhn with this:

'Hello World';for(){}

Save as a .ps1 file. Make sure the system's ExecutionPolicy allows unsigned scripts. Right-click and select "Run with PowerShell".

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Show instead of ShowDialog should do it, right? \$\endgroup\$ – It'sNotALie. Nov 26 '13 at 21:05
  • \$\begingroup\$ Show() does work, but doesn't let you close the window. Which isn't a requirement! \$\endgroup\$ – SpellingD Nov 26 '13 at 21:22
  • \$\begingroup\$ My edit to golf this was rejected, and my code isn't sufficiently different enough to warrant making a new answer, so here's how you could golf this to 114, I guess. ($t=($a='New-Object Windows.Forms')+".Label"|iex).Text='Hello World';($x=iex $a".Form").Controls.Add($t);$x.Show() \$\endgroup\$ – SpellingD Nov 26 '13 at 21:57
  • \$\begingroup\$ @SpellingD Thanks. I've incorporated your changes to the "true" solution, and also added a "cheap method" which currently beats all contenders. (Except, arguably, HQ9+ of course.) \$\endgroup\$ – Iszi Nov 26 '13 at 22:17
3
\$\begingroup\$

Factor, 36 code + 23 imports = 59

USING: ui ui.gadgets ; "Hello World" <label> "" open-window

When this is run inside the listener, the imports will be brought in automatically. You only need them to deploy a standalone executable.

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

Processing, 23

Based on my answer here: Make a PNG image with "Hello World!" with programming APIs, in the shortest code possible

text("HeΠo World!",9,8);

enter image description here


24 char non-cheating solution:

text("Hello World!",9,9);

enter image description here

Do I get extra points for this being the 42nd answer?

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

Groovy, 68 27

Using console.

print"Hello World";for(;;);

Using Frame.

new java.awt.Frame(){{add new java.awt.Label("Hello World")}}.show()

Inspired by @swilliams Java answer.

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

Processing, 37 chars:

void draw(){text("Hello World",0,9);}

Various things used to reduce strokes:

  • Sketch window is spawned by default; no need to manually create it
  • Using draw is shorter than setup (although the text is then redrawn each frame)
  • Uses default size, background, fill, font, and font size
  • You don't actually need all 10 pixels height for the text
\$\endgroup\$
2
\$\begingroup\$

Bash (36 chars)

xmessage -buttons "" "Hello World!"

Looks like crap, but works as requested.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ The rule “inside it must say hello world only” was explicitly added to avoid so simple solutions. \$\endgroup\$ – manatwork Nov 27 '13 at 13:27
  • \$\begingroup\$ ok, fixed this. \$\endgroup\$ – klingt.net Nov 27 '13 at 13:32
  • \$\begingroup\$ Now it's correct, but there is another problem: it became duplicate of Hasturkun's answer. \$\endgroup\$ – manatwork Nov 27 '13 at 13:56
  • 1
    \$\begingroup\$ Damn, at least i've a screenshot :) \$\endgroup\$ – klingt.net Nov 27 '13 at 14:09
2
\$\begingroup\$

Ghostscript 50

0 0 moveto/Courier 20 selectfont(Hello World)show

Could make it 49 by using a 9-point font, but it's a little hard to read.

Can make a smaller window by invoking gs with a geometry argument for an additional 8 chars.

gs -g200x30 hello.ps
\$\endgroup\$
2
\$\begingroup\$

C#, 72

class P{static int Main(){System.Console.Write("hello world");for(;;);}}

Based on the answer by @Noctis. I would have suggested it as a comment if I had enough Rep.

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

Delphi - 73 62

uses Dialogs;begin MessageDlg('Hello World',mtCustom,[],0)end.

Edit after @manatwork and @Gareth 's suggestions. Which actually brings me to a character count of 62.

\$\endgroup\$
  • \$\begingroup\$ How you get that character count? The code you posted has 77 characters and the minimum to which it can me reduced is 64: uses Dialogs;begin MessageDlg('Hello World',mtCustom,[],0)end. \$\endgroup\$ – manatwork Nov 29 '13 at 15:43
  • 1
    \$\begingroup\$ You need to count newlines as part of your character count. That's why many answers on this site are all on one line. \$\endgroup\$ – Gareth Dec 2 '13 at 14:44
  • \$\begingroup\$ Ah, I didn't know that. I'll edit my answer. \$\endgroup\$ – R-D Dec 2 '13 at 14:48
2
\$\begingroup\$

Shell script: 56 character

convert -size 99x9 xc: -draw 'text 0,10 Hello\ World' x:

Sample output:

Hello World

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

Ti84-Basic, 25

ClrHome
Disp "HELLO WORLD

Arduino, 27

Serial.print("Hello World")

Place this in void setup()

Game Maker Language, 40

show_message_ext("Hello World","","","")

I'm pretty sure this is the shortest way without adding any extension packages.

\$\endgroup\$
  • \$\begingroup\$ If you would accept an OK button, show_message("Hello World") is 27 characters. \$\endgroup\$ – Timtech Nov 27 '13 at 11:40
  • \$\begingroup\$ Extremely necroing this one, but I have 2 (slight) remarks about your Ti84-Basic one. 1: couldn't you drop the final "? 2: Should you count it in bytes, we have a clear winner here ;) \$\endgroup\$ – ɐɔıʇǝɥʇuʎs Mar 30 '14 at 14:30
  • \$\begingroup\$ @Synthetica Yeah. Forgot that :) \$\endgroup\$ – Timtech Mar 30 '14 at 15:24
  • \$\begingroup\$ Your TI-BASIC answer does not open a window, and it outputs capital rather than lowercase letters. \$\endgroup\$ – lirtosiast Jun 7 '15 at 15:07

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.