Support says this will work what is wrong with it?

javac.Language.java

class Language {

protected String name;
protected int numSpeakers;
protected String regionsSpoken;

protected String wordOrder;

Language(String langName, int speakers, String regions, String wdOrder) {
this.name = langName;
this.numSpeakers = speakers;
this.regionsSpoken = regions;
this.wordOrder = wdOrder;
}

public void getInfo() {

System.out.println(this.name + " is spoken by\n" + this.numSpeakers + " people mainly\nin " + this.regionsSpoken + ".");
System.out.println("The language follows the word\norder: " + this.wordOrder);

}

public static void main(String args) {
// testing Language
Language spanish = new Language(“Spanish”, 555000000, “Spain, Latin America, and Equatorial Guinea”, “subject-verb-object”);
spanish.getInfo();
}

}

Many errors in Bash. Thanks very much.
Ad Blocker turned off, Firewall turned off.
Same errors. First error:
$ javac.Language.java
bash: javac.Language.java: command not found

I can’t set the environment can I?

God Bless,
Don

The command should be $javac Language.java not $ javac.Language.java.
Ad blocker and firewall won’t affect this since the java compiler is not connected to the internet.

Thanks. But that:

javac Language.java

still gives:
javac Language.java

$ javac Language.java
Language.java:1: error: class, interface, or enum expected
javac Language.java

God Bless,
Don

I will try it with the $ like you said…

Your actual .java file should start

class Language {

protected String name;
protected int numSpeakers;
protected String regionsSpoken;

not like this

javac Language.java
class Language {

protected String name;
protected int numSpeakers;
protected String regionsSpoken;

Don’t put the $, that’s just to show it’s the prompt.

The first line was accepted but not much else:

$
$ class Language {
bash: class: command not found
$
$ protected String name;
bash: protected: command not found
$ protected int numSpeakers;
bash: protected: command not found
$ protected String regionsSpoken;
bash: protected: command not found
$
$ protected String wordOrder;
bash: protected: command not found
$
$ Language(String langName, int speakers, String regions, String wdOrder) {
bash: syntax error near unexpected token String' $ this.name = langName; bash: this.name: command not found $ this.numSpeakers = speakers; bash: this.numSpeakers: command not found $ this.regionsSpoken = regions; bash: this.regionsSpoken: command not found $ this.wordOrder = wdOrder; bash: this.wordOrder: command not found $ } bash: syntax error near unexpected token }’
$
$ public void getInfo() {
bash: syntax error near unexpected token (' $ $ System.out.println(this.name + " is spoken by\n" + this.numSpeakers + " ople mainly\nin " + this.regionsSpoken + "."); bash: syntax error near unexpected token this.name’
$ System.out.println("The language follows the word\norder: " + this.wordOer);
bash: syntax error near unexpected token "The language follows the word\norder: "' $ $ } bash: syntax error near unexpected token }’
$
$ public static void main(String args) {
bash: syntax error near unexpected token (' $ // testing Language bash: //: Is a directory $ Language spanish = new Language("Spanish", 555000000, "Spain, Latin Amera, and Equatorial Guinea", "subject-verb-object"); bash: syntax error near unexpected token (’
$ spanish.getInfo();
bash: syntax error near unexpected token ;' $ } bash: syntax error near unexpected token }’
$
$ }

Here’s a video guide for compiling java in windows command line: How to Run Java Program in Command Prompt (CMD) in Windows 10 - YouTube

Your code itself is legal java code (it may have errors, but they should be regular java error, not bash errors). So it’s an issue of compilation at this point.

The java compiles fine in IntelliJ but not on Codecademy.
Do I have to change environment variables? How to do that on Codecademy?
Thanks.

God Bless,
Don

What error do you get when trying to compile on the codecademy environment?
Can you share a link to the environment where you’re trying to run it if it’s from codecademy?

Quite a few really…

$
$ class Language {
bash: class: command not found
$
$ protected String name;
bash: protected: command not found
$ protected int numSpeakers;
bash: protected: command not found
$ protected String regionsSpoken;
bash: protected: command not found
$
$ protected String wordOrder;
bash: protected: command not found
$
$ Language(String langName, int speakers, String regions, String wdOrder) {
bash: syntax error near unexpected token String' $ this.name = langName; bash: this.name: command not found $ this.numSpeakers = speakers; bash: this.numSpeakers: command not found $ this.regionsSpoken = regions; bash: this.regionsSpoken: command not found $ this.wordOrder = wdOrder; bash: this.wordOrder: command not found $ } bash: syntax error near unexpected token }’
$
$ public void getInfo() {
bash: syntax error near unexpected token (' $ $ System.out.println(this.name + " is spoken by\n" + this.numSpeakers + " ople mainly\nin " + this.regionsSpoken + "."); bash: syntax error near unexpected token this.name’
$ System.out.println("The language follows the word\norder: " + this.wordOer);
bash: syntax error near unexpected token "The language follows the word\norder: "' $ $ } bash: syntax error near unexpected token }’
$
$ public static void main(String args) {
bash: syntax error near unexpected token (' $ // testing Language bash: //: Is a directory $ Language spanish = new Language("Spanish", 555000000, "Spain, Latin Amera, and Equatorial Guinea", "subject-verb-object"); bash: syntax error near unexpected token (’
$ spanish.getInfo();
bash: syntax error near unexpected token ;' $ } bash: syntax error near unexpected token }’
$
$ }

This looks like you’re trying to run the actual lines of your java file in bash.
You should have your code saved in a java file (Language.java).
Then, the compiler program is called javac, and it can interpret your file. (That’s the javac Language.java command).

Can you link to where you’re trying to run it in codecademy?
Maybe show a screenshot of what it looks like when you type the ls command to list the files.

https://www.codecademy.com/courses/java-for-programmers/projects/java-language-families

This works let me post my instructions for how to get this running, one sec.

  1. Paste your code here and click SAVE

  2. Type ls command to confirm your file is there (you should see Language.java listed).

$ ls
Language.class  Mayan.java
Language.java   SinoTibetan.java
  1. Type javac Language.java this will compile your file. If successful you should not get any messages.

  2. To run the file type java Language
    You will get this output

Spanish is spoken by
555000000 people mainly
in Spain, Latin America, and Equatorial Guinea.
The language follows the word
order: subject-verb-object

@net2829343819 check these instructions and see if they work for you.

This is how it should look like from the terminal end:

1 Like

It is probably a problem a new user will experience on Codecademy.
The bash accepts the input right beside the Codecademy Editor with save and copy to clipboard buttons. How does one put a file like Language.java into bash?

Thanks for all your work.
The file Language.java compiles fine in IntelliJ and runs fine.
What am I missing? Thanks.

God Bless,
Don

You’re not missing anything (your code works!), it’s simply getting used to the procedures. You can look into the command-line lessons codecademy offers.

I also recommend this video series if you want to understand how the command-line works a little better: Linux Command Line (01) What Is The Linux Command Line - YouTube

Best of luck.

1 Like

Ok, Thank you!

God Bless,
Don

1 Like