build and compile

I am new to java and am having trouble with setting things up so my code will compile.

I have 2 code programs (OSX) : JJ Edit (very bare-bones) and Net Beans.

I think with the JJEdit, I have to have all my classes in the same document, and with NetBeans I have to have all my classes in the same project, but in different documents.

Here is some code from the book I am learning with. The Echo class is at the bottom outside of the EchoTestDrive. I've tried putting it several different places.

Thanks for your help.

public class EchoTestDrive {

public static void main (String [] args) {

Echo e1 = new Echo;

Echo e2 = new Echo;

int x = 0;

while (x<4) {

e1.hello();

e1.count=e1.count + 1;

if (x==3) {

e2.count = e2.count + 1;

}

if (x>0) {

e2.count = e2.count + e1.count;

}

x=x+1;

}

System.out.println(e2.count);

}

}

class Echo {

int count = 0;

void hello() {

System.out.println("hello");

}

}

[1091 byte] By [exactitudea] at [2007-10-2 0:48:25]
# 1

The best thing to do is to just compile your code in a command shell using javac.exe.

Both NetBeans and JEdit use Java conventions. That's what you should understand first.

JEdit does not require that all your classes be in the same document. Java itself has no such requirement.

What you have to learn is CLASSPATH, which tells the class loader where to find all the .class files it needs to compile and run your code. Start reading about that.

Your code fails to compile because you have syntax errors.

This works better:

public class EchoTestDrive {

public static void main (String [] args) {

Echo e1 = new Echo();

Echo e2 = new Echo();

int x = 0;

while (x<4) {

e1.hello();

e1.count=e1.count + 1;

if (x==3) {

e2.count = e2.count + 1;

}

if (x>0) {

e2.count = e2.count + e1.count;

}

x=x+1;

}

System.out.println(e2.count);

}

}

class Echo {

int count = 0;

void hello() {

System.out.println("hello");

}

}

Look at the lines where you call the Echo constructor.

%

duffymoa at 2007-7-15 17:58:30 > top of Java-index,Java Essentials,New To Java...
# 2
Thank you- this has been a great help.
exactitudea at 2007-7-15 17:58:30 > top of Java-index,Java Essentials,New To Java...