Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive interpreter for Java

Is there a good interactive interpreter for Java, similar to Scala's? When programming, I like to try small pieces of code to see if they work like I expect before plugging them in to my main program. I would prefer an interpreter that is not based online since I often work offline.

Thanks in advance!

like image 460
astay13 Avatar asked May 25 '11 03:05

astay13


2 Answers

Since Scala runs on a JVM, why not the Scala interpreter? That's what I do when I need to test a few Java-snippets.

It's nice to have tab completion that works.

scala> System.getPropert
getProperties   getProperty
scala> System.getProperty("user.home")
res0: String = c:\Users\robert

Ok, you have to know a bit about Scala syntax when you do stuff like:

scala> val testMap = new java.util.HashMap[String, java.util.List[String]]
testMap: java.util.HashMap[String,java.util.List[String]] = {}

scala> testMap.put("planets", java.util.Arrays.asList("Mars", "Jupiter", "Pluto"
))
res0: java.util.List[String] = null

scala> testMap.get("planets")
res1: java.util.List[String] = [Mars, Jupiter, Pluto]
like image 186
Robert F Avatar answered Oct 12 '22 08:10

Robert F


In the past I used beanshell. It was really light and got the job done. http://www.beanshell.org/

like image 35
Jake Dempsey Avatar answered Oct 12 '22 09:10

Jake Dempsey