SE450: Lecture 1 (Logistics/Tools/Introduction)

Contents [0/41]

Are You In The Right Room? [1/41]
Overview of Today's Class [2/41]
A Brief Introduction [3/41]
Contact Information [4/41]
Course Homepage [5/41]
Attendance [6/41]
Assessment [7/41]
Projects [8/41]
Textbooks [9/41]
Prerequisites [10/41]
Java Self-Assessment [11/41]
Expectations [12/41]
Tools [13/41]
IDEs [14/41]
Recommended Setup [15/41]
Tell Me About Yourself [16/41]
Course Overview [17/41]
Course Objectives [18/41]
The NEW SE450 [19/41]
The Position of SE450 in the Curriculum [20/41]
Software Engineering [21/41]
Object Oriented techniques [22/41]
Some important terms [23/41]
Objects vs. Classes [24/41]
Java Overview [25/41]
Java Tools Overview [26/41]
Java Features [27/41]
Example: Hello World [28/41]
Example: Hello World - in a package [29/41]
Java Applets [30/41]
Java Tools: general [31/41]
Java tools: general (cont.) [32/41]
Java Tools: javac [33/41]
Java Tools: java [34/41]
Java Tools: javadoc [35/41]
Java Tools: jar [36/41]
Java Tools: jdb [37/41]
Java Tools: javap [38/41]
Java Tools: appletviewer [39/41]
Homework [40/41]
Homework (continued) [41/41]

Are You In The Right Room? [1/41]

Course: SE450 (Object-Oriented Software Development)

Instructor: Matthew Wright

Overview of Today's Class [2/41]

Adminstrative information.

Overview of the course.

Principles of object oriented programming.

Java review and Homework #1 assignment.

A Brief Introduction [3/41]

What is this course about?

Contact Information [4/41]

Instructor:Matthew Wright
Home Page:http://www.depaul.edu/~mwright1
Email:mwright@cs.depaul.edu
Phone:1-773-399-7882
Address: CTI, DePaul University
3166 South River Road, 2nd Floor
Des Plaines, IL 60018
Office:Faculty Offices (See front desk for location)
Office Hours: Monday 5:15-6:15pm in Faculty Offices (See front desk for location)
Monday 9:30-10:00pm in Faculty Offices (See front desk for location)
Class Page:http://www.depaul.edu/~mwright1/se450
Class Hours: Monday 6:15pm-9:30pm in O'Hare [Section 203]

I prefer communication via email.

