Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Projects are the central concept of developing in IntelliJ IDEA. Let's explore how to create them and navigate around.
Code
package com.teamtreehouse;
import java.util.Set;
import java.util.TreeSet;
public class Systemizer {
public static void main(String[] args) {
System.out.printf("This is the classpath: %s %n",
System.getProperty("java.class.path"));
Set<String> propNames = new TreeSet<String>(System.getProperties().stringPropertyNames());
for (String propertyName : propNames) {
System.out.printf("%s is %s %n",
propertyName,
System.getProperty(propertyName));
}
}
}
Helpful hints
- The default JDK installation is ...
- If you want to get the tips at any time choose Help > Tip of the day
Mac specific instructions
- If you want to use your function keys without pressing the
fn
key, simply check System Preferences > Keyboard > Use all F1, F2, etc. keys as standard function keys
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
All right, we got our IDE installed and
we're ready to start our first project.
0:00
Projects can be thought of as what we
were exploring each time we created a new
0:04
work space.
0:07
So for instance we would have started a
new project for our Pez dispenser, one for
0:09
our hangman game or one for
our karaoke machine and
0:12
what ever else we end up
creating in the future.
0:15
So let's dive in and explore how to
create projects in your new environment.
0:18
All right, so if it's not started up
already, go ahead and start up IntelliJ.
0:23
Then we'll click this Create New Project.
0:27
Here you'll see it's asking for
a Project SDK.
0:29
Now SDK remember stands for
software development kit.
0:34
So let's choose the JDK we installed.
0:37
Oh, it's not here, that's just common
the first time you start up IntelliJ,
0:40
the very first time.
0:44
After we do this we won't
need to do it again.
0:45
So, I'm gonna click new over here and
0:47
you'll see there's different types
of SDK's that are available, and
0:49
the one that we want is the JDK,
or the java development kit.
0:52
I'm gonna click that and of course this
is gonna look different if you're on
0:56
a different OS It's gonna try
to guess where it's at and
0:59
this on a Mac here will show what
the directory structure looks like.
1:03
So here we go, yeah this looks right
it's in the library it's the JAVA.
1:07
The one that I installed was JDK1.8.
1:09
You might have installed a later version,
okay, great.
1:12
So I'm gonna go head and
I'm just gonna click choose.
1:18
Because it was correct, and
there, sure enough there it is.
1:20
So now we have this project SDK here,
cool.
1:23
So let's click next.
1:26
All right, so
in this oddly laid out window here,
1:28
it's asking us if we wanna create
a new project from a template.
1:31
Now templates help by
creating common code for us.
1:35
For instance, the one template that
we have available here is called
1:37
the command line application.
1:41
Also known as the console applications
that we've been building.
1:43
So, what this will do is it will write
the boilerplate Java main method, and
1:46
let's go ahead and do that.
1:51
Let's choose that.
1:51
So, I'm gonna click this, and it
automatically chose that, and it says down
1:52
here, Simple Java application that
includes a class with the main method.
1:55
That's exactly what we want.
1:58
Great, so, let's choose that.
1:59
We'll click Next.
2:01
Okay, so let's name our project.
2:03
For this first one let's just recreate
that systemizer class that we wrote in
2:04
the work space earlier.
2:08
So, the name of this project
would be Systemizer, cool.
2:09
And see how it normally, it started
going ahead and typing along and
2:15
naming the folder the same as the project.
2:18
That'll help us find it later so
very similar on a Mac,
2:20
this is my home directory, and then
there's a folder called IdeaProjects.
2:23
And whatever I named
that is what it put here.
2:27
I could make this different, but that's
what I wanna have, I'm gonna leave it.
2:29
And the base package, remember this
is packages like we have been doing.
2:32
So, you take your URL and flip it around.
2:35
So we're com.teamtreehouse,
if you have a website and
2:38
you feel like putting it in there,
feel free to do so.
2:42
I'm gonna go ahead and click Finish and
that's gonna build everything out for us.
2:44
Okay, so these tips here, these are pretty
awesome, but they're a little overwhelming
2:50
and in your face, especially when
you're just getting started.
2:54
So what I'm gonna do is I'm gonna leave
this check box, Show Tips on Startup,
2:56
checked, but
I'm gonna go ahead and close them.
2:59
This is a great place to go,
and you can click Next Tip and
3:01
Previous Tip and kinda walk through and
learn things about your IDE here.
3:04
So I'm gonna go ahead and
close it for now though.
3:08
So before we get started I just wanted
to let you know that I have a plugin
3:10
installed that will show key
commands as I'm using them,
3:13
like keyboard shortcuts that I'm doing.
3:15
And it will show both Mac and Windows.
3:18
Now, the keyboards on Mac and
Windows machines,
3:20
if you don't know,
are a little bit different and
3:23
therefore the hotkeys that you do to
do things are a little bit different.
3:25
I just thought it'd be nice to show
on the screen what's going on.
3:28
You will not see those on your
screen don't worry about that.
3:31
So this area here is called the editor and
it's where we're going to do editing and
3:35
it works much like that editor
we were using in workspace, but
3:38
it is infinitely more powerful.
3:42
Now since Java's a strongly type language,
it knows things about what we're trying to
3:45
do, through a process
called code inspection.
3:49
Here, check this out.
3:52
I'm gonna start typing, and it's going to
take a stab about what I'm talking about.
3:52
This is called code completion.
3:57
So, I'm gonna type S, and look at that.
3:58
It popped up a list of what I
could probably be talking about.
4:01
So, I'm going to use the arrow keys and
I'm going to choose System,
4:04
because what I want to do here is I'm
going to write out to the screen.
4:08
Let's do System.out.println.
4:10
So, I'm gonna choose System, I moved using
the arrow keys and I'm gonna press dot.
4:12
And there it chose that and because
it knows what type of class this is,
4:18
it knows what the public fields are and
it also knows what all the methods are.
4:22
So you can see all the methods
that are available here.
4:26
So I'm gonna go ahead and choose out and
again I'm gonna press dot.
4:28
And because it knows what type out it is
it knows the different things that it
4:32
can do so, if we stroll down here we can
see that it has print, I can start typing
4:36
as well and it will go down on the list of
what's available and I wanna do println.
4:40
So that's great let's go ahead and
backup a bit I just want
4:45
to show you what would happen if we move
away so I'm gonna click my mouse away.
4:47
Now you'll see that it
highlighted in red and
4:51
see that little red squiggly line here?
4:53
Let's mouse over that and it says,
that it can not resolve symbol 'pr'.
4:54
And that also there's another error,
that it expected a semi colon.
5:00
Handy, right?
5:05
So I'm gonna to go back and
put my cursor right here and
5:06
if I wanted to get the code completion to
kick off again, I can press control space.
5:08
Give that a second.
5:14
The first time that this kicks
off it has to index everything.
5:15
So just give this one second and
it'll be quicker in a bit.
5:18
Again so we can choose println and
we'll say hello from our IDE.
5:21
Cool so I'm gonna go ahead and
save and I did that with Apple S and
5:29
because that's such
a common thing to do right.
5:35
If you're going to always be logging out
to the screen, there's a shortcut to it.
5:37
So if you type out S-O-U-T and actually
see there's some other ones on here.
5:42
But we're going to to S-O-U-T and
I'm going to press the tab key and
5:47
there's the System.out.println.
5:51
There, lots of savings there.
5:52
Okay so let's just go ahead and run this.
5:59
Now remember what we had to do in the past
was compile with the Java C program and
6:03
then run the program
with the Java command.
6:07
Well guess what,
this IDE knows how to do that.
6:09
To run this code let's go to the Run menu,
it's up here Run and chose run main.
6:12
Note next to this instruction here
there's a little keyboard shortcut here.
6:20
So it's saying on a Mac if
I do Ctrl + R it will run.
6:24
Now because we created this project
using the command line template
6:27
everything was already all set up for
us to just run this.
6:31
We'll see later how to
configure things this way but
6:34
because the template was using main it
automatically knows what that is so
6:36
let's go ahead and let's run this.
6:39
Okay so now things are being compiled and
6:41
it ran and here in this area
down here is our console.
6:46
If you mouse over you can see
the program that was actually run and
6:50
you can see here that it says JAVA and
6:53
then a bunch of parameters dropped
we'll explore that a little bit later.
6:55
So, you can see how the program ran.
6:59
I clicked in and I'm just going to
move my mouse, move my cursor over and
7:03
we could see that I called all
of these different properties.
7:08
Wow, right, and there it's at the class
path that was in the dash CP we did
7:11
before, so it got the class path also,
so I just wanted to show you that and
7:15
that's how it's running it off.
7:20
And here's our messages,
hello from our IDE and saving space.
7:21
Those are just the two
things that I wrote there.
7:23
Okay, so, let's go ahead,
I'm going to remove these two lines and
7:25
save again.
7:30
Okay, so let's go grab the code
that we wrote in workspace and
7:34
just plop in in here.
7:37
It's in the teacher's notes below.
7:38
So, I came over to my workspace and
I copied and I'm gonna come in here and
7:40
I'm just gonna paste.
7:44
All right, so
let's move the cursor over here where
7:48
it's highlighted in red,
this thing set here.
7:53
Let's see what it says.
7:58
It's saying that it doesn't
know what a set is, and
8:00
I remember we didn't import that.
8:02
So that's why it's saying that.
8:04
So let's go ahead, I'm gonna press, and
8:05
that key command there is Alt + Enter on a
Mac that's what it's suggesting that I do.
8:08
So I'm gonna go ahead,
I'm gonna press that, okay.
8:12
And here is the action that it's
suggesting is to import the class, so
8:16
let's go ahead and do that, cool.
8:19
And then it's doing it again for
the TreeSet, so I'm gonna do that again.
8:22
I'm gonna press Alt+Enter, and
it imported and if we scroll up,
8:25
you'll see that it did the imports for
us, pretty cool, right?
8:28
Huh, it looks like there's
still a problem so,
8:32
look here I haven't let's mouse over here.
8:36
It says class or interface on this one.
8:38
I think I have an extra brace so if I move
my cursor, see how it highlights this ones
8:40
highlighted and
that ones highlighted up there.
8:45
And then if I go to this one
that's closing the main class
8:47
then this is closing nothing.
8:50
So I have an extra brace, so
I'm gonna go ahead and get rid of that,
8:52
and now everything is happy.
8:55
There we go, so I'm gonna save that.
8:56
All right, so let's run that again.
8:59
So again, that was Ctrl+R or
Shift+F10 on Windows and Linux.
9:02
Cool, awesome, here it is.
9:12
It's a whole of different things.
9:14
Okay so now one more thing that I
wanted to show you really quick.
9:16
Let's say that we were looking at this
code that we wrote just a while ago, but
9:19
let's say that we forgot
what some of this was.
9:22
So, if I wanted to highlight over this,
and
9:24
I wanted to see what this said,
I could just press F1 for help.
9:26
So here it is about the getProperties and
9:31
it says that it returns the
java.util.Properties and I can click that.
9:33
And I can navigate just like we
did to the documentation, but
9:36
here it is, right in our code.
9:38
Wow, right?
9:41
What a powerful set of tools all ready,
and there are so
9:43
many more packed in there.
9:45
I think a handy way to view
this might be as a tool shed.
9:47
There are lots of powerful tools in
the tool shed that assist you in making
9:51
tons of cool things.
9:54
But they aren't used all the time.
9:55
I mean you don't use the jigsaw
every time you build something.
9:58
Sometimes you just need a sander but
10:01
when you do need that jigsaw
it's good to know it's there.
10:03
And like I mentioned, well, not all tool
sheds have the same tools in them, more or
10:07
less, the same tools are available
in every heavily used tool shed.
10:12
Eventually, every tool
shed owner buys a nail gun
10:16
just to stay competitive with
their neighbors tool shed.
10:19
I'm going to do my best at walking you
through each of these different tools
10:22
in your IDE tool shed.
10:26
But I'm sure we won't touch on all of it.
10:27
Feel free to explore, you'll not only
learn about what the idea is capable of,
10:29
but also some great Java
best practices as well.
10:34
And unlike the tool shed
analogy I just used,
10:37
you don't have to worry about
losing a finger if you mess up.
10:39
The help system at IntelliJ
is really great and
10:42
I wanna show you how to explore around.
10:45
If you find some killer tool that you
just love, share it in the forum.
10:47
This stuff can be super exciting,
and let's not let it overwhelm us.
10:50
Sound good?
10:54
I wanna show you how to deal
with multiple files and
10:55
importing other projects,
right after this next exercise.
10:57
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up