How to run a highlighted code only in IntelliJ IDEA? Sometimes you don't need to run the whole file and wants to just run the some numbers of code. Are there any such choices in IntelliJ IDEA?
It's possible to evaluate arbitrary expressions (Run | Evaluate Expression):
To evaluate a code fragment, click the Code Fragment Mode button and fill in the Code Fragment text box.
You can also use the Scratches feature.
Since version 15 Java scratches are runnable.
Related
My IDE is IntelliJ and my laptop is Mac OS.
When I click Code -> Reformat Code, even if I am not highlighting any code, the whole file gets reformatted.
How to make it format nothing if no code is highlighted?
Thank!
The behavior is expected, see corresponding help page:
If you don't want any of the code reformatted, do not invoke the Reformat Code action.
You can always undo the misfired reformatting with Meta+Z.
I'm switching from Sublime Text 3 to IntelliJ, I had a test.java file on my desktop that I used for small testing but now I am not able run the same in IntelliJ, the problem is it's not showing the file when I select run.
I tried experimenting with different projects created through IntelliJ and understand that I need to set Project to run the code, but again I don't see the file I want.
Here is the project selection screen
Here is what happens when I hit run
See this answer and this document.
You need to configure the content and source roots inside the Java module.
If you right click on test.java and click "Run 'test'", that will attempt to run your main class. Although you may have a NullPointer exception in your code. When you attempt to access a.get(0), the value will return null as there are no Integers in your ArrayList. Also generally class files are named with uppercase first characters. Hope this helps!
I'm tired of having to take time to reformat code after every statement. Call me lazy or call me spoiled, but every IDE I've used reformatted code automatically when I entered a semicolon.
I've been using intellij because eclipse and android studio have too many internal dependencies that cause problems. But it doesn't reformat code the way the other two do. Is there a plugin or method I could use to correct this?
I didn't tried by myself but the following could address the problem with automatic re-format:
activate the option "save file automatically if the application is
idle for..." option in IntelliJ Idea Settings
install and configure the save actions plugin
https://plugins.jetbrains.com/plugin/7642-save-actions
Regarding Eclipse (I didn't use it for a long time) wasn't automatic reformat of the code triggered on file save? You said you had in eclipse this support on entering a semicolon.
Kind regards.
Also try shift-ctrl-enter. This completes the line, adding semi-colon, closing brackets etc but as a side effect also reformats the line.
Problem
I am running a project using a tomcat configuration in IntelliJ.
The Evaluate Expression and Evaluate Code Fragment dialog is stuck in that I cannot type within the box. The break points work normally though.
This is the first time I am seeing this behavior.
Update
I noticed the focus is stuck on the project pane and sometimes a search for: box appears.
One way to comfortably use an IDE in an interactive language is to interact via the IDE in a command line environment. I am wondering if that is a possibility in Juno. In other words, is there a command line environment as in Matlab, to call functions, give initial values, and run expressions. If so what is the way to access it?
Note: There is a console window in Juno, but I can't find a way to insert my commands inside that.
Note: The question and this answer apply to the version of Juno that was based on LightTable. The current version is based on Atom and has an interactive console.
You can't enter commands into the console in Juno--that's for displaying output. Commands can be submitted from within the editor by setting your cursor in the line to submit and pressing Ctrl+Enter or Shift+Enter. The value will then be displayed in a small popup next to the line and the output will be printed to the console if you have the console visible.
Note that the inability to use the console as you desire is by design. See here for information about the console from the Juno docs.