Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

Newbie question regarding packages

Thread view: 
snoopy_@excite.com - 30 Mar 2006 02:09 GMT
I am going through a java for dummies book and have an issue compiling
a class.  If I use "import com.mysite.util.Console" it compiles fine,
however if I use import com.mysite.util.* it fails.  I assume this has
something to do with my CLASSPATH so I will include that as well...
Any insite would be appreciated. Thanks.

C:\javaclasses;.

Compiled Console.class file is in C:\javaclasses\com\mysite\util\

-----------------------------------------------------------------------------------------------
public class PackageTest
{
    public static void main(String[] args)
    {
        while (Console.askYorN("Keep going?"))
        {
            System.out.println("D'oh!");
        }
    }
}

-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------

package com.mysite.util;

import java.util.Scanner;

public class Console
{

    static Scanner sc = new Scanner(System.in);

   public static boolean askYorN(String prompt)
   {
       while (true)
       {
           String answer;
           System.out.print("\n" + prompt + " (Y or N) ");
           answer = sc.next();
           if (answer.equalsIgnoreCase("Y"))
               return true;
           else if (answer.equalsIgnoreCase("N"))
               return false;
       }
   }

}
-----------------------------------------------------------------------------------------------

Snoopy_
Jubz - 30 Mar 2006 11:43 GMT
Where is PackageTest running from? Where are you running the java
command from (which directory)?
Robert Baer - 31 Mar 2006 11:56 GMT
> Where is PackageTest running from? Where are you running the java
> command from (which directory)?

  ?? What ??
  What is "Package Test" and "java command"??
Oliver Wong - 31 Mar 2006 23:34 GMT
>> Where is PackageTest running from? Where are you running the java
>> command from (which directory)?
>>
>   ?? What ??
>   What is "Package Test" and "java command"??

He's responding to the OP's question, which I'm requoting here for the
benefit of other readers who may have missed that post.

<quote>
I am going through a java for dummies book and have an issue compiling
a class.  If I use "import com.mysite.util.Console" it compiles fine,
however if I use import com.mysite.util.* it fails.  I assume this has
something to do with my CLASSPATH so I will include that as well...
Any insite would be appreciated. Thanks.

C:\javaclasses;.

Compiled Console.class file is in C:\javaclasses\com\mysite\util\

-----------------------------------------------------------------------------------------------
public class PackageTest
{
public static void main(String[] args)
{
while (Console.askYorN("Keep going?"))
{
System.out.println("D'oh!");
}
}
}

-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------

package com.mysite.util;

import java.util.Scanner;

public class Console
{

static Scanner sc = new Scanner(System.in);

   public static boolean askYorN(String prompt)
   {
       while (true)
       {
           String answer;
           System.out.print("\n" + prompt + " (Y or N) ");
           answer = sc.next();
           if (answer.equalsIgnoreCase("Y"))
               return true;
           else if (answer.equalsIgnoreCase("N"))
               return false;
       }
   }

}
-----------------------------------------------------------------------------------------------
</quote>

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.