GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes .class files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ".class files" Watch ".class files" New topic
Author

.class files

Prahlad Joshi
Ranch Hand

Joined: Apr 21, 2007
Posts: 44
abstract class a
{
abstract int print(String s);
public void methodA()
{
System.out.println("in method A of abstract class");
}


}
class A extends a
{
public int print(String s)
{
System.out.println("printing"+s);
return 1;
}
public void methodA()
{
super.methodA();
}
}
abstract class b
{
abstract void methodB();
public void caller()
{
a object=new A();
object.methodA();
}

}


class B extends b
{
public void methodB()
{
System.out.println("oveerinding or implementing abstract class'm ethodB");
}
public void caller()
{
super.caller();
}
}
public static void main(String args[])
{
B object =new B();
object.caller();
}
I couldn't understand why the above code is generating the following error
Exception in thread "main" java.lang.NoClassDefFoundError: b (wrong name: B)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at NewClass.main(NewClass.java:52)
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Are you running this on a Windows machine? Windows file systems are case-insensitive by default, so "B.class" and "b.class" are the same file--but your program requires that those two files be distinct since they contain different classes.

One way to overcome this problem is to generate the two class files one by one and put them into a .jar file, which will preserve the case distinction. Another solution is to put the two classes in different packages. But ultimately, this example illustrates why you should generally follow the naming convention of using UpperCase for type names, and avoid having type identifiers that differ only in case.
[ November 01, 2007: Message edited by: Kelvin Lim ]

SCJP 5.0
Prahlad Joshi
Ranch Hand

Joined: Apr 21, 2007
Posts: 44
thanks for your quick and complete explanation Kelvin(ya i am using windows).It cleared all my doubts.
 
GeeCON Prague 2014
 
subject: .class files