Results 1 to 3 of 3
  1. #1
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    157
    Rep Power
    5

    Default 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");
    }

    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    The IDE creates the required folders for those packages. You need to do the same thing.

  3. #3
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    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

  1. Replies: 7
    Last Post: 11-09-2009, 07:51 AM
  2. jxl package
    By little_polarbear in forum New To Java
    Replies: 5
    Last Post: 05-05-2009, 02:19 PM
  3. Regarding package
    By makpandian in forum New To Java
    Replies: 2
    Last Post: 03-24-2009, 05:47 PM
  4. Package Compiling
    By kaperks in forum Advanced Java
    Replies: 1
    Last Post: 02-23-2009, 02:56 PM
  5. JXL Package
    By gaya3 in forum Java Servlet
    Replies: 1
    Last Post: 05-23-2008, 09:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •