I started to learn Java with lynda.com.
The one of the first lessons tells how to write simple Hello World program. This lesson introduses us with two console commands same in Windows, Linux and Mac:
javac <path_to_source>
java <name_of_class>
I do all similar to code implemented in lesson. Here is it:
package com.lynda.jt;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Next you have to use these two commands to compile and run this program:
$ cd ~/HelloWorld
$ javac com/lynda/jt/HelloWorld.java
$ java com.lynda.jt.HelloWorld
But after running javac
command it ends with error (I didn't save console output). Next I try to compile again but in other directory:
$ cd ~/HelloWorld/com/lynda/jt/
$ javac HelloWorld.java
$ cd ~/HelloWorld
$ java com.lynda.jt.HelloWorld
Error: Could not find or load main class com.lynda.lt.HelloWorld
Now its compiled and HelloWorld.class file appeared, but program still not running.
Next I delete .class file and do again:
$ cd ~/HelloWorld
$ javac com/lynda/jt/HelloWorld.java
$ java com.lynda.jt.HelloWorld
Hello World!
Now it's work but why? Previously I tried many other package diclarations:
com.lynda
com.lynda.javatraining
com.lynda.javatraining.hello_world
com.noq.jt
and others. But 99% of usesed paths lead to error messages. As to me it's just RANDOM.
Please clarify me this.