user2884703
user2884703

Reputation: 49

Cannot run Java HelloWorld on MacBook Pro OS Yosemite 10.10.5

I have a Mac running Yosemite 10.10.5 on a MacBook Pro and I have the recommended Java version jre.8u91. I have tried different attempts to run the following simple program, Which I created using TextEdit:

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

Note: it puts it away as an .rtf file. There is no .java file option under TextEdit file suffixes. There are others. In the Terminal app I type the following:

cd ~
Javac HelloWorld3.java

and receive the following:

Davids-MacBook-Pro:documents davidellisrogers$ javac HelloWorld3.rtf
error: Class names, 'HelloWorld3.rtf', are only accepted if annotation processing is explicitly requested
1 error
Davids-MacBook-Pro:documents davidellisrogers$

It has been a year since I used Java with Netbeans on my PC. I am relatively new to the Mac world. I suspect the .rtf and have forgotten the annotation parameter from my PC days.

Would appreciate help.

Upvotes: 2

Views: 75

Answers (1)

CSK
CSK

Reputation: 352

You need to save as HelloWorld3.java

and run the following command:

javac HelloWorld3.java

java HelloWorld3

Upvotes: 1

Related Questions