For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2006 > Newbie question regarding packages









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie question regarding packages
snoopy_@excite.com

2006-03-29, 10:02 pm

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

2006-03-30, 8:02 am

Where is PackageTest running from? Where are you running the java
command from (which directory)?

Robert Baer

2006-03-31, 8:03 am

Jubz wrote:

> 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

2006-03-31, 7:03 pm


"Robert Baer" <robertbaer@earthlink.net> wrote in message
news:XV7Xf.6754$HW2.5671@newsread3.news.pas.earthlink.net...
> Jubz wrote:
>
> ?? 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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com