Tag Archives: computer

my desktop having some spray linesdesktop

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 “HelloWorld.java”.

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