Getting started with IntelliJ IDEA

First up, I have created a tutorial on the IntelliJ IDEA Guide if you want to view the content with videos. I’ll concentrate on text-based for this blog post.

When someone new joins your team, it can be quite an overwhelming experience. There are lots of people to meet, new technologies to learn, different processes to learn and of course, an IDE to learn! It’s helpful to remember what every new starter wants – they want to make a difference, they want to add value, they want to move the needle.

I have created these tips and grouped them to help everyone who is new to IntelliJ IDEA learn in logical groups. You don’t need to know everything in the IDE to be a badass developer, but learning a bunch of functionality that will help you to go faster in 80% of cases is a great way to start. I’ve ordered these tips in the order you’re most likely to want to get to grips with them, but feel free to choose your own adventure!

Working together

There really is no substitute for sitting next to someone and pairing on something in the IDE; it’s a great way to learn a bunch of new keyboard shortcuts and see how your peers use the tool. However, the world was reshaped a few years ago, and now remote working is commonplace, which means you may not be co-located with your peers to benefit from this way of learning. This is where JetBrains Code With Me can add a lot of value, especially if you use it with the Presentation Assistant plugin loaded so you can see the host’s keyboard shortcuts. There are some licensing considerations to be aware of, but it’s available in IntelliJ IDEA Community edition for individual users of up to 3 users for 30 minutes for free.

You can watch these videos to learn more about Code With Me:

And read about it on the JetBrains blog:

…. and finally, the step in the IntelliJ IDEA Guide.

Learning the IDE

This one seems kinda obvious… of course, you want to Learn the IDE; that’s why you’re here! That said, you may not know about the Feature Trainer because it’s a relatively recent addition to the product. You can access the Feature Trainer from the home page by clicking on the Learn tab, or, if you’re already in a project, go to Help > Learn IDE Features.

The current lesson list is:

  • Onboarding tour
  • Essential
  • Editor basics
  • Code completion
  • Refactorings
  • Code assistance
  • Navigation
  • Run and debug
  • Git

Each of these has several lessons within it that take you through a feature that can help you in your workflow. Even not-so-new-starters can learn something from the Feature Trainer, so go ahead and check it out on a Friday afternoon when you have some headspace to learn something new.

…. and finally, the step in the IntelliJ IDEA Guide.

Customising your IntelliJ IDEA Environment

Since we spend a large portion of our day working inside the IDE, it’s reasonable to assume that we will want to customise it for our eyes. Of course, this is separate to code style, which should be standardised across the team you’re working with; that’s one advantage of checking in your `.idea` file. When you’re new to IntelliJ IDEA, the Preferences/Settings dialog (⌘, | Ctrl+Alt+S) can be quite daunting but you can search for what you’re looking for, such as “theme”, “keymap”, “plugins” or “font”.

…. and finally, the step in the IntelliJ IDEA Guide.

Navigating Code

One of the first tasks you have when you are getting to know a new codebase is how to move around it. Again there are lots of ways to do that in IntelliJ IDEA, but I’ve focused on the ones that I think are most helpful for new users. Of course, you can use the Project tool window to move around your files, but I recommend getting comfortable with both Recent Files (⌘E | Ctrl+E) and Recent Locations (⌘⇧E | Ctrl+Shift+E) as these can be thought of as your working context.

As you get more familiar with the structure of the codebase, I recommend you add Go To Declaration or Usages (⌘B | Ctrl+B) and Go to Implementation (⌘⌥B | Ctrl+Alt+B) to your repertoire.

Finally, as you start to figure out your workflow you may need to move between files in a sequential order; this is where (⌘[ | Ctrl+Alt+←) to go backwards and (⌘[ | Ctrl+Alt+→) to go forwards comes in.

…. and finally, the step in the IntelliJ IDEA Guide.

Finding Code

As you move from looking around the code to looking for specific code that performs a task, you can get a lot of support from your IDE. Search Everywhere (⇧⇧ | Shift+Shift)  and Find Action (⌘⇧A | Ctrl+Shift+A) are great ways to narrow down your search in the first instance. As you progress to more specific searching, I recommend you check out Structural Search by using either Search Everywhere or Find Action and typing in “structural”. You can then build your own queries as required. There’s an example in the link below for the IntelliJ IDEA Guide.

…. and finally, the step in the IntelliJ IDEA Guide.

Reading Code

As we all realise as we progress through our careers, we spend more time reading code then writing it. Maybe we wrote that code, or someone else wrote that code; either way you often need to understand what some code does.

Tools you can use to help you read code include Inlay Hints, which you can turn on and off in the Settings and Preferences (search for “inlay hints”). These decorate your code with annotations that can help you to understand the flow of data.

The scrollbars are another great source of information. Coloured blocks on the left-hand scroll bar show you if code has been added, deleted, changed or has an error in for the code you are currently viewing. The right-hand scrollbar shows you the same information for the whole file so you can see at a glance without scrolling if you have any errors and if everything is as you expect it to be.

Finally, sometimes you’re reading code because you’re fixing bugs. IntelliJ IDEA has an Inspections Widget, which appears at the top right of the file by default. This tells you the state of the file and if there are any errors. You can either click on it to open the Problems tool window, go to the next error directly with (F2 | F2).

…. and finally, the step in the IntelliJ IDEA Guide.

Understanding Code

When you come across a block of code that you don’t fully understand, you can use Context Actions (⌥⏎ | Alt+Enter) to see if IntelliJ IDEA has any suggestions for reshaping the code without changing what it does. This is worth doing even if there’s no highlighting on the code to indicate a potential refactor.

IntelliJ IDEA also allows you to Find the Type (⌃⇧P | Ctrl+Shift+P) which can be a helpful shortcut to remember, especially when you’re working with larger, more complex blocks of code.

Finally, you can analyse the flow of data through your code with Code > Analyze Code > Data Flow to Here and to analyse data flow downstream use Code > Analyze Code > Data Flow from Here. Using data flow analysis allows you to track both the data input (producer) and as the data output (consumer).

…. and finally, the step in the IntelliJ IDEA Guide.

Writing Code

Writing code is of course part of our day job and, again an area that IntelliJ IDEA can support you. As you’d expect from your IDE, IntelliJ IDEA gives you extensive code completion including Type-Based completion (⌃␣ | Ctrl+Space), which filters the list to only types that apply to that specific context. Support for code generation is extensive. You can use (⌘N | Alt+Ins) both in the Project tool window and in the editor to generate new files and common code constructs.

Similar to Search Everywhere, IntelliJ IDEA supports Running Anything (⌃⌃ | Ctrl+Ctrl) which you can use to run any of your Run Configurations as well as scripts and commands such as `mvn clean` or `gradle –status`.

Lastly, IntelliJ IDEA has recently made a number of changes to support you in managing dependencies. You can use the new Dependencies tool window to view and update your dependencies using the Package Search functionality.

…. and finally, the step in the IntelliJ IDEA Guide.

Changing Code

Changing code is one of those inevitabilities in our jobs. Perhaps we’re refactoring it, adding functionality or deleting it; either way, you will be changing some code you or someone else wrote at some point. Use (⌃T | Ctrl+Alt+Shift+T) to pop up the refactoring menu. Once you’ve refactored code, you can reformat the code with (⌥⌘L | Ctrl+Alt+L).

Maybe you want to make the same change in multiple places; IntelliJ IDEA allows you to create multiple carets either in a stacked list or randomly as required. ( | Ctrl) twice, holding it down the second time and then pressing the Down arrow to create a stack of carets or by clicking in your code to add a caret. You can learn more about this feature from this blog post on foojay.

Sometimes, especially with long blocks of code or poorly formatted code, it’s hard to see where scope starts and stops. You can use (⌥↑ | Ctrl+W) to expand the scope and (⌥↓ | Ctrl+Shift+W) to collapse the scope.

IntelliJ IDEA supports as many clipboards as you need meaning everything you copy inside IntelliJ IDEA is available for you to paste, even if it wasn’t the last thing you copied. One of my favourite features is being able to copy multiple things and then pasting them in one list from the Clipboard History (⌘⇧V | Ctrl+Shift+V).

Lastly, sometimes things go wrong, and it can seem like you’ve lost your work. IntelliJ IDEA takes snapshots of your code while you work (no save necessary!) when certain events happen. Those events might be refactoring a piece of code, a test passing or failing, or some other change you make. These changes are stored as your Local History. While it is not a substitute for a version control system such as Git, Local History can step in and help when things take an unexpected turn. You can access Local History from the right-click context menu both at the directory level in the Project tool window and on an individual file basis. The diff view it provides allows you to select which changes you’d like to restore to your file, or perhaps the whole file!

…. and finally, the step in the IntelliJ IDEA Guide.

Testing Code

Of course, you want to test your code! Perhaps you’re even doing TDD, but how can IntelliJ IDEA help you here? First up, you can split windows in the editor, allowing you to have your code on one side and your test on the other so you don’t have to flick between them. You can open any file from the Project tool window in a right split by holding down ( | Shift) when you press ( | Enter). The same tip works to open a file from the Recent Files dialog (⌘E | Ctrl+E).

Sometimes it’s helpful to jump from the file to its associated test if it has one. If you’re in a class and use Navigate to Test (⇧⌘T | Ctrl+Shift+T), IntelliJ IDEA will look for a test that it thinks tests that file. For example, if your class is called BlueMoon, IntelliJ IDEA might reasonably assume that a file called BlueMoonTest is in fact the test for that file and take you there. If you use Navigate to Test and IntelliJ IDEA can’t find a test class it will suggest creating a new one for you and offer to generate some test method code constructs.

…. and finally, the step in the IntelliJ IDEA Guide.

Seeing How Far You’ve Come

The Productivity Guide in IntelliJ IDEA is a fun way to see which shortcuts you have used and which you have yet to try. You can access it from Help > My Productivity. Check it out to see what you could learn next!

…. and finally, the step in the IntelliJ IDEA Guide.

 

Python you say?

In the spirit of trying to write more regular shorter blog posts I shall start with a small announcement! I am now doing some Python advocacy at JetBrains.

For all you Java folk, I’ll still be doing some Java advocacy, amplifying cool Java stuff on the socials and creating content, for example on the IntelliJ IDEA Guide. My Python journey is just beginning and I will share as much of it with you as possible. If you know of any awesome Python folk and resources in the community, I’d love to hear about them, please drop me a comment here or on the socials.

Starting a new challenge is always exciting, but I’m hopeful that with my passion for learning and sharing that journey to help others I can bring value to the community. I’m excited to work more with folk like Paul, Jodie and Benjamin, while still collaborating with other awesome developer advocates who amplify Java at JetBrains including, but not limited to, Marco, Marit and Mala. Fortunately, now I am working with Python I won’t need to change my name to something starting with “M”!

Five cool features in IntelliJ IDEA

Here are my top five cool features in IntelliJ IDEA. There are of course more than five, but that wouldn’t make a catchy blog title!

  • Management of JDKs
  • Code completion
  • On-demand error highlighting
  • Customization
  • Tight integration

#1 – Management of JDKs

IntelliJ IDEA does a fantastic job of managing your JDKs. You can download new JDKs and configure existing JDKs on your machine with IntelliJ IDEA. I created a tip for this on the IntelliJ IDEA Guide but the short version is – go to your Project Structure with ⌘; (macOS), or Ctrl+Alt+Shift+S (Windows/Linux), to view your Project Structure.

The SDK drop-down shows you all the JDKs that are configured for use with IntelliJ IDEA (assuming you’re using a Java project), then there is an option to Add SDK and finally, IntelliJ IDEA shows you a list of detected SDKs:

The top list outlined in orange is all the JDKs that I’ve configured for use with IntelliJ IDEA. The bottom list outlined in green is the detected SDK – that is all those on your machine that you’ve downloaded but are not yet being used by IntelliJ IDEA. The middle option, Add SDK, outlined in purple is where you can download a new JDK from different vendors to your machine by selecting Download JDK. You can also select JDK to browse to a JDK on your machine that exists but IntelliJ IDEA hasn’t detected. You can also download IntelliJ Platform Plugin SDKs and Android SDKs here.

When you select Download JDK you can choose your version and vendor and IntelliJ IDEA will download your chosen JDK and configure it with use with IntelliJ IDEA.

#2 – Code Completion

IntelliJ IDEA takes code completion to the next level. There’s Basic Completion, Advanced Completion, Live Templates, Postfix Completion, Statement Completion and more.

Here’s a whirlwind tour for you! Basic completion usually is available by default, but you can also invoke it with ⌃␣ (macOS), or Ctrl+Space (Windows/Linux). Smart completion or type-matching completion is similar to basic completion, but it only shows options for the current context. You can invoke smart completion with ⌃⇧␣ (macOS), or Ctrl+Shift+Space (Windows/Linux).

Live Templates are also a form of code completion that allow you to use abbreviations such as main that IntelliJ IDEA will convert to Java’s main method. There are dozens of live templates, and you can create your own!

Postfix completion is similar to live templates in some respects in that it also uses abbreviations but it helps you avoid backward caret jumps as you craft the code. It also allows you to manipulate existing code as you add the dot and then the abbreviation for the postfix completion you want to use, for example ifn for if null.

Finally, statement completion is one of my favourites because it adds the correct parentheses, braces, and semicolons to my code! The shortcut is ⇧⌘⏎ (macOS), Ctrl+Shift+Enter (Windows/Linux). This is just one you need to try out, granted three key presses is more than one semi-colon but it’s very helpful because it reduces errors in my code. I also find I can quickly use ⇧⏎ (macOS), or Shift+Enter (Windows/Linux) to create a new line – it’s just a syntactically pleasing combination!

#3 – On-Demand Error Highlighting

You can write code and see error highlighting in real-time in IntelliJ IDEA, no more waiting for the compiler; if your code isn’t going to compile, IntelliJ IDEA will tell you about it straight away. I prefer to fix errors as they happen, usually with Quick Intentions which is ⌥⏎ (macOS), Alt+Enter (Windows/Linux). IntelliJ IDEA helpfully gives you a little red light-bulb when there’s an error with your code:


  

Alternatively, you can use F2 to navigate to each error in your Project or use the Problems tool window which is ⌘6 (macOS), or Alt+6 (Windows/Linux) to get an overview of any problems across your project.

If you search the IntelliJ IDEA tip page for “quick intentions” it will give you a flavour of some of the ways it can help.

#4 – Customisation

I would be remiss if I didn’t mention how much I love being able to customise IntelliJ IDEA. Fortunately, it comes packed with sensible default options but equally allows you to customise these over time as you get more familiar with the product. Of course, I don’t use 95% of the customisations but the point is that I can and many people in the community do. That said, the 5% I do use makes my authoring experience a more enjoyable and productive one. The best way to get an idea of what IntelliJ IDEA is capable of in the customisation department is to go to your Settings/Preferences with ⌘, (macOS), or Ctrl+Alt+S (Windows/Linux). You can then browse and view the groupings on the left such as Appearance & Behavior and Editor. My favourites customisation are:

#5 – Tight Integration

I couldn’t come up with a better name for this one, but fundamentally it’s the integration part of the IDE. It’s easy to take this part for granted because IntelliJ IDEA makes it look easy, however integration with tools such as Git, Maven, Gradle, Docker and more in both IntelliJ IDEA Community Edition and IntelliJ IDEA Ultimate.

Having a one-stop shop for all your coding needs really is a productivity boost, plus there’s no more faffing about configuring external tools to work with your coding tool because it’s all neatly integrated!

New to Java? Some Resources

In this tweet, I was asked if I had a list of resources for developers who are new to Java. I didn’t at the time, but I’ve spent some time researching and here is that list.

I’ve listed content that is both free and paid. It’s not that one type is superior; it’s just to give you plenty of choices. These are the resources that I’ve used and do still use to re-learn Java. So, if you’re new to Java or looking to pick it up again after a break, this blog is for you.

The other super important point is that everyone learns differently; some like reading, some like doing, some like watching, most of us like a bit of a mix of everything. I tend to switch between them depending on what I want to learn about and how I feel. You’re probably similar, so pick an approach that works for you.

Learning Platforms

Let’s start with learning platforms. There are plenty of them to choose from, so you can pick one that works for your learning and budget style.

JetBrains Academy is a reasonably new learning platform that I’ve been using to skill back up on Java. I’ve used it in conjunction with other learning materials. I like the mix of theory with practice tasks. Of course, the slick integration with IntelliJ IDEA is a bonus too.

I’ve also used Udemy in my Java learning travels. There is a wealth of content available here, and you can sample most of it before you buy.

Finally, I’ve played around with codewars. This is a nice gentle introduction to katas (more on them soon), irrespective of where you are on your coding journey. It’s less structured than either JetBrains Academy or Udemy and can provide some light coding respite when the mood takes you.

Communities

The Java community is a rich, vibrant and welcoming place. This is played out in the communities that have sprung up around it.

The Virtual JUG is what it sounds like; a virtual Java User Group that hosts talks and shares knowledge. They have a Slack and Meetup space, so you can hear great speakers, speak yourself and learn from your peers.

Since I’m based in the UK I also want to give a shout out to the London Java Community and the Manchester Java Community. They are both great resources of information and supportive communities. I fully expect that this is mirrored in other Java User Groups worldwide, so I recommend you find your nearest one (or set one up(!)) and get involved. Talking of getting involved, creating content is an excellent way to do that.

The Java Specialists is another active group run by @heinzkabutz. Heinz also has a newsletter that I recommend you take a look at.

The Code Ranch is a very friendly place for newcomers to Java where you can post questions, learn from others and try out coding questions. The forum is also really active (oh, and did I mention that everyone here is super lovely?).

Code Katas

I am a relative newcomer to code katas, but I really like them as a way of learning. They are self-contained mini-puzzles that you can solve at your leisure.

@TheDonRaab does a great job of keeping these updated for Eclipse Collections: https://github.com/eclipse/eclipse-collections-kata

@CGuntur has also created these Java Katas for you with really nice instructions and updates: https://github.com/c-guntur/java-katas

I’ve not started these yet, but I like the look of them because the tests are right there to look at.

Specific Java Resources (including Frameworks)

This is a bit of a catch-all section, but there are a few resources that I’ve come across that are amazingly useful; they are listed here.

This course from @techgirl1908 was one of the very first resources I used on my journey to familiarise myself with the last 20 years of Java. I found it to be well-paced, gentle and incredibly useful.

@marcobehler has created a lot of content around Java, and specifically, Spring. This blog, and this Spring course, it is a bit like an onion. It starts with life before Spring and builds up the complexities so that you feel like a wizard when using Spring (and subsequently Spring Boot) and understand how the magic is being done and why. I feel like there’s a spring onion pun there, but I’ll move swiftly on.

There is a wealth of Java information on the Baeldung site. I don’t have one specific blog to point to, but invariably when I’ve Googled Java something there is a blog on this site that explains how to do it. It always amazes me just how rich this content is in terms of quantity and quality (many authors contribute to it).

One more thing I do want to mention is the official Oracle documentation for Java. I say this because you don’t have to store the Java language in your head. There is no shame in looking stuff up (another reason why technical interviews are so broken). Spend your time on the artistic side of learning to code, not remembering stuff that is one Google search away. Sure, you’ll learn more in time, but it doesn’t need to be your priority when you are starting your Java journey.

Of course, there are plenty of dedicated Java blogs out there, which you can find with a quick Google, but I want to keep this list of resources specifically targeted at content that newcomers might find helpful and that I’ve used.

Books

I like books; arguably, I like them more than videos. As with all other resources I’ve listed here, there is no shortage of them. These are the ones that I specifically have found helpful.

Head First Java by Kathy Sierra and Bert Bates. Yes, this book is old on the scale of Java, but it’s still very, very good and will probably appeal to your brain’s way of learning. I started with this book, and I didn’t regret it.

97 Things Every Java Programmer Should Know. Am I including this because I work with @trisha_gee, no, I am including this because I got a lot of value from it. I liked the vast range of topics that I could dip in and out of it very quickly because all the content is standalone. Many very experienced Java professionals contributed to this, so in my mind, they are worth listening to!

Effective Java by Joshua Bloch this isn’t the book that you start with, but it’s a book with a relatively low barrier to entry, and a book that I got a lot of value from (and probably need to re-read now I have more knowledge).

Head First Design Patterns 2nd Edition. This book is so fresh off the printing line that the ink is likely still wet. I’m going to come clean and say that I don’t own this yet, but I plan to own it very soon. I do own the first edition, and it was excellent. I fully expect the second edition to be just as good, if not better. Design pattern knowledge and understanding will serve you well, no matter what your coding goals are.

Java Certification

A note about Java Oracle Certification: this tends to be one of those subjects that can polarise opinion. I think certification is very valuable for a deep understanding of the Java language, and it will serve you well if you want to study and obtain it. I don’t think you need to be certified as such, and I suspect that on the job knowledge of Java will provide you with an equally rich and diverse experience of the language, albeit from a different angle. It’s entirely up to you, but here are my recommendations for resources if you want to pursue Java certification.

There are excellent books available from Jeanne Boyarsky and Scott Selikoff. I haven’t taken the exam, but I have found the books very useful and the examples informative.

My colleague Mala Gupta is also a passionate advocate of Java Certifications and her book for Java SE 11 is in preview so that you can get your eyes on it already!

Goals, Learning Styles and Time

Irrespective of if you’re new to coding, new to Java specifically, or took a break from Java, this is a list of resources that will help you get up and running quickly. I suggest you find the ones that work for you and build your list. Invariably what works for one person might not work for the next, so feel free to explore the wealth of content out there. Your learning style will also play a part, as will the amount of time you have available.

Whatever you do, enjoy the journey and remember what your goals are. Never lose sight of the why; that’s what will get you to where you want to be.