[program-java] Re: To Jim C About Eclipse Tutorial

  • From: "Homme, James" <james.homme@xxxxxxxxxxxx>
  • To: "program-java@xxxxxxxxxxxxx" <program-java@xxxxxxxxxxxxx>
  • Date: Tue, 10 May 2011 16:48:17 -0400

Hi Jim C,
Here is the page that's going up in a few minutes. I'll get the URL for you 
when I get there for the start of the tutorial. See below my name.

Jim

As Tradition Would Have It

That's right. We're going to do the Hello world program in Eclipse. Mainly 
we're going to do that so that we can talk about what Eclipse can do for us at 
least a little bit, and we can get a little deeper into the environment we're 
beginning to work with.

Here's what we will do.

Create our first Java project.

Create our first Java source file.

Take a brief look at Eclipse views.

Let Eclipse generate come comments.

Let Eclipse complete some code.

Look at our output.

Review the keystrokes we used to access Eclipse features.

For little programs like Hello world, Eclipse is a bit like using a bull dozer 
to plant a geranium in a flowerpot. It's built for big projects, so it wants to 
force us to build one, even if we're just building a little program.

If you haven't started Eclipse, do that now.

I'm assuming that you told Eclipse where you want to keep your Java files, so 
you shouldn't see the dialog that asks you that question.

Once Eclipse is up and running, the Welcome screen displays. At the bottom of 
the screen is a link that says "Go to the workbench." Press Enter on that link.

If you now read the title of the window, it will say Java - Eclipse.

To start a new Java project, hit Alt+Control+N. This puts you in a menu of the 
kinds of new things you can create. The first one you land on is Java Project. 
That's what we want to create, but go ahead and look through the menu. I'll 
wait.


Choose Java Project.

Let's talk about the controls in the dialog that comes up.

Eclipse uses the F1 key to get help on what you are doing at the time, so 
before we fill out the dialog, go ahead and hit F1 and listen to what Eclipse 
tells you without navigating.

Now go ahead and tab around, but don't press Enter on any of the links you land 
on. I want to show you something and talk about what's going on here.

Once you tab past the links, You get back around to the Project Name control. 
If you keep tabbing, you get back to the set of help links. Before you hit F1, 
those links weren't part of the New Project dialog, but now they are.

OK, so if you click on the Java Project Wizard link, you get a help screen that 
talks about the various controls in the dialog we're working with. Go ahead and 
read that part of the help as if it were a web page. You are looking at a web 
browser control from inside Eclipse. This is one of the native controls it can 
generate.

When you are finished reading about the wizard, you can get back to the fields 
of the dialog with the Tab key.

Get back to the Project Name control. Give your project a name. I'm going to 
call my project hello. That's hello in lowercase.

I'm going to use the default location, which is the workspace I set up when I 
first installed and started Eclipse.

I'm leaving the JRE (Java Runtime Environment) setting as is.

I'm going to allow Eclipse to create separate folders for source and class 
files.

I'm leaving the add project to work sets checkbox unchecked for this first 
project. This allows you to shorten the list of projects with work sets, which 
are groups of projects.

I'm pressing the Next button.

Now tab around to see the settings in this next dialog, but don't change 
anything.

Press the Finish button.

When you press Finish, you land on a toolbar.

Tab around until you get to a tree view control.

In my case, I'm on a control that says "Hello," and that control is closed.

Let's open up the project and see what got created. To do that, hit Right Arrow.

One line down from the item that says closed is something that says "src." 
That's where the source files for your programs for the project will go when 
you create them. This is the folder you allowed Eclipse to create when you told 
it that you wanted it to put source files and class files in separate folders. 
In our case, we're only going to have one little program.

Now look down. This next item we won't mess with. Go ahead and check it out.


Now, let's go ahead and get our first program into the Java editor. Once we do 
that, we can get a look at this tree structure again, because once we have our 
program created, this tree will change to reflect the name of our program and 
any methods. Our program will only have one: the main method.

In Java, every public class has to be in its own separate file. Our application 
consists of one public class, so we'll make a file and put the code in it.

Go ahead and press Alt+Shift+N again.

This time, when the menu comes up, you can hit the letter c for Class.

This brings up the New Java Class dialog.

The first control we land on is Name.

By convention, Java classes must begin with an upper case letter. I'm going to 
call my class Hello with a capital H.

The next thing you land on after you have created the class name and pressed 
Tab is a set of radio buttons. Leave Public selected.

Leave the next two controls unchecked.

Tab around until you see a check box that says "public static void main(String 
[args])."

Check this box.

This box will cause the code for the main method, which is the start of any 
Java file that can run to appear in the Java editor. Any public class can be 
the starting point for a Java application if it contains a main method. Our 
program is going to contain a main method and one statement.

Uncheck the box that says "Inherited abstract methods."

Check the box that says "Generate comments."

Press the Finish button.

The next thing that happens is that focus lands briefly in the tree of items in 
your project on the name of your class, then the editor opens and your cursor 
lands on the first line of the program, which happens to be a JavaDoc comment. 
A JavaDoc comment is a special comment that the Java documentation tools, which 
are part of the Java Development Kit that you downloaded and that Eclipse found 
when you ran it for the first time, uses to create documentation about your 
Java programs. When you look at all the stuff that comes with Java, you are 
looking at comments that were turned into HTML files, that came from the 
content that someone wrote inside these comments.

JavaDoc comments start with /** and end with */. So arrow down to right below 
the line that says */.