I check voicemail several times a day (if I'm in the office)

I check email several times a day, as well as in the evenings.

Please check that the email address on your CampusConnect record is correct. I will send email to the class in the event of last minute changes or announcements.

Course Homepage [5/41]

Course homepage: http://www.depaul.edu/~mwright1/se450

Please check it frequently and before coming to class.

Lecture slides are available in two HTML formats: one slide per page and all slides on one page.

Lecture slides are available if a check is shown (click on the check).

Lecture slides may not be available before the class (but I'll try).

Lecture slides may change after class (but only to update changes from class).

Attendance [6/41]

You must attend the midterm exam, final quiz, and final project presentations.

The midterm (Quiz I) will be held 2003/02/03, in class. The final quiz (Quiz II) will be on 2003/03/10. Final project presentations will be the following week by appointment, or the day after. You will need to allocate 15 minutes between 4:00pm and 10:00pm. Further details will be given in the coming weeks.

A medical note will be required for an absence to either the final or the midterm. Business trips or vacations are not valid reasons for missing the exam and final project.

Block out these dates now!

Class attendance is strongly encouraged, but not mandatory. However, if you are absent from class you are responsible for understanding the material and for finding out about any announcements made in that class. In addition, much of the discussion will be based upon diagrams drawn on the board. They may not appear in the slides and may not be captured well by COL.

Assessment [7/41]

Your final grade will be based on:

Homework will be given weekly, and gradually will decrease as the project is started. The homework will turn into the project (more about this later).

Program submissions will be assessed on whether they achieve the set task and the quality of the code. Once we cover unit testing, it will also be required that you write valid unit tests to prove that your code works and fulfills the requirements of the homework.

Unless otherwise stated, homework assignments are due by 5:00 PM on the Monday after the class in which they are assigned. I will review the assignment in class, so you are encouraged to ask questions at that time. If you wait until the night before to do the homework and need help, I can't guarantee that I will be available, so start it early.

You are expected to complete all of the homework assignments by the deadline. Late homework submissions will not be accepted, and all homework assignments will count towards the final grade (i.e. no free homework assignments)

Homework assignments must be submitted through the online system. Email submissions will not be accepted. Grades will also be posted to the COL site, along with comments if needed.

There will be no extra credit homework and/or projects.

You must achieve a passing grade on both the exam and final project to pass the course.

Grading Scale:

A : total >= 93
A-: 93 > total >= 90
B+: 90 > total >= 87
B : 87 > total >= 83
B-: 83 > total >= 80
C+: 80 > total >= 77
C : 77 > total >= 73
C- : 73 > total >= 70
D+: 70 > total >= 67
D : 67 > total >= 63
D-: 63 > total >= 60
F : 60 > total

Projects [8/41]

What is the project about?

Textbooks [9/41]

Required:

Optional:

Optional:

Prerequisites [10/41]

You must have the following:

If you do not have 416 or java experience, drop now.

Useful, but optional:

Java Self-Assessment [11/41]

Develop a linked list class.

Develop a class hierarchy of shapes, which includes:

Shape 
  Closed Shape 
    Circle, Rectangle, ... 
  Open Shape 
    Line, Curve, ... 
  Text 

Each class supports a method toString that returns the attributes of the shape as a string.

Instantiate a List of shapes. Use the java.util.List interface and a List implementation from the JDK.

Insert several different shapes into the List, and print out the contents of the List of shapes using the appropriate List iteration methods that are part of the Java Collections classes.

If you have:

Expectations [12/41]

The course will be conducted using Java and some of its many APIs. I expect you to be able to work your way through the APIs using Javadoc or a Java reference book. In other words, if you have a question about how to do something with a Java API, I will not be answering API related questions immediately, but rather pointing you to documentation for API related questions.

The course requires that you actively engage the material on your own. You should not only read the example code given in class, but modify and run it. Learn to use the tools talked about in class.

Spend at least a few hours a week just playing with the examples given in class, or your own Java code.

The only way to learn programming is to program. (I know, I know, you've heard that before, but it's true!).

Tools [13/41]

The class homework, project, and examples should all be developed, compiled and run using the 1.4 Java Development Kit from Sun. It is available on Win32, Linux, and Solaris. If you are using HP or another *nix OS, 1.4 is probably still available for you as well, but I may not be able to support environmental issues you may have.

IDEs [14/41]

IDEs

For this class, I ask that you do not use IDEs for development. An IDE (Integrated Development Environment) would include (but is not limited to) the following:

I define an IDE as a tool that generates code, compiles it, and runs the debugger in one environment. While these tools are not a bad idea, and in fact can make you very productive, I still do not want you to use them. This is not because I want to make your life harder, but for these reasons:

From BlueJ's website: Many teachers do not use an integrated environment (usually because of problems with finding a suitable one). In that case, students work from a command line (using Sun's JDK) and spend considerable time becoming familiar with Unix or DOS instead of learning about programming. In this case, valuable opportunities are lost for better teaching and learning through the use of better tools. Other environments are developed for more professional users and present an absolutely overwhelming set of interface components and functionality. Students are lost in these environments, and the effect can be as bad as having no integrated environment at all. Other environments are really modifications of non-object-oriented (procedural) environments and offer the wrong set of tools and abstractions. All of those, too minimalist tools, too complicated tools or the wrong tools, cause considerable problems. So why not use BlueJ? Because you are no longer beginners! (SE 450)

Recommended Setup [15/41]

I would recommend the following setup:

Some editors you might want to use are:

I would not recommend Notepad or Wordpad.

Please set your tab stops to a reasonable number (say 4) and properly indent your code.

Ant and JUnit will be discussed later in the quarter.

Tell Me About Yourself [16/41]

What do you do, and what are you looking for in this course?

Course Overview [17/41]

We will study object-oriented design and implementation. Among the topics of the course are:

Java and the UML will be used for source code examples, homework assignments, and the exams.

Course Objectives [18/41]

By the end of this course you should:

The NEW SE450 [19/41]

Why is SE450 different than it used to be?

What happened to SE455?

What's the difference?

The Position of SE450 in the Curriculum [20/41]

How is this course related to others?

Software Engineering [21/41]

What do Engineering practices have in common?

Analysis of Designs - Engineering vs. Craftmanship. The quality can be assured beforehand

Non-recurrence of failures - will the Tacoma Narrows Bridge ever be built the same way?

Codification of knowledge - best practices

Does this happen with Software?

Object Oriented techniques [22/41]

History

Simula (1960s) -> Smalltalk (1970s) -> C++,Objective C, Eiffel (1980s)

1990s brought about C++ maturity and Java

UML

Design Patterns

Iterative Development (RUP and XP)

Some important terms [23/41]

Encapsulation: OO programming requires encapsulation. The characteristics and behavior of the object are joined in one module, but the implementation of the module is separated from its contractual interface, and hidden from clients of the module.

Abstraction: The behaviors, or functionalities of a module (or class) should be characterized in a succinct and precise description known as the contractual interface of the module, i.e. the contractural interface captures the essence of the behavior of the module. It is dealing with only the parts of a real-world entity that are essential to interact with it inside the world of software.

Association: a general binary relationship.

Aggregation: has-a or part-whole relationship between classes.

Composition: exclusive ownership and control of the lifetime of the component class by the aggregate class.

Generalization: inheritance, extension - the grouping of common traits among different entities.

Polymorphism and dynamic binding:The ability to interchange modules dynamically without affecting clients. Many modules can all have the same type, and be used in the same code.

Design Pattern: describes a problem which occurs repeatedly in an environment and then describes a solution to problem in such a way that it can be used many times over, without doing it the same way twice.

We'll look into all of these in more detail in the coming weeks

Objects vs. Classes [24/41]

Object: represents anything in the real world that can be distinctly identified. Object and instance are interchangeable.

Class: represents a set of objects with similar characteristics and behavior. An object is an instance of a class.

Java Overview [25/41]

Today we will review some very basic Java concepts, as well as look into the tools that are part of the SDK. This will provide you with all the tools you need to do the homework, but you may still need to refer to the SDK documentation and the Javadocs for the Java APIs in order to complete the homework.

We will also look at tools and resources for the Java language, including the SDK (Software Development Kit), documentation, examples, web resources, and some environment details.

Java Tools Overview [26/41]

Java tools are part of the JDK

They consist of:

You can download the Sun 1.4 JDK at http://java.sun.com/j2se/1.4/download.html. Make sure you get the SDK and not just the JRE (Java Runtime Environement). You can also download the J2SE documentation at the same time. This is highly recommended, since it allows you to browse most of the docs locally. These docs will come in very handy throughout the course.

Java Features [27/41]

Features:

History:

Example: Hello World [28/41]

There are two main types of Java programs, applications and applets. We will be developing all (or almost all) applications in this course.

An example application

        // Filename: Hello.java
        /**
        * A Java application that prints the message: "Hello from Venus!"
        */
        public class Hello {
            public static void main (String[] args) {
                System.out.println("Hello from Venus!");
                /* System.out refers to the standard output */
            }
        }
        

Let's break down this program:

Filename - The filename must match the class name for the class in the file. Only one public class is allowed per file.

The first document is a javadoc comment. The Javadoc tool will be discussed shortly. Javadoc comments start with /** instead of just /*

The class name is Hello. It is public

It has one method. Static and other method modifiers will be discussed soon

Java can use two non-javadoc comment blocks: /* comment */ and // comment

Example: Hello World - in a package [29/41]

Java uses packages to group classes logically. All classes are in a package. If you don't specify a package, a class is in the default package, and the class has default visibility (it's almost like the class has public visiblility, but it is called package visibility).

The example with a package

        // Filename: Hello.java
        package example;
        /**
        * A Java application that prints the message: "Hello from Venus!"
        */
        public class Hello {
            public static void main (String[] args) {
                System.out.println("Hello from Venus!");
                /* System.out refers to the standard output */
            }
        }
        

This will matter when we set up our source code directories and run the java compiler and launcher

Java Applets [30/41]

Applets are embedded in html pages, and are run by the web browser that is displaying the page.

We won't be spending any time with applets in this class, but here is an example:

        import java.awt.*;
        import java.applet.Applet;

        public class HelloApplet extends java.applet.Applet {

            public void paint(Graphics g) {
                Dimension d = getSize();
                g.setColor(Color.black);
                g.fillRect(0,0,d.width,d.height);
                g.setFont(new Font("Sans-serif", Font.BOLD, 24));
                g.setColor(new Color(255,215,0));
                g.drawString("Hello World!", 40, 25);
            }

        }
        

And the corresponding html file:

        <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

        <html>
        <head>
        <title>SE450 Hello World</title>
        </head>
        <body>
        <center>
            <applet code="HelloApplet.class" width="300" height="100">
            </applet>
        </center>
        </body>
        </html>

        

To run the applet, open the html file with appletviewer or a java enabled web browser.

The superclass of all applets is java.applet.Applet

