A216448a699b8cb7e3f70fba31d76974

This is just a little program I made

public class HelloWorld
{
    public static void main( String[] args )
    {
        System.out.println( "Hello world" );
    }
}

Refactorings

No refactoring yet !

0706636fd5e30fa66019d7ffacdb5b11

Marco Valtas

October 6, 2007, October 06, 2007 15:40, permalink

3 ratings. Login to rate!

Ok, your HelloWorld is not problematic and not need a refactoring, but just for fun you can avoid call the main method.

public class HelloWorld {
    static {
        System.out.println("Hello World");
        System.exit(0);
    }
}
D41d8cd98f00b204e9800998ecf8427e

tubarao

October 7, 2007, October 07, 2007 15:22, permalink

1 rating. Login to rate!

At the risk of being a pedant, I'd propose the following because:

* it follows the code-style conventions recommended by Sun (braces, whitespace etc)
* a static block with System.exit(0) is less conventional than a main(String[]) method and maintenance programmers aren't interested in how much fun the original writer had
* fair enough, the classloader would trigger the static block, but would you get some sort of NoMainMethodException after that?

These are serious issues, these are serious times :D

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}
7ed545949ea2a1a01abbed2238ff7fbc

Memer

October 9, 2007, October 09, 2007 01:15, permalink

1 rating. Login to rate!

Noes, ur doin' it all wrong!11!

//INTARNET MEMES FTW
public class HaiWerld

    public static void main( String[] args ) {
        System.out.println( "HAI WERLD!!11!!" );
    }
}
D41d8cd98f00b204e9800998ecf8427e

Blah

October 9, 2007, October 09, 2007 17:17, permalink

1 rating. Login to rate!

Why does everyone like to use braces like that? It's much easier to read things when they line up.

private void test blah()
{
  // code here 
}

//seems better than

private void test blah() {
  //code here
}
D41d8cd98f00b204e9800998ecf8427e

HoGe

October 12, 2007, October 12, 2007 15:24, permalink

No rating. Login to rate!

I love variable length arguments and 'final' keyword.

public class HelloWorld
{
    public static void main(final String... args)
    {
       System.out.println("Hello World");
    }
}
7bfd646dea8e47642bbb573f026bf159

engtech

October 17, 2007, October 17, 2007 01:56, permalink

No rating. Login to rate!

@blah: http://refactormycode.com/codes/66-hello-world#refactor_354

I use the later because I find when the top brace is on the same line then I know what that loop/conditional is all about.

D6d78b560c1733fcb5d36734d4114b18

Jose

November 8, 2007, November 08, 2007 20:34, permalink

No rating. Login to rate!
public class HolaMundo {
    public static void main(String [] arg){
        String saludo = "Hola Mundo";
        system.out.println(saludo);
    }
}
D41d8cd98f00b204e9800998ecf8427e

Tim

December 16, 2007, December 16, 2007 14:38, permalink

No rating. Login to rate!
class HelloWorld
{
   public static void main(String args[])
   {
       system.out.println("Hello world");
   }
}

Your refactoring





Format Copy from initial code

or Cancel