Learn how to create a simple project to configure IntelliJ.
- [Narrator] And we've now got IntelliJ started and ready for us to use. So if you're a MAC user, I hope you're also following along and we can pick up at this point. So we're going to create a new project. We're just going to create a Java Hello, World! type project to start us off. So for now don't tick any of the boxes in here. We're just creating a new Java project. We do need to choose the SDK. Now if like me, there's not one selected in your dropdown we need to click on New and then you need to navigate to where Java is installed on your machine.
So for me, that's in C:\Program Files and Java. And then you want to pick the JDK folder. So for me, that's this one here. I'm using Java 8 here, and make sure it's the JDK, not a JRE that you're picking and click on OK and we should then be ready to continue. So we can click on Next. And I don't want to create a project from a template. Just click on Next again. And we need to give the project a name. Let's let's call this HelloWorld.
And you can save it wherever you like. So by default it's saving it in a folder under my name called IDEAProjects. That's absolutely fine for me. We'll click on Finish and at this point IntelliJ will start. I don't want to see tips on startup but leave that ticked if you want to. And we're ready to start. Now, unlike Eclipse, IntelliJ looks very different and the first thing to point out is that it's actually still installing itself and starting up.
You can see a little sort of progress bar here. We need to wait to that to get to the end before you really start to do anything. And as you can see now it's got to the end and we've got another window pop-up here. And we can expand this HelloWorld folder and in there is an SRC folder and that's where our project files are going to go. Now if you are an Eclipse user I want to just point out to you the website I've got on-screen here. Which is a page from the IntelliJ IDEA website which will tell you some of the differences between working with Eclipse or indeed some of the other IDEA's you might have used and IntelliJ.
I will just point out a couple of them which are I hope enough to get you started. Most things are quite intuitive and will work like you expect them to. The key difference is that the shortcuts, the keyboard shortcuts, are quite different. You will need to look these up if you like to use keyboard shortcuts rather than clicking with your mouse on the menu. A couple of the key differences then. The first thing is there is no Save button. If I click on the File menu there's no option here to save the files that you're working with.
There is a Save All but you have no individual save on a file. Now, the reason for that is that IntelliJ saves as you go for you. So you don't need to do it. The next difference is that Eclipse will compile and build your project as you save files. IntelliJ won't build automatically for you. You need to tell it to compile it or build. Unless you tell IntelliJ to build automatically. I like to tell IntelliJ to build automatically for another reason which is that if you've got an error in your code there's an equivalent to the Problems Window in Eclipse.
A list of the faults, but you don't see that unless Build Automatically is switched on. In order to set that, you need to click on File and then Settings. You want to go to the Build Execution Deployment section and expand that. Then click on Compiler and tick this box here that says Build project automatically. Go to click Apply there. You may need to check that when you start a new project, that that has been ticked for you. I've found in some versions of IntelliJ it remembers it, in others it seems to be project specific.
So, do always check that whenever you create a new project. Okay, well let's create our Hello, World! Application cause there'll be the opportunity both to check that it's working but also we can see some of the other differences in using IntelliJ. We'll start by creating a new Java Class. We'll right-click on the SRC folder and do New Java Class. We'll give this class a name, I'm going to call it Main. Well this looks like a standard Java Class here. Let's create a public static void main class with an array of strings called args.
Well here's the first thing you might notice, if you make a mistake so that the code can't compile and I've missed out the letter g on the end of string. Then IntelliJ highlights it in red rather than the squiggly underline you might be used to seeing in Eclipse. We'll just correct that. Now we can type in our System.out.print line. You can see we're being offered a suggestions for what we might need here just like Eclipse does. In fact if you're half way through and you want to get the IntelliJ to complete this for you, you'd press Ctrl + Space or Command + Space just like you would do in Eclipse but then you need to press Enter to finish it off.
Actually I wanted print line there. Let's put in Hello World. Okay so, that hopefully looks okay. You'll notice we get occasionally this sort of light bulb appear. If you click on the light bulb, it makes suggestions for what you might want to do here. If you choose one of those suggestions it will alter your code for you. Those suggestions don't make much sense but we will see some of those later on. Let's run this project. Now, because this is a runnable class we get these little green arrows appear.
Either way there is a valid entry point or in fact because this is Java at the top of the class. I'm going to click on this green arrow here to say it's the main method that we want to run. Choose Run there from the menu. And here's our console window and we've got the words Hello World printed out. Once we've run our project for the first time we can repeat that run by clicking on the green button up here, the Run Main here. That will run again. I'm just pointing that out because, of course, if you've got a different class visible on screen but you want to run the Main Class you'd be able to do that by clicking on this green button.
I just want to mention two quick keyboard shortcuts before we finish this video. If you want to alter the indents in your application then you want to highlight it with Ctrl + A and to do the indent it's Ctrl + Alt + I or Command + Alt + I on a Mac. In Eclipse I think it's Ctrl + I, in IntelliJ it's Ctrl + Alt + I. For your imports, if you want to optimize your imports, it's Ctrl + Alt + O, not Ctrl + O.
Okay, well that should be enough. I think we're ready to start with Kotlin. We're going to be doing that in the next chapter. So when you're ready, I'll see you there.
- Creating a new Kotlin project
- Working with strings
- Data types in Kotlin
- Creating and calling top-level functions
- Creating classes
- Throwing exceptions
- Class inheritance
- Java interoperability
- Functional programming
- Using JUnit with Kotlin