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 Type Casting

Aditya Puri
Aditya Puri
1,080 Points

Difference between loading and importing

What is the difference between loading and importing a class in the java repl? Can anyone please explain? :D

Aditya Puri
Aditya Puri
1,080 Points

watch the video it is showed in the beginning, when he opens the repl and loads and imports class

1 Answer

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

I think, but I'm not sure, all what load "file" command simply does is reading "file" and execute all commands in there, one-by-one, as if typed by you.

So it is totally unrelated to Java, it is just useful "REPL" command that read all lines in "file", that's it.

All the rest you have to write yourself.

So separate java command:

import com.teamtreehouse.Treet

From REPL command that just reads all lines in file provided and execute them:

:load com/teamtreehouse/Treet.java

What I can say more, you can:

  • create text file "text.txt"
  • write there System.out.println("here")
  • and then type :load text.txt

The result of the command will be success: REPL will just execute whatever was in that file, so he'll execute and write "here" in console. Try that out if you want.

In languages like Bash ,e.g. that you don't need to compile like Java, there is very much alike command called source, that does exactly the same, reads whatever is in file and executes it