There is no main() method, it is loaded and run by the browser

paint() method paints the picture, but there are three methods that are called implictly by the browser:

The applet tag in the html file needs to expose the source code, width, and height the applet will use on the page.

Applets use a sandbox security model, they can't open network connections to other hosts, start programs, or issue OS commands, unless the user explicitly grants these privileges.

Java Tools: general [31/41]

You will need to download the Java tools to your computer and run the installer. The java tools will all be placed in a directory of your choosing (default is c:\j2sdk1.4.0_0x where x is the version you downloaded). This directory is your JAVA_HOME.

Every major operating system has what are known as environment variables and has a different way to set them. You will need to know how to do this on your computer in order to complete assignemnts and pass this class. It's very simple, but it seems to give a large number of people trouble.

With the JDK, you need to think about 3 main variables. Your PATH, your CLASSPATH, and JAVA_HOME. Your path is the set of directories where the OS looks for executable programs and scripts. This needs to include your JAVA_HOME's bin directory.

Setting an environment variable: On Windows:

        set PATH=%PATH%;c:\j2sdk1.4.0_03\bin
        

On Unix (bash):

        export PATH=$PATH:/usr/java/j2sdk1.4.0_03/bin
        

Note the path separator on Unix is ":", on Windows it is ";".

You can set an environment variable permanently on Windows by putting it in your autoexec.bat (Windows 9x) or by setting it in your Sytem -> Environment Variables Tab (Windows NT/2000/XP). You can always set up a .bat file to set your environment and run it from a command shell. The command shell on Windows 9x can be run by selecting Start -> Run -> type command in the Open box and click OK, or on Windows NT/2000/XP by doing the same and typing cmd.

In Unix (bash shell) you can put the PATH, etc in your ~/.profile or ~/.bash_profile.

Once the PATH is set up, you can run the SDK tools.

The classpath is the path where the java tools will look for compiled class files. If you are using any third party libraries, you will need to include them on the classpath. You will also need to include directories where compiled class files are located. To include an archive of class files (a jar or zip file), just include the path to the actual file. To include a directory, just include the directory where the files are located. If the files are in a package and their package structure is reflected in the filesystem, point to the directory that contains the "root" of the package structure

Java tools: general (cont.) [32/41]

All the java tools can be executed from the command line in a shell.

Many of them take the -classpath argument. You can either set the CLASSPATH environment variable, or pass it in on the command line each time.

Most of the commands take the -version and -verbose arguments as well. Use these to figure out if you are using the right version of the tools and to help debug problems

Java Tools: javac [33/41]

