Tracks
/
Java
Java
/
Exercises
/
Hello World
Hello World

Hello World

Tutorial Exercise

Introduction

โ€œHello, World!โ€ will get you writing some Java and familiarize yourself with the Exercism workflow. Completing it unlocks the rest of the Java Track.

Watch our "Introduction to Hello, World" video to get started ๐Ÿ‘‡

Instructions

The classical introductory exercise. Just say "Hello, World!".

"Hello, World!" is the traditional first program for beginning programming in a new language or environment.

The objectives are simple:

  • Modify the provided code so that it produces the string "Hello, World!".
  • Run the test suite and make sure that it succeeds.
  • Submit your solution and check it at the website.

If everything goes well, you will be ready to fetch your first real exercise.

Since this is your first Java exercise, we've included a detailed Tutorial that guides you through your solution. Check it out for tips and assistance!

Tutorial

Table of Contents

Introduction

Welcome to the first exercise on the Java track!

This document is a step-by-step guide to solving this exercise. The instructions should work equally well on Windows, macOS and Linux.

Even if you are already familiar with Java basics, stepping through this guide may be helpful as it will help you understand the output from the tool, Gradle, that we use to compile and test our code, as well as introduce some of the patterns common to all exercises in this track.

Exercise Structure

When you fetch a new Java exercise, you will receive:

  • one or more test files (always). These live in the src/test/java directory and define a set of tests that our solution must satisfy before we can safely declare that it is working.
  • one or more starter files (initially). If provided, these live in the src/main/java directory and define shells of the classes you will need in order to solve the current problem.

Solving "Hello, World!"

You can use our online editor to solve your solution and run the tests, but if you want to solve the problem and run tests locally check these links below:

Step 1: Fix the solution

Either working locally or using the online editor, you should find the following code:

String getGreeting() {
    return "Goodbye, Mars!";
}

The objective is to modify the provided code so it produces the text "Hello, World!" instead of "Goodbye, Mars!".

Step 2: Run the Tests

After making corrections and implementing your solution, run the tests again. You can run the tests using the online editor or locally on your machine:

  • To run the tests in the online editor, click the "Run Tests" button.
  • To run the tests locally, check Testing on the Java track If the tests fails, that's ok! See what the error message is telling you, change your code and test again, when your tests pass, move on to the next step.

Step 3: Submitting your first iteration

With a working solution that we've reviewed, we're ready to submit it to exercism.org. You can submit the solution using the online editor or locally using the Exercism CLI:

  • To submit the exercise locally, first install the exercism CLI if you haven't already and then submit the files of your solution, e.g:

    exercism submit <file location>
    
  • Replace <file location> with the relative location of your Greeter.java file, so if you are working in C:\exercism\java\hello-world then the command would be

    exercism submit .\src\main\java\Greeter.java
    
  • If you want to use the online editor to submit your solution, just click the "Submit" button!

For a closer look at submitting a solution locally:

Next steps

From here, there are a number of paths you can take.

Regardless of what you decide to do next, we sincerely hope you learn and enjoy being part of this community. If at any time you need assistance do not hesitate to ask for help.

Cheers!

Move on to the next exercise

There are many more exercises you can practice with. Grab the next one! (example for two-fer)

exercism download --exercise=two-fer --track=java

Become a mentor

The heart of Exercism are the conversations about coding practices. It's definitely fun to practice, but engaging with others both in their attempts and your own is how you get feedback. That feedback can help point out what you're doing well and where you might need to improve.

Some submissions will be nearly identical to yours, others will be completely different. Seeing both kinds can be instructive and interesting.

Mentors review submitted solutions for the track they've chosen to mentor to help users learn as much as possible.

To read more about mentoring, go to the following link.

Contribute to Exercism

The entire of Exercism is Open Source and is a labor of love for over 100 maintainers and many more contributors.

A starting point to jumping in and becoming a contributor can be found here.

Edit via GitHub The link opens in a new window or tab
Java Exercism

Ready to start Hello World?

Sign up to Exercism to learn and master Java with 25 concepts, 148 exercises, and real human mentoring, all for free.