You land on the line that contains the name of the class. the left brace at the 
end of that line marks the beginning of the class.

Move down past another JavaDoc comment.

The line you land on after that is the one that you saw in the check box in the 
New Class dialog. This is the header for the main method.

Right below that line is what's called a single line comment. You can tell that 
it is a single line comment because it starts with two slashes.

Note that JavaDoc comments can cover more than one line, while single line 
comments end at the end of the current line. You can either use single line 
comments on a line by themselves, or on the end of a line after some Java code. 
Java can also have C-style multiple line comments. They start with /* and end 
with */.

The comment Eclipse put in serves two purposes. It tells the Eclipse task 
manager that you need to put something here in this method, which is now empty, 
and it tells you what is going on.

Keep moving down. You'll see the right brace that marks the end of the main 
method, and another right brace that marks the end of the Java class you just 
generated.

To summarize the code of your program, here's what we have.

Excluding comments, we have a class called Hello that begins inside a left 
brace and ends with a right brace.

Inside the class called Hello, we have a method called main which starts with a 
left brace and ends with a right brace.

Right now, the method called main has no code. Therefore, your program does 
nothing. It's a legal program, but it does nothing. Next, we'll make it do 
something.

You have to put your code between the inner set of braces. The inner set starts 
right after the name of the main method and ends below the comment.

Now, follow this next set of directions carefully.

Type the word system beginning with a capital S at the beginning of a line and 
with no spaces, type a period. What I'm talking about should look like this.

System.

At this point, press the Tab key.

You hear a dialog come up. You are on a line that talks about the System class. 
The greater sign indicates that the class contains stuff.

Move your arrow keys down and check out what is included for a little while.

You are exploring a Java class that is part of what you get with the Java 
Development Kit.

Scroll down until it says "out."

At this point, if you hit the Tab key, you can get some help on what you are 
looking at in the list of items.

Once you have looked at the help text, you can use Escape to get back to the 
list.

Once you have out selected on the list and press Enter, the code in the editor 
will change to reflect what you have picked from the list.

Now, make sure that the cursor is at the end of the word "out" and press Tab 
again.

Scroll down to the line that contains the word println and press Enter.

Now read the line that appeared in the editor.

Note that inside the parentheses there is an x.

Move onto the x and delete it.

Your cursor will now be on the right parenthesis.

Type one double quote.

Now read the word, and you will hear it say quote quote.

Your cursor is now on the right most double quote. You have created an empty 
string.

Eclipse put in the closing quote for you.

Type the words Hello world followed by an exclamation point into the quotes.

Your program will write whatever is in quotes to the screen when you run it.

Move to the end of the line and make sure the last thing on the line is a 
semicolon.

This line is now a Java statement.

Congratulations. You have just made your first Java program. It prints that 
traditional Hello world! message to the screen.

Press Control + F11 to run it. Hopefully, you won't have introduced any 
compiler errors. If you have, we'll get to how to fix them in a second.

For those of you who put in a perfect program, let's check out the output. It 
didn't appear on the screen the way it would if you would have run this program 
from the command line, but Eclipse did run your program, and you can look at 
the output in something called the Console view.

You can get to the Console view by pressing Alt+Shift+Q, followed by the letter 
C.

Now that the cursor is in the console view, you can re-run the program with 
Control+F11. This time, since you're in the Console view, you hear the output 
come to the screen. If you move your cursor up, you can examine it.

At this point, you have about eight views in the workbench. You can switch 
among them with Control+Shift+F7, but you have to be a little tricky about 
looking at them all. You have to hold down Control+Shift, Press F7, then tap 
the Control key and let all the keys go. At this point, if you luck out, you 
can move up and down and see the names of the views. One will be the editor, 
which is where your program is. Another will be the Console view, which holds 
the output of your program. Still another will be something called the Package 
Explorer. This is the name of the tree structure I talked about back at the 
beginning of this lesson which reflected the src folder, and which changed to 
reflect the name of your program.


Finally, let's introduce an error into the program and see how to look at what 
it is and fix it.

go to the end of the line that contains the statement and delete the semicolon.

Now press Control + F11 to run the program.

In my case, a dialog comes up and tells me that there are errors, and asks me 
if I want to continue anyway. I press Continue.

To look at errors, one thing you can do is hit Alt+Control+q, followed by X. 
The way I remember it is that X crosses things out, so you want to X out the 
errors in your program, but maybe your mind doesn't work like mine does.

OK, so we get an error screen. You can move down into a listing and when you 
press Enter, focus lands on the spot where Eclipse thinks the error is. Go 
ahead and fix the error.

We are done for today. The next page is a review of key strokes we've learned 
so far.

From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Tuesday, May 10, 2011 1:47 PM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Re: To Jim C About Eclipse Tutorial

Jim H.

What is the actual link to this?

Jim

________________________________
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Homme, James
Sent: May 10, 2011 10:56
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] To Jim C About Eclipse Tutorial
Hi Jim C,
I just want you to know that the tutorial that you wrote in which you go from 
the beginning of Eclipse to building a little MVC application is extremely 
good. My tutorial is going to have that outline, but be a lot more wordy. I'm 
getting ready for a class, so I might be slow to get the next material  on the 
site. The next page is going up today. I just wanted to clarify how to look at 
syntax errors, so that it was accurate.

Jim

Jim Homme,
Usability Services,
Phone: 412-544-1810.


________________________________
This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.

Other related posts: