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.
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.
Here is a set of prompts that you can use for students to make predications and then try in the Java playground.
4 + 5;
4.0 + 5.5;
4 - 5;
5.5 - 4.0;
3 * 5;
3.0 * 5.0;
4 / 2;
3 / 2;
4.0 / 2.0;
3.0 / 2.0;
4 % 2;
3 % 2;
7 % 4;
2 + 3 * 5;
(2 + 3) * 5;
(2 + 3) * (5 / 2);
2 + (3 * 5) / 2;
"Hello" + 5 + 2;
"Hello" + (5 + 2);
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!”