Hi all, does anyone know of a good compiler I can download for java? It would be nice if it was an IDE but it does not have to be. I currently have the j2sdk-1_4 compiler http://java.sun.com/j2se/1.4.1/download.html and it does not seem to work that well. Also I know that this is really easy, but hey I can't compile anything I make, what is wrong with this code?

public class BuckleShoe
{
	public static void main(String args)
	{
		EasyReader console = new EasyReader();
		private int choice;

		do
		{
			System.out.print("Enter a number 1-10 (or 0 to quit):");
			int choice = console.readInt ();

			switch (choice)
			{
				case 0:
				   System.out.println("Bye");
				break;

				case 1:
				case 2:
				   System.out.println("Buckle your shoe");
				break;
				
				case 3:
				case 4:
				   System.out.println("Shut the door");
				break;

				case 5:
				case 6:
				   System.out.println("Pick up sticks");
				break;
		
				case 7:
				case 8:
				   System.out.println("lay them straight");
				break;

				case 9:
				case 10:
				   System.out.println("A big fat hen");
				break;
				
				default:
				   System.out.println("invalid entry");
				break;
			}
		} while (choice != 0);
	}
}

My guess is that your school uses some new packaged classes because they are too lazy to create a one line statement that reads input. EasyReader is not a java class, that is, if you haven't downloaded that add on..

use this:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int x = br.readLine();

My guess is that your school uses some new packaged classes because they are too lazy to create a one line statement that reads input.

Your guess is right, ( I probably should have said that) but I can not even compile extremely simple programs such as:

public class HelloWorld
{
  public static void main(String[] args)
        {
             System.out.println("Hello, World");
         }
}

I get an error message that says:

Empty.java [1:1] class HelloWorld is public, should be declared in a file named HelloWorld.java
public class HelloWorld
^
1 error
Errors compiling Empty.

I don't understand, am I supposed to save in some sort of special file/format before compiling?

The filename should have the same name as the class:

public class X

so the filename should be:

X.java

Is your filename HelloWorld.java ?

The filename should have the same name as the class:

public class X

so the filename should be:

X.java

Is your filename HelloWorld.java ?

The file name is the same ( HelloWorld.java ), but here is another error message I get when i try to create the program,

java.lang.NoClassDefFoundError: Mystuff/Empty
Exception in thread "main"

Ohh I see what it is now, it's your classpath..Have you set it yet?


If you haven't set it to point directly to the tools.jar file

If you have, post it, and I will take a look at it.

Actually I haven't :o how would I start to do this? I have Netbeans IDE version 3.6 as my compiler, and I am running it on windoze xp home.

The Sun compiler is the ONLY official one for the language.
There are others that are certified to be correct but the Sun package (which you claim doesn't work...) is the standard.

Anything that doesn't compile with that should not compile with anything.

Sorry, I've never really worked with netbeans, so I don't know anything about setting the classpath on that...Maybe it's the same principle though:

try this:

GOTO: Start -->(right click on)My computer--> properties -->advanced

--environment variables

you should have one that says classpath and path:

set the path variable to the path that points to the bin folder located in your jdk folder

set the classpath variable to the path that points to the tools.jar file located in your jdk folder

Again, not sure if this will work. I don't use netbeans.

If you don't even know how to use your classpath you shouldn't be using an IDE at all.
For an IDE, you normally set the included libraries for a project in the project options.
RTFM about how to do that.
As to Netbeans, scrap that piece of junk.

Compiler suggestion: Use EditPlus 2 with javac as a user tool. How to set that upis in the EP2 help file.

I use Eclipse 3, That seems to be quite good to me. It has a built in console window where you can test run your code.

This article has been dead for over six months. Start a new discussion instead.