Link Details

Link 98216 thumbnail
User 200525 avatar

By accavdar
via cavdar.net
Published: Jul 26 2008 / 04:28

Can you print out “Hello World!” without writing a main method in Java? Think for a while. Yes, you’re right. It can be possible using “static initialization blocks”...
  • 39
  • 9
  • 3521
  • 1262

Comments

Add your comment
User 190346 avatar

ilazarte replied ago:

1 votes Vote down Vote up Reply

Hah. good interview question.

User 241219 avatar

jerryji replied ago:

0 votes Vote down Vote up Reply

I do hope you are just kidding

User 232567 avatar

jdave replied ago:

-2 votes Vote down Vote up Reply

Personally I hate it! :) It is a horrible hack with little or no real word application. I'm not sure that knowing this makes you a better programmer...

User 231703 avatar

MattRussell replied ago:

2 votes Vote down Vote up Reply

I'm fairly sure that just knowing this specific thing doesn't make you a better programmer...but sometimes people push tecnhnology in weird and wonderful ways just for the fun of it, and that's OK, although it's not everyone's cup of tea. Further, often this sort of tinkering leads to cool real-world innovations. Clearly, writing "Hello World" in a crazy way has no practical utility, but people with this sort of attitude to programming might, for example, discover a new technique for writing an internal domain-specific language by bending the language in a different way.

User 232567 avatar

jdave replied ago:

-1 votes Vote down Vote up Reply

I had to blog http://dzone.com/links/not_saying_hello_world_without_main_method.html
While agree that knowing the ins and outs of a language is good, I have learned to be wary in general of 'hacks' and particularly of using them in real code. In this case I see little value beyond an interest in passing.

User 319680 avatar

hhasdal replied ago:

1 votes Vote down Vote up Reply

Static initialization blocks are underrated but important java language feature.
Sometimes static blocks saves lots of code duplication. It may not be accurate for newbee java users
to use the blocks, but for more advenced developers it is a great feature to use when needed.

User 313949 avatar

rentzias replied ago:

0 votes Vote down Vote up Reply

thnx for the static initialization point and hello world implementation trick.. nice post..
,

User 211643 avatar

zynasis replied ago:

0 votes Vote down Vote up Reply

so what, big deal

User 222498 avatar

M Easter replied ago:

0 votes Vote down Vote up Reply

how did this get 30+ up votes? odd.

User 276353 avatar

Umberto replied ago:

0 votes Vote down Vote up Reply

..old news

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.