aspose file tools
The moose likes Beginning Java and the fly likes Help with test class - new to programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with test class - new to programming" Watch "Help with test class - new to programming" New topic

Help with test class - new to programming

Rute Fischer

Joined: May 05, 2014
Posts: 2

I've just started to programming in Java, I’m using the book Head First Java to learn how to program. The book explains that for this moment I can use a testclass to test my created class.
My question: how does the testclass know where to find my created class when using a reference variables to access the created variables? See code examples below.
Both files compile without any problem but I fail to see how they link / work together. I'm really curious. Thank you for your time, Dutchy'91.

codes: contains: contains:

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31415

Welcome to CodeRanch! I added code tags to your post to make it easier to read.

In Java, all code goes in a package. If you don't specify one, it goes in the default package. Both of your classes are in the default package.

Java also has concept called a classpath. The default is class files in the current directory. You can automatically refer to classes in the classpath in the same package without doing anything.

Putting this together, it means you can refer to classes in the same directory if both are in the default package without having to do anything special. Which is a nice default! It lets people new to Java start without having to be aware of either of these concepts.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rute Fischer

Joined: May 05, 2014
Posts: 2
Hi Jeanne,

Thank you for your clear explanation. It makes more sense to me now how the referencing works 'under the hood' when executing my class file.
Again, thank you for your time!

Consider Paul's rocket mass heater.
subject: Help with test class - new to programming