I use IntelliJ IDEA and was thinking about how nice it would be to be able to pop up a context where I could write, compile and run some simple core java code and then automatically dispose of the whole thing when I close the context.
Sometimes you just want to try simple something out, like a regular expression (I'm aware there's a regex tester plugin) or some series of bit-wise operations; for whatever reason its not always feasible to test directly within the project code and creating a whole new project is disruptive to the work flow.
So my question is this: what do other people use to try out their snippets of code?
We can type a short sequence, like psvm , and have IntelliJ IDEA generate things like the public static void main method. We can even create our own live templates for code snippets we commonly use. If we put the cursor inside the main method, we can run it by using ⌃⇧R, or Ctrl+Shift+F10 on Windows.
In IntelliJ IDEA, you can jump between test classes and production code. In the editor, place the caret at the test class or at the test subject in the source code and press Ctrl+Shift+T (Navigate | Test Subject or Navigate | Test).
Take into account IntelliJ Idea's (from version 14) Scratches:
Ctrl+Shift+Alt+Insert
and select typeYou can use jshell from any command line (or from the IntelliJ terminal).
View > Tool Windows > Terminal (Alt + F12)
Type jshell
:
user@xyz:~/IdeaProjects/prj$ jshell
| Welcome to JShell -- Version 9-ea
| For an introduction type: /help intro
jshell>
Enter your snippet (you don't need to add ;
at the end of the row)
jshell> Set.of("c", "b", "a").size()
$1 ==> 3
Exit from jshell
using one of the following approaches:
/exit
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