Friday, 6 March 2015

How to learn to code Java without using a 'main' method

In the book Java For Testers, I teach Java slightly differently to make it easier to learn. Let me explain how.

When you learn Java, one of the first things you traditionally learn is how to create a 'main' method.

That makes sense right?

After all:

  • You're learning how to write applications. 
  • Applications need to be compiled. 
  • A compiled Java application needs a main method to run.

Of course, you also need to know:

And you might need to know:

jar cmf helloworld.jar HelloWorld.class

java -jar helloworld.jar

And if you are beginning your learning in how to program Java, then you don't even understand the code you've written to write "Hello World" to the console

System.out.println("Hello World");

I wonder why people prefer to learn scripting languages like Python and Ruby?

But, you don't have to learn all this when you start, especially not when you want to learn to write automation code rather than application code.

You could:

  • Write all your code in an IDE
  • Write JUnit @Test methods
  • Run the JUnit @Test methods from the IDE 
    • (right click on the method name and choose "Run")

That way, you can start to learn the Java programming language. And use it to "do stuff" without all the baggage.

That's why in the book Java For Testers, you learn to write all your code as JUnit @Test methods.

And of course, our evil, manipulative subtext... you'll also start your career in Java programming by learning "Test First". So you're learning TDD and you might not even realise it.

Sneaky, but, what did you expect from the people behind

Java For Testers is a tutorial guide. Learn Java by writing JUnit @Test code.

Java For Testers ebook available from:

1 comment:

  1. Yes, JUnit is similar to having main method but much cleaner