2

It's been quite a while since I've used java extensively, and I'm having trouble with something I think is probably quite simple. Code is on a linux system, and I'm using javac and other command line tools.

Two files, the second won't compile. Here's the first, named ITranslator.java:

package org.helloopensource.greetings;

public interface ITranslator {
    public abstract String translate(String fromLanguage, String toLanguage, String word);
}

Here's the second, named Greeting.java:

package org.helloopensource.greetings; 

public class Greeting {
    private ITranslator translator;

    public Greeting(ITranslator translator) {
            this.translator = translator;
     }

    public String sayHello(String language, String name) {
            return translator.translate("English", language, "Hello") + " " + name;
    }
}

When I try to compile, I get:

> javac -classpath `pwd` Greeting.java
Greeting.java:4: cannot find symbol
symbol  : class ITranslator
location: class org.helloopensource.greetings.Greeting
    private ITranslator translator;
            ^
Greeting.java:6: cannot find symbol
symbol  : class ITranslator
location: class org.helloopensource.greetings.Greeting
    public Greeting(ITranslator translator) {
                    ^
2 errors

Like I said, I suspect this is something simple, or something dumb I'm doing wrong. Any help would be greatly appreciated.

Thanks,

Sean.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
Sean
  • 431
  • 2
  • 6
  • 14
  • Any reason you're not using an IDE (Eclipse, IntelliJ IDEA, NetBeans, ...)? – Matt Ball Jun 29 '11 at 20:17
  • 1
    @Matt - any reason why he should? – KevinDTimm Jun 29 '11 at 20:26
  • @Kevin http://stackoverflow.com/questions/208193/why-should-i-use-an-ide – Matt Ball Jun 29 '11 at 20:29
  • @Matt - disagree - for this simple stuff an IDE gets in the way. Understanding the API and how to use vi/emacs/xxx will save you some day. That said, my 'big' dev work gets done in an IDE, but I still do plenty of work using a plain old text editor. – KevinDTimm Jun 29 '11 at 20:32
  • Two reasons, really both the same. – Sean Jun 29 '11 at 20:43
  • Blasted thing took my return key as the add comment key. Anyway, I haven't used Java in about ten years, so I want to keep it simple. Second, I don't need the aggravation of learning an IDE at the same time. Finally, I know vi extremely well, and I'm very fast with it. I hear Eclipse can be set up to use a vi style editor, so maybe I'll try that when I've got the basics back in my head. If not, I'll probably stick with vi. (And yes, I've used many IDEs over the years.) – Sean Jun 29 '11 at 20:56

2 Answers2

10

Java requires that class files be found in a subdirectory that matches their package names. So:

    mkdir -p org/helloopensource/greetings
    mv *.java org/helloopensource/greetings/
    javac -classpath . org/helloopensource/greetings/*.java

should do it.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
0

javac *.java


irreputable
  • 44,725
  • 9
  • 65
  • 93