This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
And what if you have a class named MyClass.java in the default package, located in .../myProject/classes ? If you run java MyClass, should it run MyClass in the current directory, or the one located in the default package?
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Java start looking for user defined classes from environment variable "CLASSPATH" until you specifiy -cp or -classpath option while running java , which overrides
default classpath and is a preferred way for setting classpath for individual application.
default value for CLASSPATH in java is current directory "."
so if your classpath is set to current directory "." and you give command "java com.wickedlysmart.MyClass" , it will look for MyClass in directory ./com/wickedlysmart/ and if it finds the class it will execute .
but if you give name only "MyClass" than it would be incorrect name for that class , so it won't run.
but it all depends upon what is value or CLASSPATH in your environment .