Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package declaration

 
marisha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
i am a beginner in this Java Forum.I have one problem.
my classpath is set to \jdk1.3\projects
and my all .java files lies there. Now when i include "package projects" in my java file.it compiles but give run time error as
"Exception in thread main.. Wrong name projects
But when i remove "package projects" from the java file it works fine.
thanx
 
Kishan Kumar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marisha,
since you have set your classpath till the projects directory
this wont work. try setting the classpath = c:\jdk1.3
this should work. packages take the classpath as the base and
tries to find the package from there. In your case it is trying
to find c:\jdk1.3\projects\projects which is not existing.
If there was a directory like that it would have worked.
set classpath = c:\jdk1.3
package projects.kishan.kumar;
will search for the directory
c:\jdk1.3\projects\kishan\kumar to put the class files.
Please remember declaring packages inside the file will not
create directories in the file system. you should first explicitly create files and the compile the program containing the package statement or else it will result in the compile time
error.
Hope this helps and hope i have not confused you.


------------------
Regards,
V. Kishan Kumar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic