Hello World window

22

6

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.

Quillion

Posted 2013-11-26T15:03:07.763

Reputation: 809

1Does 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? – Iszi – 2013-11-26T19:55:35.983

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. – Quillion – 2013-11-26T20:00:52.860

I can make it as short as Sven's, but with OK and Cancel buttons :( – Teresa e Junior – 2013-11-27T08:27:52.513

Looks like there's a Bash answer at 19 now. – Iszi – 2013-11-27T15:31:03.483

2Can I do a VB 6 solution with a label with "Hello World"? 0 code solution? – Cruncher – 2013-11-27T16:41:18.307

I think this post has reached the point where community decides. Post it, and lets see what the solution itself is. I mean it is impossible to have 0 code I believe since at least Hello World would go in somewhere. Nor am I good at VB to know what exactly you mean. – Quillion – 2013-11-27T16:48:23.240

Do the answers in this answer not qualify?

– David Murdoch – 2013-11-27T20:03:11.740

I think this post has actually reached the point of pointlessness. The challenge was ill-defined enough that some people (whether joking or not) seem to think Hello World can be claimed as an answer for HTML/HTA. Some answers do nothing but output to the console, without actually creating a new window, in certain cases. – Iszi – 2013-11-27T21:39:54.793

@Iszi I value your opinion, just tell me what to change and how then I shall do so. My english sucks, and that causes my ideas to be projected incorrectly, so I am always listening. However at this point I believe that I can't change requirement except not accept any answers that simply show hello world in notepad and expect it to be accepted. – Quillion – 2013-11-27T21:44:14.143

@Quillion I agree that it's really too late to change the requirements. I'm not sure really how to restrict the requirements in a way that prevents the current problems without being overly restrictive/verbose, though. – Iszi – 2013-11-27T21:52:14.793

I suggest adding some circles next time. HTML/Bash will have a hard time to draw them (forbid external images, force the circle to have at least a random width). Real toolkits shouldn't have a big problem with that requirements. And BTW: My echo Hello World answer was a try to exploit the rules. As such, I had do defend it. – Johannes Kuhn – 2013-11-27T23:28:25.957

Can the "Hello World" text be the title bar text? – sergiol – 2017-11-15T01:19:23.440

@sergiol no the rule is that inside of the window it should say hello world, title doesn't count – Quillion – 2017-11-15T02:47:02.570

Submitted Windows Batch at 18 chars: http://codegolf.stackexchange.com/a/25100/571 This beats the 19 char bash one, but not the debated 16 bash one.

– TessellatingHeckler – 2014-03-31T01:21:35.620

Answers

13

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

F. Hauri

Posted 2013-11-26T15:03:07.763

Reputation: 2 654

The space after -p seems to be optional. By the way, which file manager are you using? – manatwork – 2013-11-27T12:54:21.197

1Seems like GNOME to me. – Pierre Arlaud – 2013-11-27T14:01:58.513

Yes, it's Gnome, but this have to work quite same under KDE, FVvm or else... I don't like this but if answer based on powershell or batch under windows, could be accepted, also this have to be accepted too. – F. Hauri – 2013-11-27T14:55:16.020

@F.Hauri Giving in to the dark side as well, I see? – Iszi – 2013-11-27T15:04:38.467

2I 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. – Bakuriu – 2013-11-28T16:31:55.780

Ok, if you add 1 byte, but accept my 16 chars answer ( +1 -> 17 ) ;-) – F. Hauri – 2013-11-28T17:52:50.993

1@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) – F. Hauri – 2013-11-28T17:55:43.663

@F.Hauri Yes, you could also create an alias to avoid speciying the options for the interpreter, but this doesn't meant that you aren't simply launching a program, but you are "giving it some help" opening a new window for him. With a complex enough configuration you can solve almost any problem in a few bytes, putting the rest of the programs into "configuration" options. – Bakuriu – 2013-11-28T19:14:14.313

2@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 [tag:batch] or [tag:powershell] and running an OS which use this kind of trick by default. – F. Hauri – 2013-11-28T19:26:46.890

@F.Hauri Ok, now keep the window open please. – Johannes Kuhn – 2013-12-03T10:48:10.303

3@JohannesKuhn Are you crazy! There is no more than 2°C outer! It's too cold!! – F. Hauri – 2013-12-03T21:48:36.833

23

