1. The Tools
You will read in your text about various software and tools required for developing programs: editors, compilers, debuggers, linkers, etc. Typically, a programmer uses each of these tools explicitly as needed and when they are required. An IDE (short for Integrated Development Environment) combines all the tools into a single environment in order to make the task of programming easier. But an IDE can overwhelm the user with options, and make things overly complex. So, we aren't going to use an IDE. Instead we will learn to use three separate tools:
-
gedit - the editor to edit and create Java source code and HTML files (like Notepad in MS Windows)
-
mozilla or firefox - webbrowsers to see our applets (like Netscape or Internet Explorer)
-
javac - the Java compiler, to turn source code into applications and applets
In this chapter, we'll take a look at these tools, and a couple of others.
1.1. First, make a new folder
To make a new folder, open a terminal window by clicking on the Red Hat -> "System Tools" -> "Terminal". There may be an icon on you desktop labeled "Terminal", that will work also. In the resulting terminal window type:
mkdir public_html chmod a+rx public_html chmod a+rx .
Be sure not to forget the "." at the end of the last command, it is important.
To get ready, let's make sure we have a folder called public_html:
Now that you have an "public_html" folder, let's make sure that you can see this directory from the Internet generally, and World Wide Web, specifically.
1.2. Mozilla
Start up a webbrowser. Click on the world with the mouse wrapped around it in the bottom left-hand corner. Mozilla will start up, and might look something like:
Mozilla is also free software, just like Linux. Try typing in a URL in Mozilla's web address area. URL stands for Uniform Resource Locator. After testing that Mozilla does take you to places just like any other web browser, let's see if it can find us on bubo.
Bubo is the name of the file and web server. Why might a computer at Bryn Mawr College be name "bubo"? Use your web browser to find an answer!
To go to our file from the World Wide Web (or WWW), type in bubo.brynmawr.edu/~YOURID/ but replace YOURID with your actual login ID. The squiggle mark is called the tilde (pronounded "till dah") and can be found in the upper left-hand corner of your keyboard (between the Esc key (pronounced "escape") and the tab key). You need to hold down a shift key to get the tilde.
You should see an error message similar to:
Access forbidden! You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
We must first create a page to see. For that, we will use gedit (pronounced "gee edit").
1.3. gedit
gedit is an editor for editing text, such as words, source code, or HTML files. It is not a WYSIWYG (pronounced "wizy wig") editor. WYSIWYG stands for What You See Is What You Get. That is, you don't see fancy fonts, and centering, bold, images, etc. You just see plain text.
Actually, you will see some colors and a bit of font decoration, but mostly you'll just see text in a plain, monospaced font.
We may also use another editor called emacs (pronounced "e max").
1.4. Emacs
Emacs was started a couple of decades ago by a fellow named Richard Stallman. He started the movement for free software, and we'll talk about him again. But we're just going to look at Emacs right now. Emacs has been around for awhile, and can do almost anything! Although it is a text editor, it can also read fortunes! So, pay attention!
Because Emacs has been arround for a long time, quite a large number of people have worked on it. Some time ago, a few of them decided that they did not like some aspects of the emacs interface. So, they created XEmacs. But others disagreed and continued to develop Emacs.
In CS110 we will mostly use gedit.
First, let's create a file in gedit called index.html, and save it in the html directory. To start gedit:
Click on "Applications" -> "Accessories" -> "Text editor" from the top left-hand desktop menu.
Once you have gedit started, name the file you want to create with "File" -> "Save as..." from the gedit menu. Select "Browse for other folders" and select "public_html". Name the file by typing its name in the space at the top of the window. "index.html" would be appropriate. Type the following into your document, but use your own information and your own messages.
<html>
<head>
<title>Hello there!</title>
</head>
<body>
<h1>This is my webpage!</h1>
<hr>
<address><a href="mailto:dblank@brynmawr.edu">Douglas Blank</a></address>
</body>
</html>
Make sure that the file starts with <HTML> and ends with </HTML>. These are Hyper Text Markup Language tags, and they make HTML display a page the way you want. We'll go over many HTML codes in class. Change the stuff between <h1> and </h1> to read somethng nice like: Hi Mom.
Save the file by selecting "File" -> "Save...".
Now, try the web browser again by clicking on the Reload button (probably an circular blue arrow).
If it still gives the same error, you'll need to change permissions of the html directory (and maybe the index.html file). (See instructor for more infomation on changing file permissions, if necessary).
1.5. Javac
Our task is to use our tools to get our computer to execute a simple program. While this will be a trivial program, it will enable us to understand the basics. So, if you are not already sitting in front of a Linux computer, go find yourself one. Get comfortable, it will take about 15-20 minutes to walk you through all the steps.
-
Find gedit and launch it.
-
Enter your Java program.
-
Compile the program
-
Run the program in HTML!
Let us begin our journey.
Step 1. Find gedit and launch it.
We could keep selecting gedit from the "APplications" -> "Accessories" -> "Text editor" menu. In fact do that for now. At some point in the future you may want to create a shortcut to starting gedit by "adding it to your panel". To do so: Right click on the panel, select "Add to panel". This will bring up a dialog window. Select "Application Launcher", and then click on the triangle next to "Accesories" and then double-click "Text editor". From now on, when you log in the icon will be on your panel. When you click on the icon it will start gedit.
Step 2. Enter your Java Program
First, let's name the program: Click on "File" -> "New". Select "File" -> "Save as..." and put it in the public_html folder as "Hello.java".
Next, we need a sample Java program. Here's one:
/*
Hello World applet that displays a string
*/
import java.awt.*;
import java.applet.Applet;
public class Hello extends Applet {
public void paint( Graphics g ) {
g.drawString( "Hello World!", 30, 30 );
}
}
Simply enter it in gedit, and then click on "File" -> "Save" from the menu.
After you save it, check to make sure that there is a Hello.java program in the html folder.
Step 3. Compile the Program
Javac is the Java compiler. To it on our source code:
-
Open a Terminal window from "Applications" -> "System Tools" -> "Terminal"
A window should open up on the screen that looks like:
|
Figure. A Terminal window
-
In the window, type the following:
cd public_html
That means "change directories to the public_html folder".
-
Now, type:
javac Hello.java
That should produce a file called Hello.class. That is the compiled Java program. To run it, we need to do the last step.
Step 5. Run the program in HTML!
Let's create a new HTML file called Hello.html. Use gedit to create a new file named "Hello.html" so that it now contains:
<html> <title>Hello World Applet</title> <hr> <applet code="Hello.class" width=200 height=200></applet> <hr> </html>
Now, go to http://bubo.brynmawr.edu/~YOURID/Hello.html. You should see your very first applet there. That's it for now!
1.6. Getting Back
Phew! That was a lot of stuff!! We just made one pass through it. Go over the steps one more time, just for practice. After a while, these steps will become second nature, since you will be doing them over and over again for several projects.