You will invoke the java compiler against the java source files you are trying to compile. You can use many command line options to make the compiler more sophisticated in how it deals with your code and bytecode.

For the example program above (in default package), you would run:

        javac Hello.java
        

in the same directory where the Hello.java file would be located. This would compile the code and place the Hello.class file in the same directory.

You can also put the .class files in a different directory by using the -d command line option. So if your source files were in src, and you wanted the class files in build, you can run

         javac -d build src\Hello.java
         

To turn on debugging information for the debugger (more on this later) you can run the javac command with the -g option.

For the java program in a package, put the source code in a directory structure that matches the package structure. So the file Hello.java will be in a directory called example. The directory that contains the example directory is the package root. This is where we run the commands from. So the java compiler would be run as following: On Windows -

         javac example\Hello.java
         

on Unix

         javac example/Hello.java
         

Java Tools: java [34/41]

To run java programs, you use the java runtime launcher. For the example above, you would run:

        java Hello
        

Note that the .class is not included in the java command. This is assuming your classpath has been set to the directory where the .class files are located. To set it at runtime:

        java -classpath c:\se450\build Hello
        

will work.

If you get something like:

        Exception in thread "main" java.lang.NoClassDefFoundError: Hello
        

you didn't set your classpath correctly. Fix the classpath and it will work (or give you a different error)

To run the program that is in a package, you first need to ensure that the classpath contains the package root. Then run it as follows:

        java example.Hello
        

Java Tools: javadoc [35/41]

Java has a great tool that will build excellent documentation of java source code that includes special comments. These are called Javadoc comments. You can learn all about the Javadoc tools here or in your documentation download (it will be in docs/tooldocs/javadoc/index.html). This will explain all the detail on how to use and run javadoc

Read this tutorial on how to write good javadoc comments.

There are a number of tags that javadoc supports. Some of the more common ones are:

Here's a complete example from the javadoc example:

        /**
         * Graphics is the abstract base class for all graphics contexts
         * which allow an application to draw onto components realized on
         * various devices or onto off-screen images.
         * A Graphics object encapsulates the state information needed
         * for the various rendering operations that Java supports.  This
         * state information includes:
         * <ul>
         * <li>The Component to draw on
         * <li>A translation origin for rendering and clipping coordinates
         * <li>The current clip
         * <li>The current color
         * <li>The current font
         * <li>The current logical pixel operation function (XOR or Paint)
         * <li>The current XOR alternation color
         *     (see <a href="#setXORMode">setXORMode</a>)
         * </ul>
         * <p>
         * Coordinates are infinitely thin and lie between the pixels of the
         * output device.
         * Operations which draw the outline of a figure operate by traversing
         * along the infinitely thin path with a pixel-sized pen that hangs
         * down and to the right of the anchor point on the path.
         * Operations which fill a figure operate by filling the interior
         * of the infinitely thin path.
         * Operations which render horizontal text render the ascending
         * portion of the characters entirely above the baseline coordinate.
         * <p>
         * Some important points to consider are that drawing a figure that
         * covers a given rectangle will occupy one extra row of pixels on
         * the right and bottom edges compared to filling a figure that is
         * bounded by that same rectangle.
         * Also, drawing a horizontal line along the same y coordinate as
         * the baseline of a line of text will draw the line entirely below
         * the text except for any descenders.
         * Both of these properties are due to the pen hanging down and to
         * the right from the path that it traverses.
         * <p>
         * All coordinates which appear as arguments to the methods of this
         * Graphics object are considered relative to the translation origin
         * of this Graphics object prior to the invocation of the method.
         * All rendering operations modify only pixels which lie within the
         * area bounded by both the current clip of the graphics context
         * and the extents of the Component used to create the Graphics object.
         * 
         * @author 	Sami Shaio
         * @author 	Arthur van Hoff
         * @version 	%I%, %G%
         * @since       JDK1.0
         */
        public abstract class Graphics {

            /** 
             * Draws as much of the specified image as is currently available
             * with its northwest corner at the specified coordinate (x, y).
             * This method will return immediately in all cases, even if the
             * entire image has not yet been scaled, dithered and converted
             * for the current output device.
             * <p>
             * If the current output representation is not yet complete then
             * the method will return false and the indicated {@link ImageObserver}
             * object will be notified as the conversion process progresses.
             *
             * @param img       the image to be drawn
             * @param x         the x-coordinate of the northwest corner of the 
             *                  destination rectangle in pixels
             * @param y         the y-coordinate of the northwest corner of the 
             *                  destination rectangle in pixels
             * @param observer  the image observer to be notified as more of the 
             *                  image is converted.  May be <code>null</code>
             * @return          <code>true</code> if the image is completely 
             *                  loaded and was painted successfully; 
             *                  <code>false</code> otherwise.
             * @see             Image
             * @see             ImageObserver
             * @since           JDK1.0
             */
            public abstract boolean drawImage(Image img, int x, int y, 
                                              ImageObserver observer);


            /**
             * Dispose of the system resources used by this graphics context.
             * The Graphics context cannot be used after being disposed of.
             * While the finalization process of the garbage collector will
             * also dispose of the same system resources, due to the number
             * of Graphics objects that can be created in short time frames
             * it is preferable to manually free the associated resources
             * using this method rather than to rely on a finalization
             * process which may not happen for a long period of time.
             * <p>
             * Graphics objects which are provided as arguments to the paint
             * and update methods of Components are automatically disposed
             * by the system when those methods return.  Programmers should,
             * for efficiency, call the dispose method when finished using
             * a Graphics object only if it was created directly from a
             * Component or another Graphics object.
             *
             * @see       #create
             * @see       #finalize
             * @see       Component#getGraphics
             * @see       Component#paint
             * @see       Component#update
             * @since     JDK1.0
             */
            public abstract void dispose();

            /**
             * Disposes of this graphics context once it is no longer referenced.
             * @see       #dispose
             * @since     JDK1.0
             */
            public void finalize() {
                dispose();
            }
        }
        

