Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes core java creating package exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "core java creating package exception" Watch "core java creating package exception" New topic
Author

core java creating package exception

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

package P;
class Example
{
public static void main(String args[])
{
System.out.println("creating package p");
}
}

i compiled this with

javac -d . Example.java

and made it run with

java Example


but it gave me an exception classNot found

why is it doing so??


http://www.lifesbizzare.blogspot.com || OCJP:81%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41054
    
  43
Because a) the class is not named "Example", it is named "P.Example", and b) the class file is in the wrong location - it should be in a subdirectory called "P". You may want to read up on packages: http://java.sun.com/docs/books/tutorial/java/package/index.html


Ping & DNS - my free Android networking tools app
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37907
    
  22
Try java P.Example

Have a look at the Java™ Tutorials and search this forum for "compiling package" where you should find at least three ways to compile classes with package names.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37907
    
  22
Ulf, it is only Rob who is allowed to beat my by two minutes like that
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41054
    
  43
I promise to do worse in the future :-)
 
 
subject: core java creating package exception
 
Similar Threads
Java 1.4 Enhancements
Problem in Exception Handling??
How to create a package?
doConnect?
How to access a local class in jsp