I presume this problem has to do with the CLASSPATH, but I it is set (".;C:\jdk1.4;C:\jdk1.4\demo") in System as well as -classpath as below, still it works only when its package is explicitely called:
C:\jdk1.4\demo>java demo.SprinklerSystem
valve1 = null
C:\jdk1.4>java demo.SprinklerSystem
valve1 = null
Otherwise the exception occurs:
C:\jdk1.4>java demo
Exception in thread main
java.lang.NoClassDefFoundError: demo
C:\jdk1.4\demo>java SprinklerSystem
Exception in thread main
java.lang.NoClassDefFoundError: demo.SprinklerSystem
java.lang.Class java.lang.ClassLoader.defineClass0(java.lang.String, byte[], int, int, java.security.ProtectionDomain)..
C:\jdk1.4>java -classpath C:\jdk1.4\demo;. SprinklerSystem
Exception in thread main
java.lang.NoClassDefFoundError: demo.SprinklerSystem
Even this one failes:
C:\jdk1.4\demo>java -classpath C:\jdk1.4\demo;. demo.SprinklerSystem
Exception in thread main
java.lang.NoClassDefFoundError: demo/SprinklerSystem
C:\jdk1.4\demo>java demo.SprinklerSystem
valve1 = null
C:\jdk1.4>java demo.SprinklerSystem
valve1 = null
Otherwise the exception occurs:
C:\jdk1.4>java demo
Exception in thread main
java.lang.NoClassDefFoundError: demo
C:\jdk1.4\demo>java SprinklerSystem
Exception in thread main
java.lang.NoClassDefFoundError: demo.SprinklerSystem
java.lang.Class java.lang.ClassLoader.defineClass0(java.lang.String, byte[], int, int, java.security.ProtectionDomain)..
C:\jdk1.4>java -classpath C:\jdk1.4\demo;. SprinklerSystem
Exception in thread main
java.lang.NoClassDefFoundError: demo.SprinklerSystem
Even this one failes:
C:\jdk1.4\demo>java -classpath C:\jdk1.4\demo;. demo.SprinklerSystem
Exception in thread main
java.lang.NoClassDefFoundError: demo/SprinklerSystem