I am writing a simple program:
class Demo{
public static void main(String[] args){
system.out.println("Hello");
}
}
on compilation it gives an error: package system not found.
Why it do so that package not found instead system is a misspelled class name.
When you say
something.somethingElsethe compiler assumes you are doing apackageName.classname. In this case you were intending to accessoutof theSystemclass, but you could very well be trying to access a package calledsystemthat is not present (in the classpath for instance). So it is a guess from a compiler.And (I guess) it is so because this is the better guess. Let’s say the compiler said class not found. You might be happy. But tons of others doing
Java.util.List(instead ofjava.util.List) would complain “I was trying to access thejava.utilpackage but misspelled it. The compiler wrongly says Missing class name.Update (for the sake of completeness)
From @paxdiablo’s answer below: