This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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 Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package Question" Watch "Package Question" New topic

Package Question

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
I saved the file as 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;
public void main (String args[]) {
Exercise1 instance = new Excercise1();
> javac

c:\jdk1.3\bin>javac class Exercise1 is public, should be declared in a file named
public class Exercise1 {
^ 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();
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:


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/
only if the file is in folder com/acme.
Otherwise you can compile like this:
javac -d .
this will create com/acme directories and add the put classfile in it.
subject: Package Question