• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble setting CLASSPATH variable in windows 2000 prof.

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can anyone help me in setting classpath variable in windows 2000 prof.?

I'm trying to set classpath thru system properties>environment variables>system variables.

I've already set CLASSPATH variable appropriately. When I type in command classpath at cmd, it displays

" ' classpath ' is not recognized as an internal or external command, operable program or batch file."

When I run cmd and try to compile java file, it says package does not exist.

I tried rebooting the system several times after setting classpath variable and it does shows Classpath variable in the environment variables list after reboot but does not help.

What is that I am missing? What else can be done to get things rolling?

Kindly advise,


Raghav.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Well, "classpath" isn't a command, so the fact that nothing happens when you type "classpath" is just fine. CLASSPATH is just an environment variable, and it sounds like you know how to set it just fine.

You say "When I run cmd and try to compile java file, it says package does not exist." What command do you run, exactly? What is the error message, exactly? We can't tell you what you're doing wrong if you don't tell us what you're doing.
 
Raghav Aggarwala
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thank you very much for replying.

1. I am try to execute this command

// Command

c:\temp\java> javac Retirement.java

//Result

Retirement.java:1: package corejava does not exist
import corejava.*;
^
Retirement.java:16: cannot access Console
bad class file: C:\temp\java\book\corejava\Console.class
class file contains wrong class: corejava.Console
Please remove or make sure it appears in the correct subdirectory of the classpath
goal = Console.readDouble("How much money do you need to retire?");
^

2 errors

// End of command and result


2. The file Console.class is located in c:\temp\java\book\corejava

3. Console is a public class. Method readDouble is in Console.java

4. CLASSPATH variable set as .;c:\temp\java\book

5. PATH variable set to
%path%;c:\j2sdk1.4.0_03\lib;C:\j2sdk1.4.0_03\bin;c:\temp\java

How do I find where corejava package is located? I am presuming it's in corejava directory in my case which is c:\temp\java\book\corejava. I copied this from Core Java CD that comes with CORE JAVE book. What should I do to remove those 2 errors.


Thank you Ernest. Your suggestion will be very helpful.

Raghav.


// *************************************** File Retirement.java**********

import corejava.*;

public class Retirement
{


public static void main(String[] args)
{

double goal;
double interest;
double payment;
int years=0;
double balance = 0;

goal = Console.readDouble("How much money do you need to retire?");
payment = Console.readDouble(" How much money will you contribute every year?");
interest = Console.readDouble("Interest rate in %(ex: use 7.5 for 7.5%):");

while (balance<goal)
{
balance = (balance +payment) * (1+interest);

years ++;
}

System.out.println(" You can retire in "+years+" years.");

}

}

//*********************** End of the file Retirement.java***************

//************************** File Console.java *************************
package corejava;

/**
An easy interface to read numbers and strings from
standard input

@version 1.10 10 Mar 1997
@author Cay Horstmann
*/

public class Console
{ /**
print a prompt on the console but don't print a newline

@param prompt the prompt string to display
*/

public static void printPrompt(String prompt)
{ System.out.print(prompt + " ");
System.out.flush();
}

/**
read a string from the console. The string is
terminated by a newline

@return the input string (without the newline)
*/

public static String readLine()
{ int ch;
String r = "";
boolean done = false;
while (!done)
{ try
{ ch = System.in.read();
if (ch < 0 || (char)ch == '\n')
done = true;
else if ((char)ch != '\r') // weird--it used to do \r\n translation
r = r + (char) ch;
}
catch(java.io.IOException e)
{ done = true;
}
}
return r;
}

/**
read a string from the console. The string is
terminated by a newline

@param prompt the prompt string to display
@return the input string (without the newline)
*/

public static String readLine(String prompt)
{ printPrompt(prompt);
return readLine();
}

/**
read an integer from the console. The input is
terminated by a newline

@param prompt the prompt string to display
@return the input value as an int
@exception NumberFormatException if bad input
*/

public static int readInt(String prompt)
{ while(true)
{ printPrompt(prompt);
try
{ return Integer.valueOf
(readLine().trim()).intValue();
} catch(NumberFormatException e)
{ System.out.println
("Not an integer. Please try again!");
}
}
}

/**
read a floating point number from the console.
The input is terminated by a newline

@param prompt the prompt string to display
@return the input value as a double
@exception NumberFormatException if bad input
*/

public static double readDouble(String prompt)
{ while(true)
{ printPrompt(prompt);
try
{ return Double.parseDouble(readLine().trim());
} catch(NumberFormatException e)
{ System.out.println
("Not a floating point number. Please try again!");
}
}
}
}
// **************** End of file Console.java ********************
 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic