IPL. Java Intro. 14 September 01.
The general aim of the Java half of IPL is to give students a context
in which to develop a solid working knowledge of essential server-side Java
technologies, in particular servlets, Java Server Pages, and database
connectivity. The focus this first trimester is on developing fluency in
core Java.
Required textbook: Bruce Eckel, Thinking in Java. Prentice-Hall.
0-13-027363-5. Available in electronic form at http://www.bruceeckel.com.
I expect that we'll be covering most of the material in TIJ through
Chapter 14 this trimester.
Course website: http://bob.marlboro.edu/~msie/2002/ipl/java/
Java characteristics
- A language in the C tradition
- Object-oriented programming (OOP) extensions
- Programs consist of definitions of types of objects, instantiations
of objects, interactions among objects
- Saner OOP extensions (they say) than C++
- Portable
- Very extensive class libraries
- Scalable (why does it take to pp. 119-20 of TIJ to get to the
first complete Java program?--because Java is a system. I counsel
patience).
OOP--the big (at any rate multi-syllabic) ideas
- Encapsulation
- Inheritance
- Polymorphism
Encapsulation
- Bundling of data and operations ("methods"). The language is built around the
idea of entities that have state and know how to do things (on the
analogy of entities in the world at large)
- Access control. The language lets you control the visibility of
data and operations. This is how we enforce a distinction between
interface (what an object does) and implementation (how it
does that). This distinction is crucial in Java, and appears in a number
of contexts
Inheritance
- Classes in Java can be derived from other classes
- A derived class inherits the state variables and methods of the
class from which it's derived. The derived class may then add additional
data members and methods; it may also redefine existing methods
- "Is-a": an object of a derived class may be used wherever an object
of its superclass can be used
- Inheritance facilitates code re-use
Polymorphism
- If a subclass object can substitute for a superclass one (grand
principle of "is-a") and if methods can be redefined in a subclass,
how can a poor programming language know which version of a method
to execute in any given case? Java has a clever way of inspecting an
object at run-time, when a method of that object is called, of
determining the actual type of that object, and of doing the right
thing--calling the version of the method specific to that object.
Example programs
Development environment
- I recommend you start with Sun's JDK. This is a bare-bones
development environment that you may outgrow, but it's also a minimum
overhead path to getting Java programs running.
- The JDK is already installed on bob.marlboro.edu, and your
user environments are set up so that you can just go in and
edit, compile, and run (the following instructions will work for
programs consisting of one or more class files that reside in the
same directory)
- Edit a file Foo.java (containing the definition of a class Foo).
There are many editors available on bob. Over the long haul you'll
probably want to use some version of either vi or emacs; for
bootstrapping purposes you might want to consider pico (which has
helpful on-screen cues, but which also likes to mangle line ends)
- Compile with "javac Foo.java"
- Execute with "java Foo"
- At some point you'll need to install the JDK on your server here
at school, and you may also want to do so on a machine at home or
work. It's available at http://java.sun.com/j2se/1.3
- More powerful development environments are available. You might want
to take a look for example at Forte (http://www.sun.com/ffj/index.html).
Forte is "free", but the system requirements are substantial.
Assignments
- Reading. Please read the first three chapters of Eckel. The first
chapter introduces many of the facilities in Java--more, probably, than
are needed at this early point. The crucial OOP concepts are brought in
early in the chapter--I think you can skip the sections from page 51 on.
Chapter two discusses basic object handling in Java in detail. Chapter 3
summarizes the C substrate of Java (operators, data types, flow of control
statements...).
- Programming. Please do the following exercises. Due by 29 September,
finished or incomplete.
- If you have questions about either the reading material or the
programming assignments, please ask, either in the wiki
(http://bob.marlboro.edu/~msie/2002/wiki/wiki), or on the mailing list
(msie02@gradcenter.marlboro.edu), or direct to me at markf@marlboro.edu
IPL-Java Home | IPL-Java Wiki