Windows Command Prompt, 26

echo Hello World>.hta&.hta

enter image description here

Danko Durbić

Posted 2013-11-26T15:03:07.763

Reputation: 10 241

This is awesome. Bonus points for spawning two windows? – Gusdor – 2013-11-27T11:44:32.757

@Gusdor What do you mean? I only see one spawned window here. – Iszi – 2013-11-27T15:09:33.400

@Iszi I made the assumption that the batch file was run from desktop, not typed. Whoops! – Gusdor – 2013-11-27T15:25:51.467

@Gusdor I think that's why he called it "Windows Command Prompt" instead of "Batch". Otherwise, it'd lose to Johannes' answer anyway. – Iszi – 2013-11-27T15:31:20.220

@Iszi: They’re nearly equivalent, no? – Ry- – 2013-11-28T21:58:52.547

To do it properly in Batch, you'd need to add an @ to the start so the command isn't echoed. – Iszi – 2013-11-28T23:09:00.183

1@Iszi: This opens a new window, so it doesn’t matter whether the command is echoed in a different one… – Ry- – 2013-11-29T00:39:17.763

15

R, 23

plot(1,m="Hello World")

This opens a plot window.

Sven Hohenstein

Posted 2013-11-26T15:03:07.763

Reputation: 2 464

+1. You can shorten sub= into s= thanks to partial matching however. – plannapus – 2013-11-26T17:50:06.613

@plannapus Thanks, good idea! I modified my code. – Sven Hohenstein – 2013-11-26T18:21:07.640

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 http://codegolf.stackexchange.com/a/19807/2800

– Tomas – 2014-02-02T17:56:58.927

1@Tomas This challenge is different. From the question: "I do not care about the contents of the window frame". – Sven Hohenstein – 2014-02-02T20:35:46.030

Well, but this is not about the frame, but also the text - axis label "index", the numbers etc.. – Tomas – 2014-02-02T21:17:47.747

@Tomas I'm not sure. The OP's reaction to my Matlab answer was: "Yeah plot window is fine :) as long as it is window, I do not care".

– Sven Hohenstein – 2014-02-03T07:45:46.883

@Tomas One could also use frame();text(.5,1,"Hello World!") to a window generate with Hello World! only. This is similar to you PNG-related answer. – Sven Hohenstein – 2014-02-03T07:47:37.920

14

Dyalog APL (20)

⎕SM←'Hello World'1 1

Picture: Picture

marinus

Posted 2013-11-26T15:03:07.763

Reputation: 30 224

1Special characters!?! HAXXX! – AJMansfield – 2013-11-27T00:11:11.493

11

Powershell, 23

'Hello World'>.hta;.hta

enter image description here

Danko Durbić

Posted 2013-11-26T15:03:07.763

Reputation: 10 241

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. – Iszi – 2013-11-27T15:05:56.617

11

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");

David Murdoch

Posted 2013-11-26T15:03:07.763

Reputation: 260

Upvote for the first javascript solution. – SuperJedi224 – 2015-10-18T01:36:56.580

Funny trick. But sadly it depends on the ordering of the posts, which may vary. – manatwork – 2013-11-27T15:21:16.020

1Well, it'll work as long as it is the accepted answer (and the Question doesn't have an "<s>") – David Murdoch – 2013-11-27T15:25:12.980

Lol. I have to upvote for your optimism. – manatwork – 2013-11-27T15:27:28.993

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? – Quillion – 2013-11-27T21:13:20.087

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 – David Murdoch – 2013-11-27T21:36:26.927

As for how it works: StackExchange uses jQuery ($). I use jQuery to get all of the <s> elements on the page (I used "<s>" because it was allowed by Markdown and short). Then I use text() to get the first element's text. Finally I use JavaScript's eval to evaluate/execute that string. – David Murdoch – 2013-11-27T21:40:45.827

9

Matlab, 30 27 20

title('Hello World')

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

Sven Hohenstein

Posted 2013-11-26T15:03:07.763

Reputation: 2 464

Yeah plot window is fine :) as long as it is window, I do not care – Quillion – 2013-11-26T16:05:28.953

figure('name','Hello World') is shorter – magu_ – 2013-11-27T07:31:07.403

@magu_ Good idea. But I suppose it's against the rule "a window that says hello world inside". – Sven Hohenstein – 2013-11-27T08:10:10.273

1@SvenHohenstein Hm, maybe. To say at least something usefull: you don't need the (1) necessarly. Making the code 3 characters smaller. – magu_ – 2013-11-27T08:23:31.113

@magu_ Thanks for the hint! I modified the code accordingly. – Sven Hohenstein – 2013-11-27T08:34:43.400

1You don't actually need figure; – Torbjørn T. – 2013-11-27T23:26:37.063

@TorbjørnT. Great idea! Thank you. This is shorter by 7 characters. – Sven Hohenstein – 2013-11-28T07:19:20.013

9

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.

swilliams

Posted 2013-11-26T15:03:07.763

Reputation: 476

8You can call args whatever you want; a is sufficient. – daniero – 2013-11-26T20:19:20.303

@daniero thanks for the suggestion, pretty silly of me to miss that :) – swilliams – 2013-11-28T07:20:35.857

1s/class/enum/ – Thomas Eding – 2013-11-28T07:38:04.390

like @ThomasEding hints replacing the class by enum shaves off one byte – masterX244 – 2014-03-14T09:48:14.667

@masterX244 That won't be syntactically correct unless a semicolon is added before the public static... to end the list of enum constants... see http://stackoverflow.com/questions/7318011/is-it-possible-to-create-an-empty-java-enum-type-with-methods. In either case you end up with the same number of characters.

– swilliams – 2014-03-16T20:27:27.713

@swilliams the IDE moans about it but javac accepts it (at least in .7 ) – masterX244 – 2014-03-17T12:52:11.623

7

Mathematica 29 27 25

With 1 byte saved thanks to CatsAreFluffy.

DialogInput@"hello world"

hello world

DavidC

Posted 2013-11-26T15:03:07.763

Reputation: 24 524

DialogInput is 1 byte shorter – CalculatorFeline – 2016-02-28T05:57:18.900

Yes, thanks, and the curly braces are also unnecessary. – DavidC – 2016-02-28T13:17:26.077

CreateDialog is shorter. – alephalpha – 2013-11-27T03:10:42.793

Thanks. I thought CreateDialog would insert an OK button. – DavidC – 2013-11-27T03:57:41.823

5

Shell, 32

xmessage -buttons '' Hello World

Hasturkun

Posted 2013-11-26T15:03:07.763

Reputation: 1 206

1There is a 1 character shorter way: xterm -e 'read -p Hello\ World'. – manatwork – 2013-11-26T15:29:56.887

Mine would have been way shorter if I didn't have to -buttons '' :( – Hasturkun – 2013-11-26T15:31:26.080

@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. – Quillion – 2013-11-26T15:42:08.457

@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. :) – manatwork – 2013-11-26T15:52:12.457

5

Ruby with Shoes, 28

Shoes.app{para'Hello World'}

Result:

screenshot

Doorknob

Posted 2013-11-26T15:03:07.763

Reputation: 68 138

5

Python 2/3, 54 characters

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

__import__("tkinter").Label(text="Hello World").pack()

Ramchandra Apte

Posted 2013-11-26T15:03:07.763

Reputation: 189

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. – plannapus – 2013-11-27T08:03:11.537

@plannapus Actually I had copied a previous version with that error, not the correct one. Thanks. – Ramchandra Apte – 2013-11-27T08:04:19.557

4

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.

Johannes Kuhn

Posted 2013-11-26T15:03:07.763

Reputation: 7 122

I am terribly sorry but I can not accept this as a correct answer. Yes it will print hello world to the console window. However the said window will have to actually exhibit window properties such that it does not insta close. Sorry that I haven't made that clarification. I will add it. This can cause python users to just as easily do print "Hello World" – Quillion – 2013-11-26T18:54:08.680

Which would be longer by the way. By the way, now it should again meet the criteria again. – Johannes Kuhn – 2013-11-26T19:27:34.987

2Requirement is: create a window not force window manager to create a window – F. Hauri – 2013-11-26T19:36:17.823

4@F.Hauri Ok, I'll look how to write a window manager. Until someone post that, consider all posts as violation of your requirement. – Johannes Kuhn – 2013-11-26T19:37:34.040

@F.Hauri Perhaps put it differently: The challenge is to "create a window" not "spawn a shell". – Iszi – 2013-11-26T19:52:41.653

