- Rename the file to be called
Greet.java
. That file should contain exactly the code that you posted in your question, nothing more.
- Run
javac Greet.java
.
- Run
java Greet
.
This assumes that you have a working JDK installed on your machine.
As stated in the comments before, it seems that you are trying to run your Java code with a Python interpreter. Python is a completely different programming environment.
Update: So, I had a look at Codenvy. They provide a complete Hello World example. Create a new workspace, select the "Java" quick start stack and add the console-java-simple
project to the workspace. Then run the console-java-simple: run
Maven task. You can get a list of the project's Maven tasks by pressing Shift+F10
.
The HelloWorld.java
file in their example is almost identical to your Greet.java
.
Here's how to do it step by step:
- Log in to Codenvy.
- On the dashboard, click
Create Workspace
(under Recent Workspaces
)
- On the following page, in the "Select Stack" section, select the stack labeled
Java - Default Java Stack with JDK 8, Maven and Tomcat.
(not the preselected one that includes MySQL).
- On the same page, in the "Projects" section, click
Add or Import Project
and check the console-java-simple
project. Then click Add
.
- Click the big green
Create
button at the bottom, or the one in the upper right corner. The workspace gets created and the view switches to the new workspace. Wait until you see a notification in the upper right corner telling you that the console-java-simple
project was successfully imported.
- Press
Shift+F10
.
- Double click the
run
Maven task.
- See the output of the Maven build and finally the "Hello World" at the very bottom of the console.
In the project explorer, under console-java-simple/src/main/java/org.eclipse.che.examples/
, you can find the HelloWorld.java
.
Update: By the way, I don't think that Codenvy is the right tool to get started with Java. It's not meant to be a quick and easy way to play around with Java but instead a full blown IDE running in the browser. You have to deal with a lot of distractions from actual Java programming, like build tools (e.g. Maven) to get anything running.
If getting started with Java is what you are aiming at, I'd recommend to find a way to get a JDK installed locally and then play around with that.