Tracks
/
Java
Java
/
Exercises
/
Hello World
Hello World

Hello World

Tutorial Exercise
“Hello, World!” will get you writing some Java and familiarise yourself with the Exercism workflow. Completing it unlocks the rest of the Java Track.

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:

  • Write a function that returns 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!

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.

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.

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:

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!".

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.

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:

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

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!

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

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

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 and to sign up see: http://mentoring.exercism.io/.

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 can be found here:

https://github.com/exercism/docs/tree/main/building

Last updated 23 November 2022
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 17 concepts, 130 exercises, and real human mentoring, all for free.