This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 32481

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]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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!

Have you checked out Aspose?
subject: Help with test class - new to programming
It's not a secret anymore!