File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Please Help !!! (package and accessibility) 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 "Please Help !!! (package and accessibility)" Watch "Please Help !!! (package and accessibility)" New topic

Please Help !!! (package and accessibility)

Siu Yong

Joined: May 31, 2006
Posts: 2
Hi All,

I am new to java. I want to set up different packages such as com.mypackage and com.hispackage so that I can test the access modifiers such as private, protected and default. I have tried a program as follow :

package com.myPackage;

public class MyClass{
public static void main(String [] args){
System.out.println("Hello World");

I can compile the program but when I run the program I get the following :

C:\MyProgram>java MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass (wrong name:
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(

I think the problem is because the JVM cannot see the class file

Can someone help me to set up the different packages in my win XP environment so that I can test the programs I write in any different folder. My question is how to set up a real developement environment with many different packages.
Firas Zuriekat
Ranch Hand

Joined: May 09, 2006
Posts: 144
create a directory called "com" like this:
c:\myJava>mkdir com

Also, create a subdirectory called "myPackage" like this c:\myJava\com>myPackage

Save the the file in your post ( in myPackage folder.
Then go to the myPackage folder and enter this:


You will get compile successful message.

Then to run the class file do the following:
C:\myJava>java com.myPackage.MyClass
I agree. Here's the link:
subject: Please Help !!! (package and accessibility)
It's not a secret anymore!