public class HelloWorld
{
public static void main( String[] args )
{
System.out.println( "Hello world" );
}
}
Refactorings
No refactoring yet !
Marco Valtas
October 6, 2007, October 06, 2007 15:40, permalink
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);
}
}
tubarao
October 7, 2007, October 07, 2007 15:22, permalink
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");
}
}
Memer
October 9, 2007, October 09, 2007 01:15, permalink
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!!" );
}
}
Blah
October 9, 2007, October 09, 2007 17:17, permalink
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
}
HoGe
October 12, 2007, October 12, 2007 15:24, permalink
I love variable length arguments and 'final' keyword.
public class HelloWorld
{
public static void main(final String... args)
{
System.out.println("Hello World");
}
}
engtech
October 17, 2007, October 17, 2007 01:56, permalink
@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.
Jose
November 8, 2007, November 08, 2007 20:34, permalink
public class HolaMundo {
public static void main(String [] arg){
String saludo = "Hola Mundo";
system.out.println(saludo);
}
}
Tim
December 16, 2007, December 16, 2007 14:38, permalink
class HelloWorld
{
public static void main(String args[])
{
system.out.println("Hello world");
}
}
This is just a little program I made