The Java Playground

Let’s hear from Crystal the Director, Java Education at Oracle.Sometimes you just want a tool that you can try a little code out in and see what it does. As you tweak and change it, you learn more and more about what it means and how it works. Students can also benefit from this explorative way to learn programming.

When I used to teach students the arithmetic operators - +, -, *, /, and % - I would provide them students with some code to try out. They were supposed to first predict the result of the code segment and then try it out on their computer. Most would get the addition and subtraction expressions correct, but when it came to integer division or modulus, the results weren't what they expected. This allowed them an opportunity to modify their code to see if they could figure out what the operator actually did or why it didn't behave as they originally expected.

The Java Playground is a great tool to use for this type of hands-on exploration.

There are two different ways that you can experience the tool. You can add an expression and run it with Detailed Output turned on, such as follows.

The Java Playground with Detailed Output

You can also put the output in a System.out.println statement as follows and not use the Detailed Output feature, as follows:

The Java Playground without Detailed Output.

The Java Playground without Detailed Output.

Here is a set of prompts that you can use for students to make predications and then try in the Java playground.

  1. 4 + 5;

  2. 4.0 + 5.5;

  3. 4 - 5;

  4. 5.5 - 4.0;

  5. 3 * 5;

  6. 3.0 * 5.0;

  7. 4 / 2;

  8. 3 / 2;

  9. 4.0 / 2.0;

  10. 3.0 / 2.0;

  11. 4 % 2;

  12. 3 % 2;

  13. 7 % 4;

  14. 2 + 3 * 5;

  15. (2 + 3) * 5;

  16. (2 + 3) * (5 / 2);

  17. 2 + (3 * 5) / 2;

  18. "Hello" + 5 + 2;

  19. "Hello" + (5 + 2);

  20. 5 + 2 + "Hello";

Here would be the results of entering these lines into the Java Playground.

Be sure to have a debrief with students to ensure that they really understand all of the arithmetic operators and how they work.

You can expand on this idea and create more experimentation for other content topics.

Enjoy!”

Steven Scott

We are twofifths design agency. We design logos, create unforgettable brands, design & build beautiful websites, and bring stories to life through animated motion graphics films.

http://www.twofifthsdesign.com
Next
Next

Mission Encodable