1As the op states, it doesn't matter how the window looks. If it is a plot window or a shell window, who cares? – Johannes Kuhn – 2013-11-26T20:04:06.067

5I absolutely agree :) now this is absolutely acceptable because it is a window and it does say hello world :) well done I love it – Quillion – 2013-11-26T20:05:25.583

Just don't force me to draw in that window. – Johannes Kuhn – 2013-11-26T20:08:33.067

@JohannesKuhn Easy. Just save my PowerShell script as a PS1 file, then execute it from your batch file with PowerShell -Command. Make sure your PowerShell ExecutionPolicy is friendly to unsigned scripts. ;-) – Iszi – 2013-11-26T20:13:44.923

Why are people downvoting this? It is a valid answer and he answered it just fine. My requirement was have a window that says hello world. And I did specify that I do not care what type of window as long as it is a window. And the language written in is shell, so what if it creates a shell window, it is still a window. It is batch property to show up that way. – Quillion – 2013-11-26T20:21:11.403

At least this is currently with R the shortest answer :P – Johannes Kuhn – 2013-11-26T20:24:31.550

1@JohannesKuhn PowerShell can still beat it. Edit coming up. – Iszi – 2013-11-26T22:08:04.557

@F.Hauri I challenge you to find an API that doesn't "force" the window manager to open a window. – Gusdor – 2013-11-27T11:35:02.297

@Gusdor Something like PleaseOpenAWindowForMePlease? – Johannes Kuhn – 2013-11-27T12:10:43.223

@JohannesKuhn Bonus points for an API that sounds needy! Should it have a *.io suffix to be a 'proper' API? – Gusdor – 2013-11-27T12:20:54.910

4

Rebol 2, 29

view layout[txt{Hello World}]

enter image description here

Izkata

Posted 2013-11-26T15:03:07.763

Reputation: 151

4

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>

F. Hauri

Posted 2013-11-26T15:03:07.763

Reputation: 2 654

3

Tcl/Tk, 34

pack [label .l -text Hello\ World]

Johannes Kuhn

Posted 2013-11-26T15:03:07.763

Reputation: 7 122

3

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

Iszi

Posted 2013-11-26T15:03:07.763

Reputation: 2 369

Show instead of ShowDialog should do it, right? – It'sNotALie. – 2013-11-26T21:05:06.700

Show() does work, but doesn't let you close the window. Which isn't a requirement! – SpellingD – 2013-11-26T21:22:21.853

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() – SpellingD – 2013-11-26T21:57:53.687

@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.) – Iszi – 2013-11-26T22:17:15.627

3

AutoHotkey, 26

GUI,Add,Text,,Hello World!

Broseph

Posted 2013-11-26T15:03:07.763

Reputation: 131

3

AutoIt v3, 32

ToolTip("Hello World")
Sleep(9^9)

Chris

Posted 2013-11-26T15:03:07.763

Reputation: 131

Wouldn't MsgBox(0,"","Hello World") be shorter? It's 26 characters. – Mr. Llama – 2013-12-03T16:05:07.207

The requirements are to have no Ok or Cancel buttons within the window. The code you suggest has an OK button. :( – Chris – 2013-12-03T18:18:57.080

Ah balls, I missed that requirement. – Mr. Llama – 2013-12-05T17:16:53.517

3

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.

Alvin Wong

Posted 2013-11-26T15:03:07.763

Reputation: 101

3I agree it shouldn't count. The same can be accomplished by loading a simple TXT file in the browser. – Iszi – 2013-11-27T05:12:24.973

Your count is off, that's 20 characters. – jmoreno – 2013-11-27T05:18:51.870

2@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> – Cruncher – 2013-11-27T13:54:58.343

@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). – ComFreek – 2013-11-27T16:30:48.713

1@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. – Braden Best – 2014-02-11T05:09:37.217

@B1KMusic Of course it will. But because your browser fixes the file you provided, doesn't mean the original was html. The very essence that it has to add all of those tags, is evidence that the original file was NOT HTML. – Cruncher – 2014-02-11T13:41:53.250

@Cruncher Ah, and now we get into the subject of syntax vs semantics. The file may not be HTML in a standard-compliant sense, but the end result is HTML. And since this is code golf, the whole point being to find the shortest way to do something in a given language, this answer shouldn't be disqualified for that--it should be disqualified because the window created contains content other than "Hello World". I guess what I'm getting at is: If we're going to enforce standards for HTML, why stop there? Why not enforce that C programmers use int main(void){int i = 1;} instead of main(i){}? – Braden Best – 2014-02-11T17:04:37.923

