wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Package Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package Question" Watch "Package Question" New topic
Author

Package Question

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
Hello,
I saved the file as Exercise1.java but when I compile it I receive errors as stated:
What must I do to resolve these mistakes? I think it’s got to do with the package statement.

package com.acme;
import java.util.*;
public class Exercise1 {
int counter;
public void go() {
int sum = 0;
int i = 0;
while (i<100) {
if (i==0)
sum = 100;
sum = sum +1;
i++;
System.out.println(sum);
}
}
public void main (String args[]) {
Exercise1 instance = new Excercise1();
instance.go();
}
}
> javac Excercise1.java

c:\jdk1.3\bin>javac Excercise1.java
Excercise1.java:5: class Exercise1 is public, should be declared in a file named Exercise1.java
public class Exercise1 {
^
Excercise1.java:20: cannot resolve symbol
symbol : class Excercise1
location: class com.acme.Exercise1
Exercise1 instance = new Excercise1();
^
2 errors
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
It's because of a spelling mistake
Inside main change the following line
Exercise1 instance = new Excercise1();
to
Exercise1 instance = new Exercise1();
and it will work.


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You should compile the code like this:

and run it like this:

/Rene


Regards, Rene Larsen
Dropbox Invite
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
You need to compile the code like this
javac com/acme/Exercise1.java
only if the file Exercise1.java is in folder com/acme.
Otherwise you can compile like this:
javac -d . Exercise1.java
this will create com/acme directories and add the put classfile in it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Package Question