tags:

views:

43

answers:

3

I've just started using eclipse and java and I'm not used to either one of them. I wrote a simple helloworld-programm, but the next task (school) was to create a program that takes a userinput (from commandline) and responds with the highest number of two. The code I wrote looks like following:

public class Larger {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        if(args.length < 2)
        {
            System.out.print("Too few parameters submitted.");
            return;
        }
        int num1 = Integer.parseInt(args[0]);
        int num2 = Integer.parseInt(args[1]);
        System.out.print(Math.max(num1, num2));
    }

}

It all works well when I hit the "run"-button in eclipse, but later when I browse the source-files and tries to run "java Larger.class 2 4" i get an error from java.exe saying that no class was found.

Any idea what this can be?

+2  A: 

When it fails, are you invoking the Java process through Eclipse or the command line? It sounds like you're doing it from the command line. In that case, you don't specify the ".class" portion when invoking your Java program. Try :

java Larger 2 4
Amir Afghani
Thnx. This works perfectly.
Alxandr
+2  A: 

The "run" button launch your program with the adequate classpath (the bin folder where the .class is generated)

alt text

the java needs to refer to that same bin folder, and use the class name (not the class generated binary)

java -cp bin Larger 2 4
VonC
That's right. But to be very accurate: It depends on your project setup wheter 'bin' is enough.
DerMike
A: 

To compile javac Large.java

To run java Larger 2 4

Warrior