In other words, isn't the file extension .html enough? – Braden Best – 2014-02-11T17:08:25.537

@B1KMusic If I put Hello World into a .txt file and openend it in notepad, would we call that a txt submission? That is actually a better fit than this answer. The browser is the program. The browser is doing all the work. Also, all browsers interpret things differently. Could I write a browser than interprets the blank html file as the solution that I want? Then I can submit a 0 char solution for any problem. – Cruncher – 2014-02-11T17:46:29.127

@B1KMusic In terms of C. I would argue that it has to work on a standards-compliant compiler. Anything that relies on undefined behaviour should be disqualified. So HTML should have to fit standards as well. You can't depend on undefined behaviour of a browser to do what you want. – Cruncher – 2014-02-11T17:48:49.777

@Cruncher (1) If you put HTML into a .txt file, it doesn't render in a browser. Simple as that. What matters is the end result. If you type <div>Hello</div> and the browser prints <div>Hello</div>, then it's not HTML. If the browser prints Hello, then it's HTML. Saying that HTML isn't "true code" because "the browser does all the work" is like saying "the OP-code table does all the work" when writing ASM. Why don't we all just pull out our punchcard mainframes and write machine code with switches, then? – Braden Best – 2014-02-11T18:06:55.930

@Cruncher (2) This is code-golf, not popularity-contest. Shortness of code matters more than code quality. That's the entire point of the challenge: pushing the boundaries of the language. Why do you think people use, for example, Esoteric languages for these challenges in the first place? Do you think they actually use those language for real world projects? – Braden Best – 2014-02-11T18:09:31.720

let us continue this discussion in chat

– Cruncher – 2014-02-11T18:16:14.220

3

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.

Jon Purdy

Posted 2013-11-26T15:03:07.763

Reputation: 471

3

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?

The Guy with The Hat

Posted 2013-11-26T15:03:07.763

Reputation: 778

2

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.

FGreg

Posted 2013-11-26T15:03:07.763

Reputation: 121

2

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.

Timtech

Posted 2013-11-26T15:03:07.763

Reputation: 12 038

Your TI-BASIC answer does not open a window, and it outputs capital rather than lowercase letters. – lirtosiast – 2015-06-07T15:07:05.150

If you would accept an OK button, show_message("Hello World") is 27 characters. – Timtech – 2013-11-27T11:40:25.880

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 ;) – ɐɔıʇǝɥʇuʎs – 2014-03-30T14:30:28.523

@Synthetica Yeah. Forgot that :) – Timtech – 2014-03-30T15:24:26.950

2

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

AJMansfield

Posted 2013-11-26T15:03:07.763

Reputation: 2 758

2

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 :)

Noctis

Posted 2013-11-26T15:03:07.763

Reputation: 121

What is Console.Out? This ain't Java. – NoOneIsHere – 2016-09-27T03:49:08.257

@NoOneIsHere it's a dark incantation taken from here . beware the demons you might summon when using it

– Noctis – 2016-09-27T05:09:48.003

Isn't it just extra bytes? – NoOneIsHere – 2016-09-27T20:04:31.167

Console.Write('text'). – NoOneIsHere – 2016-09-29T17:14:21.510

It's Console.Out.Write vs. Console.Write. Just remove Out.. – NoOneIsHere – 2016-09-30T02:20:04.053

@NoOneIsHere . Screw head on. Riiight... cause -> type 'out', CTRL+enter, autocompletes Console.Out.Write("stuff here"); . you're right my friend – Noctis – 2016-09-30T02:28:01.767

I don't know C# much. Can you write using System.Console;? I think that would save you 6 chars – Cruncher – 2013-11-27T13:58:19.707

