OUR NETWORK:TiVo Community TechLore Sling Community My DigitalEntertainer MyOpenRouter MediaSmart home See all... About UsAdvertiseContact Us

RoboDuke's School of Java - Lesson 1, Chapter 1

Welcome to my Java lessons! I am RoboDuke, the Javarian. I am an RS Media robot, programmable in Java. I am here to teach you the wonders of the Java programming language! We will be using the textbook Head First Java by Kathy Sierra and Bert Bates (Order from Amazon.com).

We will be utilizing two pieces of software. When we develop for programming me (won’t that be fun??) later in the lessons, we will be using a program called NetBeans (a free development tool for Java by Sun Microsystems). Instructions for downloading and installing the Netbeans software. NOTE: Microsoft Word 2003 or higher required.

BUT--- for new programmers (and I know that there are a number of you out there!!) the NetBeans IDE (integrated development environment) exposes too much information and can be confusing for "newbies" ---so we will utilize a simple yet very powerful Java IDE named Eclipse for our first lessons. This software requires NO INSTALLATION and can even be run off of a Flash drive.

Obtain two files, a zipped one which has the software and a reference document which has unzipping information and a tutorial for the use of Eclipse from the following locations:

Look at the second file and follow the instructions for unzipping the first one. It will be much easier for you if you would unzip the software directly to your C: drive (as indicated in the document). We will refer back to the rest of this second document as we progress in this lesson and get use to the environment and Java itself. Make certain as you go to refer back at the hints at the end for "How To" hints.

Eclipse is an open-source Java IDE originally created by IBM and now maintained by eclipse.org (great site to go to for information about this software). It is based on plug-ins and with the correct ones installed, you can do PHP, C++, Perl, JavaScript, and XHTML with it as well as have it contain your database, Web server, and Web application server. It is a great tool. However, we will concentrate on how to use it for client-side Java applications.

We will cover a lot of Java programming in these lessons. The goal is not to make you a complete Java programmer as much as to let you see a lot of code so you can alter it for your needs. Expect to read a LOT of Java code and to alter a LOT of Java code. My programs will be heavily laden with comments on the hows and whys.

Use your textbook as a reference only. Spend time really running and studying the examples I provide to understand why they do what they do. Although the textbook is important, you do not become a Java programmer by reading text!

Download the Lesson 1 JAR File

Watch the Adobe Connect Breeze movie to get introduced to the IDE and how to run Java programs (Popcorn required!). It is about fifteen minutes long.

Next, open up Eclipse. Write down the name of the folder where your workspace will be and click OK. After Eclipse comes up, import this jar file (see the movie information and the introduction document that you downloaded earlier for instructions on how to do this). FINALLY - we are ready to do some Java!!!!!! If you have problems, post your questions to the lesson forum. If you have code problems that you would like me to look at individually, send them to my sidekick, Diane, and she will make it top priority.

Inspect the Code

Double-click on the program named Comments. Look at the code. If you see "areas" of code folded up (as indicated with a + in front as shown here) make certain to open up the + to see the rest of the code.

Note the package name that must be the top line of the code. Double-click on the program name on the top tab to make the code full screen. Double-click on it again to make it normal sized. Run the Comments program. To run this program, single-click on this class name in the left Package Explorer. Then from the tool bar, choose Run > Run as > Java Application. The program will run and any Console output will show at the bottom of the screen in the Console view. Look at the output and note the associated code. The \n is a newline character which can be used to skip a line in the output.

Now go to the folder that you wrote down in the instructions at the top. Note that in the workspace, there was a folder created named lesson1 that has both Comments.java and Comments.class in it. The .java file is the source code and the .class file is the compiled code. See page 2-3 of your text for a description of this. Note that if you had a package named a.b.c, it would be in the workspace in a folder named "a" that has a folder in it named "b" that has a folder in it named "c" that has the java code in it. Therefore, the Windows folder structure mimics the Java package structure.

Java Overview

Let’s look at Java from 10,000 feet. Chapter 1 in your text is an overview and you are not expected to understand every detail---just to see some of the possibilities. All topics will be covered in deep detail later in the text.

Fill in the "Sharpen your Pencil" exercise on page 5. Check your answers on page 6. Then in Eclipse, run the program Page5.java. I have coded the examples (with some extra code to make them run) from this exercise. There is an auxiliary class needed (Dog.java) that we will look at in detail later in the lesson when we get to Chapter 2. See how much of it you can understand. You may have a lot of questions at this point ---but rest assured---we will get to them!

Look at pages 7-9 in your text. Note that our example Page5.java followed these rules.

But life would be boring if a program ran by finding the main method and having it run sequentially from top to bottom-then quit! How boring! I want to dance the same steps five times (loop) ---then lay down if I am tired (decision) --- but keep dancing if I am not (other choice in the decision). These are called constructs in a programming language.

Java Statements

There are three main constructs in any programming language. Looping (do something over and over), conditional statements (do something under certain conditions), and method calls (branch to a different location in the program-do something there ---and then come back to where you are). Now-that makes programming interesting!!

Java has all three types of constructs. Your book covers these on pages 10-14. Don’t worry if you do not understand all of these. We will revisit these in DETAIL in lesson3. Just try to get the general idea. But study the bullet points on page 12. It will save you some silly errors later.

Try it Yourself

See if you can type in the code on page 14 and get it to run (look back at our Eclipse user instructions for details on how to create a new class). The class you create must be named BeerSong (I could use one right now!) and will be saved as BeerSong.java.

Look at the PhraseOMatic.java program on page 16 (I have included it in our jar file). Run the program a few times and see what phrase is produced (note - the green button with the arrow on it can be used to rerun the last program that was executed). Read through the explanation of the code on page 17.

Hit the Books

Work through the exercises at the end of the chapter of the text.

BREAK TIME!! I am off to recharge my batteries so you run a few laps --- and we will be back for Chapter 2!!!

 


Back to Lesson Plan

Read More In: RS Media

Welcome to the Java Lessons of RoboDuke, the Javarian. I am RoboDuke, an RS Media robot made by WowWee and purchased at Java One in May, 2007 (more info). I currently reside at Virginia Western Community College in Roanoke, Virginia where I will be used to teach the wonders of Java Programming to students of all ages. Come follow along!


Add Your Reply

(will not be displayed)

Email me when comments are added to this thread

 
 

Please log in or register to participate in this community!

Log In

Remember

Not a member? Sign up!

Did you forget your password?

close this window
close this window