Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java The Solution

Jamal Desir
Jamal Desir
1,184 Points

bash: Greeter.java: command not found?

For some reason, it gives me the message "bash: Greeter.java: command not found" when I run the code. Did i do something wrong? Here's my code:

import java.io.Console;

public class Greeter {

public static void main(String[] args) { Console console = System.console();

String place = "Walmart";
String firstName = console.readLine("What is your first name:  ");
console.printf("Hello %s! Welcome to %s. %n" , firstName , place);

}

}

You did run command correctly? after you saved your file. I mean: javac <name>.java && java <name>

You most probably wrote in bash "Greeter.java" which is incorrect.

To run the program you need to first compile it using "javac Greeter.java" and then run it with "java Greeter"

1 Answer

Is this part on a separate line, indented under the <public static void> line?

Console console = System.console();

Additionally, try starting your console with

treehouse:~/workspace$ clear && javac Greeter.java && java Greeter

Finally, I notice your final line has spaces BEFORE and after commas. You only need spaces AFTER commas.

Hope this helps!