Your comments don't have to be this complete, but it give you an idea of how all of the tags are used.

Java Tools: jar [36/41]

The jar tool is basically a command line zip tool. Java ARchives are just zip files, with special directories in them that Java uses to store information about the Java ARchive. For this class, jar is very useful for submitting your homework as one file.

Jar has very similar arguments to the unix tar command (Tape ARchive), so if you are familiar with it, you will have no problem picking up jar.

Jar basically has four commands, create (-c), list (-t), extract (-x), and update (-u). The -f command is used to specify the filename that you want to run the command on (to update, extract, list, etc) and the -v command will turn on verbose mode which will give you more detail of the command.

For example, to list the contents of the tools.jar file in $JAVA_HOME/lib, issue the command

        jar tf tools.jar
        

and you will see a listing of every file in the archive. To extract all the files (you may not want to do this, there are a lot of them) run:

        jar xf tools.jar
        

For example, to create a zip file for homework submission, first open a command prompt and go to the directory where the submission files exist. Then, run the command

        jar cfM submission.zip *
        

and there will be a new file created called submission.zip with all the files in your directory. The M is to omit the manifest, a special file that stores information about the archive that java can use.

Java Tools: jdb [37/41]

jdb is the java debugger. It is very useful if you are trying to solve a difficult debugging problem, and using System.out.println() is not effective (or you don't want to insert the new statements and recompile).

Usually, graphical debuggers are part of an advanced IDE, but the command line version works very well. You just need to know how to run through the code.

Here is an example session with Hello, just type in help after starting jdb to see all the options.

D:\school\se450\fall02\source\code\example>jdb Hello
Initializing jdb ...
> stop in Hello.main(String[])
Deferring breakpoint Hello.main(String[]).
It will be set after the class is loaded.
> run
run Hello
>
main[1] step
>
Step completed: "thread=main", Hello.main(), line=7 bci=0
7            System.out.println("Hello from Venus!");

main[1] list
3    * A Java application that prints the message: "Hello from Venus!"
4    */
5    public class Hello {
6        public static void main (String[] args) {
7 =>         System.out.println("Hello from Venus!");
8            /* System.out refers to the standard output */
9        }
10    }
main[1] next
Hello from Venus!
>
Step completed: "thread=main", Hello.main(), line=9 bci=8
9        }