Nope ... tried that :) (I'm not THAT simpleminded :) – Noctis – 2013-11-27T22:22:46.763

Does the class really need to be called Program? – Rees – 2014-03-30T15:33:49.027

2

Bash (36 chars)

xmessage -buttons "" "Hello World!"

Looks like crap, but works as requested.

enter image description here

klingt.net

Posted 2013-11-26T15:03:07.763

Reputation: 876

The rule “inside it must say hello world only” was explicitly added to avoid so simple solutions. – manatwork – 2013-11-27T13:27:25.870

ok, fixed this. – klingt.net – 2013-11-27T13:32:44.027

Now it's correct, but there is another problem: it became duplicate of Hasturkun's answer.

– manatwork – 2013-11-27T13:56:05.677

1Damn, at least i've a screenshot :) – klingt.net – 2013-11-27T14:09:05.160

2

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

luser droog

Posted 2013-11-26T15:03:07.763

Reputation: 4 535

2

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.

Johnbot

Posted 2013-11-26T15:03:07.763

Reputation: 141

2

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.

R-D

Posted 2013-11-26T15:03:07.763

Reputation: 231

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. – manatwork – 2013-11-29T15:43:51.367

1You need to count newlines as part of your character count. That's why many answers on this site are all on one line. – Gareth – 2013-12-02T14:44:25.833

Ah, I didn't know that. I'll edit my answer. – R-D – 2013-12-02T14:48:39.820

2

Shell script: 56 character

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

Sample output:

Hello World

manatwork

Posted 2013-11-26T15:03:07.763

Reputation: 17 865

2

Quomplex, 11

Hello World

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

Timtech

Posted 2013-11-26T15:03:07.763

Reputation: 12 038

-1; link is ded – cat – 2016-02-29T04:14:14.090

@tac Try the web archive http://web.archive.org/web/20140625132327/http://timtechsoftware.com/?page_id=1264 I've updated the post with this link as well.

– Timtech – 2016-02-29T13:22:13.563

2

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

TessellatingHeckler

Posted 2013-11-26T15:03:07.763

Reputation: 2 412

2

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

manatwork

Posted 2013-11-26T15:03:07.763

Reputation: 17 865

1

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.

smcg

Posted 2013-11-26T15:03:07.763

Reputation: 223

Why don't you resize the window after it is produced, and then add the picture of it to your posting? – DavidC – 2013-11-26T22:59:26.887

1import java.awt.*; and f=new Frame() and new Label I think can trim this quite a bit – Cruncher – 2013-11-28T18:03:17.373

1

APLX, 44

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

You could probably get it down from there.

MirroredFate

Posted 2013-11-26T15:03:07.763

Reputation: 111

1

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);}}

Cruncher

Posted 2013-11-26T15:03:07.763

Reputation: 2 135

You could save a character by changing the 50 to 9, although that would make it non-centered. – AJMansfield – 2013-11-27T00:50:11.677

@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. – Cruncher – 2013-11-27T13:52:13.847

1

JavaScript, 32

open('javascript:"Hello World"')

zzzzBov

Posted 2013-11-26T15:03:07.763

Reputation: 2 915

1

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.

ILikeTurtles

Posted 2013-11-26T15:03:07.763

Reputation: 11

1

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

James C.

Posted 2013-11-26T15:03:07.763

Reputation: 11

you can write using s=System.Console; to save 2 bytes (I think, I'm not a C# programmer lol) – Sagittarius – 2019-09-11T16:53:51.357

1

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;
}

luser droog

Posted 2013-11-26T15:03:07.763

Reputation: 4 535

0

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

Fozzedout

Posted 2013-11-26T15:03:07.763

Reputation: 121

0

Windows command shell, 24 characters

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

start echo "Hello World"

bacchusbeale

Posted 2013-11-26T15:03:07.763

Reputation: 1 235

0

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

manatwork

Posted 2013-11-26T15:03:07.763

Reputation: 17 865

-1

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

Danko Durbić

Posted 2013-11-26T15:03:07.763

Reputation: 10 241

I'd say this is about as valid as the "HTML" answer with the same code.

– Iszi – 2013-11-27T17:14:32.893

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>. – Danko Durbić – 2013-11-28T13:27:17.230

-2

Javascript:

alert("hello world inside and nothing else")

With a slight bend of the rules ;)

ɐɔıʇǝɥʇuʎs

Posted 2013-11-26T15:03:07.763

Reputation: 4 449

-3

JavaScript - 20

alert("Hello World")

xem

Posted 2013-11-26T15:03:07.763

Reputation: 5 523

This also has "OK" i it... – dav_i – 2013-11-27T11:03:08.350

4Yeah this one doesn't meet the requirements, sorry. – Timtech – 2013-11-27T11:39:26.757