package pack;
public class sample{
public static void main(String input[])
{
NumberFormat numberFormat = new DecimalFormat("#,##0.00##");
System.out.println(numberFormat.format(44533125.00));
}
}
the code is working fine in the current dir.. (c:/myprogram/).
after that i copy the sample.class file and paste it in other dir(d:/myprogram).
i got error while running, like
Exception in thread "main" java.lang.NoClassDefFoundError: sample (wrong name: pack/sample)
In java .class file can run anywhere right? but why i am not able to run?
You should have the class file within the package – so it should be in a directory called
pack. Then with the parent directory in the classpath, you’d run(You should also change the class name to Sample to follow conventions, btw – and run
pack.Sample.)If you’re building with javac, specify the “-d” option to tell it the base directory, and it will create the appropriate package structure if necessary. For example:
or
will (in both cases) create
You could then run