Hi Everyone i´m new to Coding and i already hit a brickwall a 3 days ago with this exercise

I do not understand why if i closed the curly brackets and ended the syntax with colon every time i get this error regardless of how much i compare it to the example on the exercise. What can i be missing?

https://www.codecademy.com/paths/introduction-to-android-with-java/tracks/introduction-to-android-and-java/modules/learn-java-hello-world/projects/planting-a-tree

Hi Chip

Can you show us your code?

public class Tree {
public static void main(Stringargs)
{
// My tree is an Oak
/* It has been imported from Ontario
is has DNA from trees that were endemic in the Mezozoic era */ }

{ System.out.println (“Hi there!..some called me Jay, i am a mutant, sometimes i fly and sometimes i code”);}
{System.out.println(" * “);
System.out.println(” *** “);
System.out.println(” *** “);
System.out.println(” * “);
System.out.println(” * "); }

You don’t need to wrap everything in curly brackets. Try to wrap only the whole class and the main method.

1 Like

Thanks, though its turning a bit frustrating it gives me more errors the more i try, please
{public class Tree
public static void main(Stringargs) }

// My tree is an Oak
/* It has been imported from Ontario
is has DNA from trees that were endemic in the Mezozoic era */

{ System.out.println (“Hi there!..some called me Jay, i am a mutant, sometimes i fly and sometimes i code”);}
{System.out.println(" * “);
System.out.println(” *** “);
System.out.println(” *** “);
System.out.println(” * “);
System.out.println(” * "); }

Result:

Tree.java:3: error: class, interface, or enum expected
{public class Tree
^
Tree.java:3: error: ‘{’ expected
{public class Tree
^
Tree.java:4: error: ‘;’ expected
public static void main(Stringargs) }
^
Tree.java:10: error: class, interface, or enum expected
{ System.out.println (“Hi there!..some called me Jay, i am a mutant, sometimes i fly and sometimes i code”);}
^
Tree.java:10: error: class, interface, or enum expected
{ System.out.println (“Hi there!..some called me Jay, i am a mutant, sometimes i fly and sometimes i code”);}
^
Tree.java:12: error: class, interface, or enum expected
System.out.println(" *** “);
^
Tree.java:13: error: class, interface, or enum expected
System.out.println(” *** “);
^
Tree.java:14: error: class, interface, or enum expected
System.out.println(” * “);
^
Tree.java:15: error: class, interface, or enum expected
System.out.println(” * “); }
^
Tree.java:15: error: class, interface, or enum expected
System.out.println(” * "); }
^
10 errors

Objective
ANDROID AND JAVA FOUNDATIONS
Planting a Tree
Introduce yourself to users and plant a tree for them!

Tasks
4/7Complete
Mark the tasks as complete by checking them off
Creating the Class
1.
We’re starting with a blank Java file named Tree.java.

Define a class that follows the Java naming conventions.

Stuck? Get a hint
2.
This code produces an error because our program needs a main() method.

Define this method inside the curly braces of the Tree class.

Stuck? Get a hint
3.
Write a comment in main() that describes the task it will perform.

We’re going to introduce ourselves and print a tree to the screen.

You can use the single-line or multi-line syntax for your comment.

Stuck? Get a hint
4.
Below your comment, print a message introducing yourself to the user.

Try something like “Hey there, I’m Ariel and I’m learning to code in Java!”

When you run the code, you should see this message printed to the screen.

Stuck? Get a hint
Planting Trees
5.
After introducing yourself, use another print statement to output the project goal!

Something like “I’m going to plant a tree today!” or “Ready to get my hands dirty!”

See how the second statement begins on a new line? We’ll use multiple print statements to plant our tree.

For example:

System.out.println("  *  ");
System.out.println(" *** ");
System.out.println(" *** ");
System.out.println("  *  ");
System.out.println("  *  ");   

will print a tree like this:



Try it out!

Have fun and experiment with different trees.

Here are a couple we made:




**
**

 ***** 
 ***** 
 ***** 
   *   
   *   
#######
You can explore other printing methods in the Java documentation.


Planting a Tree
4/7Complete
public class Tree { //This is the curly bracket which indicates the beginning of your class Tree.
  public static void main(String[] args) { //This is the curly bracket which indicates the beginning of your main method.
System.out.println("...")
  } // This is the curly brace which indicates the end of your main method.
} //This is the curly bracket which indicates the end of your class Tree.

When you click on or next to a curly bracket they should get green and show you which one is its “partner”-bracket.

1 Like

Hi Chip,

I’ve read through the whole conversation, and I can see that you are very unsure of what the curly brackets do.

Before I start, I would like to first highlight that comments will not run with your code at all. They are there simply to help readability, so that anyone reading your code can understand. Hence the comments can be anywhere; the comments ignore all the curly brackets { } or parenthesis ( ) as well.

Java is based on object-oriented programming. Basically, everything with curly brackets can be viewed as objects.

Firstly, the class is like your file. For your file to run, all the code you type must reside within the class. It will look something like this:

public class Tree{
  //your entire code must lie within this pair of curly brackets
}

Secondly, for any code that runs into the terminal, i.e. there is output or printing for the user to see/read, it has to go into the main method. Simply put, the main method connects your code to the terminal, so a user who runs your code does not have to read the code, and will only read the information printed into the terminal (via System.out.println() ). Therefore, your code will always have a main method, like this:

public class Tree{
  public static void main(String[] args){
    /* whatever code you need to print into the terminal 
    will exist within these curly brackets as well */
    //E.g.:
    System.out.println("Let's start planting trees :)");
  }
}

As I have mentioned, the main method is a method to run your code into the terminal. So yes, many other methods can be written. These methods will have their own curly brackets, and the methods will exist outside of the main, but within the class. You will learn this further down the course.

You might not understand what the terms “public”, “static”, “void”, “String”, “args” etc. means now, but if you keep on learning, you will understand them in due time, as planned by the Codecademy course. All the best!! :muscle: