edit
Since Java 9 there’s JShell
Original answer follows
You can also use Groovy Console. It is an interactive console where you can do what you want. Since Groovy also includes classes from the core java platform, you’ll be able to use those classes as well.
It looks like this: