My first java programm “Hello World”

Today I started again to open my netbeans IDE to say “hello” to the world (which is the common 1st programm of a programmer).

Netbeans generates some more comments, packages and so on within a project.

But this is the core java code:

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

There is one public class so in general this class needs the main method in Java
and you also should save the file containing this code using the name of this class.

So you save the file as “”.

In my netbeans the code works fine.

I tried to do the same on my windows command line and got an error. Why? Because 1st of all I have to set the
environment variable to javac.exe so I can compile my .java file into a runable .class file.[*]

Me I set it in
Start – Computer – properties – extended properties – confirm “Yes” admin privs – tab extended (or more) – environment variables – system variables
and here I add at the already existing ‘Path’ variable my java bin path:

C:\Program Files\Java\jdk1.7.0_13\bin\

in the beginning followed by a semicolon or in the end of all the already existing path entries starting with a semicolon or somewhere inbetween enclosed in two semicolons.

‘OK’ – I restart the command line and I can compile my .java file into a .class file.

Why it’s still not running? I saw two mistakes:

  • name your java file like the public class which contains the main method as I mentioned before
  • run your .java file with the java command followed by the .class file name but without the extension .class –
    that was actually the problem first why I got an error and with all this packages confusion from netbeans it’s still not working.
    so I used notepad++ and pasted the core java code into a new file and saved it as described above – and now:

    simply type

    > java HelloWorld

    – finish – and you will get your ‘Hello World’.

[*]Of course you need your java installed on your windows computer


2 thoughts on “My first java programm “Hello World”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s