Interested in sponsoring the site? [find out more]
How to Diff Java Code in IntelliJ - 3 ways to use the Compare Tool
TL;DR IntelliJ has an inbuilt diff tool which you can use to compare files, classes or code with the clipboard. Just right click and choose Compare.
I was busy refactoring code in RestMud this morning because I want to try and open source the basic game engine, and then later the Web/REST API, but I want to tidy up the code a little first.
I’ve been working through the code:
- moving classes into new packages
- splitting classes to make code clearer and easier to manage
- new classes make code easier to test
And the more I tidy it up in general, the easier it is to spot smaller problems of code duplication.
How to fix IntelliJ issues by looking in the IntelliJ log
TLDR; View the IntelliJ log Help -> ‘Show Log in Explorer’
I experienced an issue when importing maven projects.
I found the answer to my problem on StackOverflow:
stackoverflow.com/questions/26754344 “…set Settings > Build, Execution, Deployment > Build Tools > Maven > Importing > JDK for Importer to Use JAVA_HOME…”
The above solution worked for me. But it made me realise that it is harder than it needs to be to find what is going wrong with IntelliJ if you don’t know one trick - how to view the logs with IntelliJ.
How to convert a breakpoint into a conditional breakpoint in IntelliJ
TLDR; right click on a breakpoint and add code that returns a boolean to make it a conditional breakpoint
Breakpoints are great. You find the section of code that you want to investigate. Click on the side of the screen to create a breakpoint. Run the code in debug and it stops where you want it.
But what if you only wanted to stop on that breakpoint sometimes.
What do you do?
FAQ: Why do I only see test that fail in IntelliJ and not the tests that pass?
When you run your tests in IntelliJ you may have seen an output where only the failing tests are shown in the run pane tree.
In the above run I have 302 passing tests, but only 1 failed.
Where are my failing tests?
All IDEs offer a massive amount of power and functionality sqeezed into a tiny GUI. So your going to miss things. And one thing people miss, and I’ve missed it too, is the “Hide Passed” icon.
Some Handy IntelliJ Code Completion Keyboard Short Cut Tips
There are plent of shortcut keys and approaches to writing code that IntelliJ will help with.