main[1] cont
>
The application exited
    

Debugging with jdb is very helpful, but the barrier to entry is a bit high. If you are familiar with command line debuggers, you will probably find it easy to use. If not, try it out and see how quickly you pick it up. It might save you time down the road on your project

Java Tools: javap [38/41]

javap is useful if you have existing .class files and need to determine a little about what methods they have and what their structure is. It isn't a complete decompiler. For that, check out jad. But it tells us a little bit more about the java language.

To run javap, you use the standard classpath variable. Just give javap the name of the Class you want to disassemble, and if it is in your classpath, it will print the method signatures of your class. For Hello:

        D:\se450>javap Hello
    Compiled from Hello.java
    public class Hello extends java.lang.Object {
        public Hello();
        public static void main(java.lang.String[]);
    }
        

javap will also print the bytecodes of the class file according the

Java virtual machine specification. This is done with the -c option.
        D:\se450>javap -c Hello
Compiled from Hello.java
public class Hello extends java.lang.Object {
    public Hello();
    public static void main(java.lang.String[]);
}

Method Hello()
   0 aload_0
   1 invokespecial #1 <Method java.lang.Object()>
   4 return

Method void main(java.lang.String[])
   0 getstatic #2 <Field java.io.PrintStream out>
   3 ldc #3 <String "Hello from Venus!">
   5 invokevirtual #4 <Method void println(java.lang.String)>
   8 return
        

For java.lang.String!

    D:\school\se450\fall02\source\code\example>javap java.lang.String
    Compiled from String.java
    public final class java.lang.String extends java.lang.Object implements java.io.Serializable, java.lang.C
    omparable, java.lang.CharSequence {
        public static final java.util.Comparator CASE_INSENSITIVE_ORDER;
        public java.lang.String();
        public java.lang.String(java.lang.String);
        public java.lang.String(char[]);
        public java.lang.String(char[],int,int);
        public java.lang.String(byte[],int,int,int);
        public java.lang.String(byte[],int);
        public java.lang.String(byte[],int,int,java.lang.String) throws java.io.UnsupportedEncodingException;

        public java.lang.String(byte[],java.lang.String) throws java.io.UnsupportedEncodingException;
        public java.lang.String(byte[],int,int);
        public java.lang.String(byte[]);
        public java.lang.String(java.lang.StringBuffer);
        java.lang.String(int,int,char[]);
        public int length();
        public char charAt(int);
        public void getChars(int, int, char[], int);
        public void getBytes(int, int, byte[], int);
        public byte getBytes(java.lang.String)[] throws java.io.UnsupportedEncodingException;
        public byte getBytes()[];
        public boolean equals(java.lang.Object);
        public boolean contentEquals(java.lang.StringBuffer);
        public boolean equalsIgnoreCase(java.lang.String);
        public int compareTo(java.lang.String);
        public int compareTo(java.lang.Object);
        public int compareToIgnoreCase(java.lang.String);
        public boolean regionMatches(int, java.lang.String, int, int);
        public boolean regionMatches(boolean, int, java.lang.String, int, int);
        public boolean startsWith(java.lang.String, int);
        public boolean startsWith(java.lang.String);
        public boolean endsWith(java.lang.String);
        public int hashCode();
        public int indexOf(int);
        public int indexOf(int, int);
        public int lastIndexOf(int);
        public int lastIndexOf(int, int);
        public int indexOf(java.lang.String);
        public int indexOf(java.lang.String, int);
        static int indexOf(char[], int, int, char[], int, int, int);
        public int lastIndexOf(java.lang.String);
        public int lastIndexOf(java.lang.String, int);
        static int lastIndexOf(char[], int, int, char[], int, int, int);
        public java.lang.String substring(int);
        public java.lang.String substring(int, int);
        public java.lang.CharSequence subSequence(int, int);
        public java.lang.String concat(java.lang.String);
        public java.lang.String replace(char, char);
        public boolean matches(java.lang.String);
        public java.lang.String replaceFirst(java.lang.String, java.lang.String);
        public java.lang.String replaceAll(java.lang.String, java.lang.String);
        public java.lang.String split(java.lang.String, int)[];
        public java.lang.String split(java.lang.String)[];
        public java.lang.String toLowerCase(java.util.Locale);
        public java.lang.String toLowerCase();
        public java.lang.String toUpperCase(java.util.Locale);
        public java.lang.String toUpperCase();
        public java.lang.String trim();
        public java.lang.String toString();
        public char toCharArray()[];
        public static java.lang.String valueOf(java.lang.Object);
        public static java.lang.String valueOf(char[]);
        public static java.lang.String valueOf(char[], int, int);
        public static java.lang.String copyValueOf(char[], int, int);
        public static java.lang.String copyValueOf(char[]);
        public static java.lang.String valueOf(boolean);
        public static java.lang.String valueOf(char);
        public static java.lang.String valueOf(int);
        public static java.lang.String valueOf(long);
        public static java.lang.String valueOf(float);
        public static java.lang.String valueOf(double);
        public native java.lang.String intern();
        static {};
    }
        

