0

I am a Java beginner. I wrote a quintessential "Hello, World!" program. It compiles, but won't run. The terminal says there is an exception in the thread main, and that the class hello is not found. I am using Ubuntu 12.04. What could be wrong here?

The file is called hello.java.

The commands I used:

$javac hello.java
$java hello

My code is below:

class hello{
public static void main(String[] args) {
    system.out.print("Hello");  
}
}

EDIT-----------------------------------------------------------------------------------------

I just realized that I am using openjdk7. Does that pose a problem?

4
  • Show us what command you ran to run this program. Commented Sep 28, 2013 at 18:18
  • What package is the class in, and how are you trying to run it? edit Beaten to it... Commented Sep 28, 2013 at 18:19
  • 1
    show ur your complete error log Commented Sep 28, 2013 at 18:43
  • Tell us whether you can see a file called hello.class anywhere. Try running the program from the same directory that this file is in. Commented Sep 28, 2013 at 20:30

3 Answers 3

1

class must be: public class hello system.out.print is wrong, must be: System.out.println("Hello World");

Sign up to request clarification or add additional context in comments.

3 Comments

If syntax is wrong compilation fails. In the question @tys says the program is compiling.
@pieter, Thank you. I just tried this; however, it is still throwing the same error.
It is compiling fine.
1

Is the filename hello or Hello? The only way I duplicated your problem was by having the class name wrong, and in java the class name an filename must exactly match (meaning the case too). So if your filename is Hello.java and the class name is hello the program will compile fine but throw the same error you mentioned. This is just a guess though.

Comments

0

Is that all your code? Since you use a terminal, can you add the results of the command ls -lR to your question? (run it in the same directory as your original command executing the application).

2 Comments

I can't add it. The result is probably 1000 lines
Ah, ok - try java -cp . hello

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.