r/learnjava • • Dec 18 '20

How do I run a java script

class Main{
    public static void main(String[] args){
        Console.log("Hello world");
    };
};

I have this saved as java file, however would like to have it run as a script. Not sure why it won't work, and how do I get it into browser?

1 Upvotes

5 comments sorted by

View all comments

3

u/[deleted] Dec 18 '20

Do you have Java installed? Is it associated with .java files?

2

u/Loud-Somewhere7334 Dec 18 '20

Yes, I do have it installed (but not the plugins for browser). I'm looking to run this in script mode. If it helps, I'm using a Native Intel CPU Mac.

2

u/feral_claire Dec 18 '20

You seem to be confusing Java and Javascript. They have similar madness but are completely different languages and are not related. Your code snippet is actuality half Java, half Javascript. Because you want to run in a browser, you are probably looking for Javascript. Java doesn't run in a browser.

How are you trying to run the code and what errors do you get?