One nice use of javap is to check if you have a class in your classpath. Just run javap against the class that you need to find (it doesn't need to be a command line program) and it will tell you if it is or isnt' in your classpath.

Java Tools: appletviewer [39/41]

Modern browsers like IE and Netscape support java and the java plugin, but sometimes there are issues with the version of the JVM in the browser, or setting up the browser properly. In this case, it is easies to use the appletview to run the applet.

The appletviewer is run by pointing it to an html file with the applet defined in it. From the earlier example:

        appletviewer hello.html
        

Homework [40/41]

Read chapters 1-3, 8.2, and Appendices B and C of Jia (and, optionally, chapters 1 of Gamma and 1 and 2 of Shalloway).

Download and install the 1.4 JDK and Documentation on your computer (or try doing it on a lab computer in a separate directory or filesystem)

Read through the documentation and play with the SDK tools, including javac, java, javap, javadoc, jdb, and jar. (You'll need 3 of them for your assignment anyway)

Read this tutorial on how to write JavaDoc comments.


Do problem 3.1 in the Jia text, with the following additions: Your program should not just print your favorite poem (or part of it, it doesn't have to be a typing exercise, just a few lines), but should take 1 or more String arguments which are words to search for in your poem. It should print the poem, and then print each word that was passed in whether or not it was found in the poem. For example, if the poem were:

Do not go gentle into that good night,
Old age should burn and rave at close of day;
Rage, rage against the dying of the light.
        

And the program were called like this:

java se450.mwright1.hw1.MyFavoritePoem rage light computer
        

The output would be:

Do not go gentle into that good night,
Old age should burn and rave at close of day;
Rage, rage against the dying of the light.

rage is in the poem
light is in the poem
computer is not in the poem
        

Use the supplied code, sample submission, and package structure here.

Also:

Homework (continued) [41/41]

Modify the text file grader.txt so that it contains your name, DePaul number (PeopleSoft ID), and your email address.

Create a zip file using the jar command that contains all necessary .java files as well as grader.txt. The java files should be in the proper package structure of your code, and the package root should be in the root of the zip file. This is easily done by running

          jar cfM submission.zip grader.txt se450\mwright1\hw1\MyFavoritePoem.java
          

Look at the jar documentation for details on this command

Include no other files.

Submit the ZIP file as "Homework1" using the homework submission system.

Please follow the submission instructions carefully. You will receive your grades more quickly and the grader will be in a better mood!

Note that the instructions call for no .class files. You also don't need to include the Message.jar file.

Check your submission before submitting by taking the zip file and moving it to a new directory, unzipping it, compiling it, and running it!

Due next Monday at 5:00 PM

Grading:


Revised: 2002/09/08