Results 1 to 3 of 3
Thread: comile with package
- 01-04-2010, 06:04 AM #1
comile with package
hi,
how this program will compile and run WITH OUT ANY IDE
put this code in a notepad name it First.java then the step of compilatin
start>>>run>>>cmd
cd e:
E:/>javac First.java
E:/>java First
the output will be
Exception in thread "main" java.lang.NoClassDefFoundError: First (wrong name: fi
rst/First)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: First. Program will exit.
then how the packge is forming by the ide or even the jcreator on the compilation
thanks for advices
package first;
class First{
public static void main(String ar[]){
System.out.println("Hello world");
}
}
- 01-04-2010, 06:23 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
The IDE creates the required folders for those packages. You need to do the same thing.
- 01-04-2010, 06:29 AM #3
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
The IDE creates it..because it creates a subdirectory named first and stores the java file in that subdirectory .
---------------------------If you want to read abt Packages.------------------------------------------------
If package name is specified, the file must be in a subdirectory called name (i.e., the directory name must match the package name).
here for an example.
Assume that you are working in a directory called Javadir, and that you create four files, whose contents are shown below.
file 1
package ListPkg;
public class List { ... }
class ListNode {...}
file 2
package ListPkg;
public class NoNextItemException { ... }
file 3
public class Test { ... }
class Utils { ... }
file 4
class Test2 { ... }
Here are the directories and file names you must use:
File 1 must be in a subdirectory named ListPkg, in a file named List.java.
File 2 must also be in the ListPkg subdirectory, in a file named NoNextItemException.java.
File 3 must be in a file named Test.java (in the Javadir directory).
File 4 can be in any .java file (in the Javadir directory).
---------------------------If you want to read abt Packages.------------------------------------------------
this would work perfect for your respective command line prompts provided java file is in the correct path .
Java Code:class First{ public static void main(String args[]){ System.out.println("Hello world"); } }Last edited by [RaIdEn]; 01-04-2010 at 06:32 AM.
Similar Threads
-
The declared package does not match the expected package
By oneforall in forum EclipseReplies: 7Last Post: 11-09-2009, 07:51 AM -
jxl package
By little_polarbear in forum New To JavaReplies: 5Last Post: 05-05-2009, 02:19 PM -
Regarding package
By makpandian in forum New To JavaReplies: 2Last Post: 03-24-2009, 05:47 PM -
Package Compiling
By kaperks in forum Advanced JavaReplies: 1Last Post: 02-23-2009, 02:56 PM -
JXL Package
By gaya3 in forum Java ServletReplies: 1Last Post: 05-23-2008, 09:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks