I was an interviewing a candidate for a Senior java position and he mentioned that they extensively use scala command prompt to debug Java programs. He said it was even possible to call a Java function directly from the scala command prompt.
I have never used scala so I was unable to verify his comments. It might be possible because both of them run on the JVM itself.
A quick google search doesn't give any pointers to this.
Is it really possible to debug Java functions from scala. Can someone give me pointers to the same.
Thanks in advance.
Yes you can, though you would have to use scala syntax:
:: ~ » scala
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val x = new java.io.File("/tmp/foo")
x: java.io.File = /tmp/foo
scala> x.length
res0: Long = 24777
Here I used scala REPL which is bundled with scala distribution, but in fact, you can use sbt (scala analog to maven) command so all project classes are instantly available on class path:
sbt
console
.... // using java code, just like any other jvm code
It is possible to use vanila REPL for the same purpose, but you will have to manually reconstruct classpath:
scala -classpath ...
And yes, as @Boris mentioned in the comments, IDEs (originally Eclipse, but now IDEA too) has it's own way of this feature -- build in, interactive worksheets (relevant plugins has to be installed):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With