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 Java Data Structures - Retired Getting There Class Review

Aditya Puri
Aditya Puri
1,080 Points

Order of the import and package statements

So Dennis said that the order of the import and the package statements matter.

I too noticed that when I had my import statement before the package statement on the treet class, I got an error.

So can somebody please explain how import and package statements have to be ordered in java?

1 Answer

Harry James
Harry James
14,780 Points

Hey again Aditya,

The order is:

package com.yourpackage.name;

import com.importthis.package;
import com.alsoimportthis.package;

// The rest of your code

Note that the import statements themselves do not have to be in any sort of order.


Hope it helps and if you have any more questions, give me a shout :)