Featured resource
2026 Tech Forecast
2026 Tech Forecast

1,500+ tech insiders, business leaders, and Pluralsight Authors share their predictions on what’s shifting fastest and how to stay ahead.

Download the forecast
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Labs

Java Base Camp: Objects

A trail crew is scouting base camp sites along a river valley. Each candidate site is a coordinate on a grid, represented with java.awt.Point. The crew needs code that can plant an anchor camp, relocate scouts as they move, measure distances between camps, generate random candidate coordinates inside the mapped area, and finally assemble a report naming the nearest usable camp.

Lab platform
Lab Info
Level
Beginner
Last updated
Dec 04, 2026
Duration
45m

Contact sales

By clicking submit, you agree to our Privacy Policy and Terms of Use, and consent to receive marketing emails from Pluralsight.
Table of Contents
  1. Challenge

    Step 1: Scout the trailhead base camp locator project

    Base camp locator

    A trail crew is scouting base camp sites along a river valley. Every candidate site is a coordinate on a grid, and Java already ships a class built for exactly this: java.awt.Point. Over the next four steps you will plant an anchor camp, relocate scouts as they move, measure distances between camps, and finally generate random candidate coordinates so the crew can pick the nearest usable camp.

    The work happens entirely inside src/main/java/lab/. Each step owns its own file, and each file already imports the classes you need (java.awt.Point, java.util.Random, java.util.List) so you can focus on the object mechanics: constructing instances, reading and writing fields, and calling instance versus static methods. ## The starter files

    • CampSites.java — plants a camp anchor and reads its coordinates.
    • ScoutRoute.java — moves a scout's own Point and measures the gap between two camps.
    • CampSurvey.java — contrasts a static utility call with an instance call, then rolls random coordinates.
    • BaseCampLocator.java — wires everything together into a final report.

    Each file has one or more methods with a // TODO: Task N.M comment marking exactly what to fill in. A // Hint: line sits underneath naming the technique to reach for, never the finished line of code. ## Why Point fits this problem

    java.awt.Point stores an x and a y as public int fields — you can read or write camp.x directly, no getter required. It also exposes instance methods like move(x, y), translate(dx, dy), and distance(otherPoint) that act on the specific Point you're holding. Keep that public-field-versus-method distinction in mind; it's the first thing that trips up developers coming from languages where fields are private by default. Once you're oriented, move to Step 2 and plant the crew's first camp.

    info> If you get stuck, you can refer to the provided solution code for each task, available in the solution folder.

  2. Challenge

    Step 2: Plant camp anchors and read their coordinates

    Step 2: Plant camp anchors and read their coordinates

    Every camp the crew marks on the map is going to be a java.awt.Point. Before you can move scouts around or measure distances, you need a way to create that first anchor camp, drag it when a scout repositions it, and print its location for a report. All three of those live in CampSites.java. ### Building a Point

    Point has a constructor that takes both coordinates at once: new Point(x, y). That's the whole API for creating one — there's no builder, no factory method, just the constructor with the two ints the crew already measured in the field. ### Fields you can write to

    With the anchor camp planted, the next job is moving it. Point.x and Point.y are public int fields, not private ones hidden behind getters and setters. That means relocating a camp is just an assignment: camp.x = newX. There's nothing to call, nothing to construct — you're editing the object in place, and the same reference the caller already has will show the new position afterward. ### When to reach for the getters instead

    So if the fields are public, why does Point also expose getX() and getY()? Because those methods return double, not int — useful when a coordinate needs to line up with other geometry APIs that expect floating-point values, like the report format this app uses. For anything that needs to match that format, call the getter rather than reading the raw field, even though both describe the same position. With CampSites.java done, you can construct a camp, drag it to a new spot, and describe where it ended up. Step 3 puts a scout's own Point in motion and measures the distance between two camps.

  3. Challenge

    Step 3: Move scouts and measure camp distances

    Step 3: Move scouts and measure camp distances

    The anchor camp from Step 2 doesn't move once it's planted, but scouts do. As they hike out from camp, their position needs to update relative to where they already are, not jump to some absolute spot pulled from thin air. Point gives you two ways to change coordinates, and picking the wrong one silently breaks the route: move(x, y) overwrites both fields with the values you pass in, while translate(dx, dy) adds those values to whatever x and y already hold. A scout who has hiked to (12, 7) and then takes 3 steps east and 1 step north should land on (15, 8) — that's a job for translate, not move. ## Comparing two camps, not just one

    Once scouts can move, the crew's next question is practical: how far apart are two candidate camps? Point answers that with an instance method, distance(Point other). It's called on one Point and given another, and it returns the straight-line distance between them as a double — no manual square-root arithmetic required. Because it's an instance method, campA.distance(campB) and campB.distance(campA) both work and give the same answer; the method belongs to whichever object you call it on, but the math is symmetric.

  4. Challenge

    Step 4: Tell static utilities apart from instance calls, then roll random camps

    The crew has camps planted and scouts who can move between them. Now they need to compare camps: how far apart are two sites, and how do you even call the method that answers that? Java draws a sharp line between two kinds of calls. A static method belongs to the class itself and never touches any particular object's fields -- Math.abs(-5) doesn't care which Math you're using, because there is no such thing as "a" Math object. An instance method, by contrast, belongs to one specific object and reads or uses that object's own state -- campA.distance(campB) only makes sense because campA is a real Point with its own x and y. Open CampSurvey.java and start with the static case. That gap only looked at one axis. To see the true straight-line distance between two camps -- accounting for both east-west and north-south offset -- you need a method that already knows how to combine both. Point supplies exactly that as an instance method: campA.distance(campB) uses campA's own coordinates against campB's, so the call only makes sense hung off a real Point object, unlike the static Math.abs you just called on the class itself. With distance measurement in hand, the crew's last problem is generating fresh candidate sites to measure in the first place. java.util.Random also follows the instance rule: you create a Random object, and calling nextInt(bound) on that particular instance produces a pseudo-random int somewhere in the half-open range [0, bound) -- never equal to bound itself. That exclusive upper limit matters here because it lets bound stand for the width or height of the mapped area without ever generating a coordinate that falls just outside it.

  5. Challenge

    Step 5: Assemble the base camp locator report

    You have an anchor camp that can be planted and moved, and you know how to measure the distance between two points. Now put those pieces to work: the crew needs a batch of candidate sites to choose from, a way to rank them against the anchor, and a one-line report naming the winner. All three pieces live in BaseCampLocator.java, and each one builds directly on java.awt.Point and the instance methods you have already used. Random candidate generation is the first piece: the crew wants a pool of grid coordinates to scout, not just one. java.util.Random gives you that with nextInt(bound), which returns a value in [0, bound) -- exactly the range a grid coordinate needs. Call it twice per candidate, once for x and once for y, and keep reusing the same Random instance across the loop so each call advances the sequence instead of restarting it. With a pool of candidates in hand, the crew needs to know which one sits closest to the trailhead anchor. Point already gives you the comparison metric: calling distance(...) on one point with another as the argument returns the straight-line distance between them. Ranking candidates is just a matter of calling that instance method once per candidate and remembering the smallest result you have seen so far. The last piece turns that ranking into something the crew can read. buildReport should not repeat the search logic -- it already has findNearestCamp to call for the winning Point, and anchor.distance(...) to get the winning distance. Pull the x and y out of each Point with getX()/getY(), and assemble the report string in the exact layout the crew expects so it can be dropped straight into the day's field notes.

  6. Challenge

    Step 6: Run the application

    Every task is done, and each one was graded the moment you completed it. What you have not done yet is watch the whole application run at once -- which is the only place the pieces you wrote separately become a single working program.

    Start the application

    Open the Terminal tab and run:

    mvn --batch-mode --quiet compile && java -cp target/classes lab.Main
    

    The program runs in the terminal and prints its output there. Every behaviour it shows is code you wrote in the previous steps, so read the output against what each task asked for -- that is the whole lab, working as one program. ### Run the checks yourself

    The lab ran each task's test for you as you went, but they are ordinary tests and you can run them whenever you like. The whole suite:

    mvn --batch-mode --quiet test
    

    Or one task at a time:

    bash runTest.sh task_2_1
    

    Each failure names the task it belongs to, so the output tells you which step to go back to rather than which line to stare at. Two things worth trying before you finish: break something on purpose and watch the matching check fail, then put it back. Knowing what a failure looks like is worth as much as knowing what a pass looks like, and it costs you nothing here.

    When you are done, everything you wrote is still in the editor tabs -- the lab is yours to keep reading.

About the author

Pluralsight’s AI authoring technology is designed to accelerate the creation of hands-on, technical learning experiences. Serving as a first-pass content generator, it produces structured lab drafts aligned to learning objectives defined by Pluralsight’s Curriculum team. Each lab is then enhanced by our Content team, who configure the environments, refine instructions, and conduct rigorous technical and quality reviews. The result is a collaboration between artificial intelligence and human expertise, where AI supports scale and efficiency, and Pluralsight experts ensure accuracy, relevance, and instructional quality, helping learners build practical skills with confidence.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight