Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java 101

Status
Not open for further replies.

MJV

Programmer
Oct 2, 2002
10
CA
Hi,

Just started to learning java.

I found this site;

When I copy the code for Account.java and AccountDemo.java,
I get the following error for AccountDemo.java:

C:\Java Samples>javac accountdemo.java
Accountdemo.java:8: cannot resolve symbol
symbol : class Account
location : class AccountDemo
Account my_account = new Account<>;
^
accountdemo.java:8: cannot resolve symbol
symbol : class Account
location : class AccountDemo
Account my_account = new Account<>;
^
2 errors

Does anyone know what is wrong with the code?

MJV
 
check the case, Account vs. account. Java is case sensitive.
Also, if the class name is Account(usual class name with uppercase 'A'), then you want to name the file Account.java (with capital 'A') also.

~za~
You can't bring back a dead thread!
 
Thanks for your answer. The case seems to be correct.
The code for Account.java and AccountDemo.java is below.

Account.java is as follows (it compiles):
/*
*
* Account
* Demonstration for Java 102 tutorial
* David Reilly, February 25, 1997
*/
public class Account
{
protected double balance;

// Constructor to initialize balance
public Account(double amount)
{
balance = amount;
}

// Overloaded constructor for empty balance
public Account()
{
balance = 0.0;
}

public void deposit( double amount )
{
balance += amount;
}

public double withdraw( double amount )
{
// See if amount can be withdrawn
if (balance >= amount)
{
balance -= amount;
return amount;
}
else
// Withdrawal not allowed
return 0.0;
}

public double getbalance()
{
return balance;
}
}

AccountDemo.java is as follows:

/* * * AccountDemo * Demonstration of Account class * */
class AccountDemo
{
public static void main(String args[])
{

// Create an empty account
Account my_account = new Account();

// Deposit money
my_account.deposit(250.00);

// Print current balance
System.out.println(&quot;Current balance &quot; + my_account.getbalance());

// Withdraw money
my_account.withdraw(80.00);

// Print remaining balance
System.out.println(&quot;Remaining balance &quot; + my_account.getbalance());

}

}

MJV
 
check your CLASSPATH(in control panel) and make sure you have
CLASSPATH=.;

&quot;.&quot; will ask the compiler to start looking from the project directory, in your case the C:\Java Samples directory.

~za~
You can't bring back a dead thread!
 
Your compiler is saying that there are two files that will not compile (from the error) :

accountdemo.java
Accountdemo.java

As maxpower1 says, case is sensitive in java.

Your &quot;Account&quot; class must be saved in a file called &quot;Account.java&quot;
Your &quot;AccountDemo&quot; class must be saved in a file called &quot;AccountDemo.java&quot;

 
opps.good point. i overlooked something.

thx sedj!

MJV, instead of
>C:\Java Samples>javac accountdemo.java

try
C:\javac AccountDemo.java



~za~
You can't bring back a dead thread!
 
dooppp!!(Homer Simpson)

i mean, try
C:\Java Samples>javac AccountDemo.java

~za~
You can't bring back a dead thread!
 
I think it's a classpath problem. When you try to compile AccountDemo, javac doesn't find the Account.class file. So the idea of including the current directory on the path should work.

Furthermore, AFAIK the name or the files are not case sensitive, for example, on Windows.

Cheers.

Dian
 
Ha ! We're all being fools.

OK, there are two problems.

As Dian said, yes AccountDemo cannot resolve Account (ie CLASSPATH).

However the filenames are defintely case sensitive, and this will cause problems.

EG - if a class Test is in test.java, you get this error :

Code:
C:\java>javac test.java
test.java:3: class Test is public, should be declared in a file named Test.java
public class Test {

1 error
 
Sorry for my last post, I think I made it too ambiguous. What I tried to say about the case sensitive thingie is:

- Yes, the class Account must be on a file named Account.java

- When compiling with the command line in Windows,

javac Account.java and javac account.java

are exactly the same, no matter which is the real name of the file.

So I still bet for a classpath problem.

Bte, MJV, don't get frightened with this. Java isn't that difficult.

Cheers.

Dian
 
Thanks to all in this thread!!!!

Dian, thanks for the kind words...I am an RPG programmer therefore have some programming experience...but NEW to Java.

BTW, it was the CLASSPATH issue, once I set that it compiled.

MJV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top