Unit_1_-_Introduction
Unit_1_-_Introduction
Unit 1 – Introduction
Faculty of Computer Science 2009
Universitas Indonesia
1
2/2/2009
References
2
2/2/2009
Software / Tool
Assignments
3
2/2/2009
Lab Activities
Grading Scheme
4
2/2/2009
Software
5
2/2/2009
6
2/2/2009
An object-oriented program is
structured as a community of
interacting agents, called objects.
◦ Each object has a role to play.
◦ Each object provides a service, or
performs an action, that is used by other
members of the community.
An Observation
7
2/2/2009
8
2/2/2009
Responsibilities
9
2/2/2009
10
2/2/2009
11
2/2/2009
12
2/2/2009
13
2/2/2009
Why Java?
14
2/2/2009
15
2/2/2009
16
2/2/2009
Typical Java
development
environment.
Platform Independence
17
2/2/2009
Good:
◦ Platform independent execution
◦ Platform independent binary data (files etc)
◦ Robust
◦ Does not allow operator overloading. Some
people regard this as a limitation. Others think
operator overloading is not a good idea
anyway!
◦ Comes with a huge class library which allow:
File input / output
Graphics
Event trapping / handling
3D modelling
Bad:
◦ Syntax is adopted from C. This means that
some control structures are primitive and
unstructured
◦ Graphics library still provides problems across
different platforms
18
2/2/2009
OO Characteristics
◦ Everything is an object.
◦ A program is a bunch of objects telling
each other what to do by sending
messages.
◦ Each object has its own memory made
up of other objects.
◦ Every object has a type.
◦ All objects of a particular type can
receive the same messages.
OO Characteristics
19
2/2/2009
◦ Everything is an object.
Think of an object as a fancy variable;
it stores data, but you can “make
requests” to that object, asking it to
perform operations on itself. In theory,
you can take any conceptual
component in the problem you’re
trying to solve (dogs, buildings,
services, etc.) and represent it as an
object in your program.
20
2/2/2009
To be OO or not to be OO?
21
2/2/2009
Welcome1.java
2 // Text-printing program.
3
5 {
8 {
10
12
22
2/2/2009
class SimpleApplication{
String text;
//Constructor
SimpleApplication(){
this.setText("I'm a Simple Program");
}
//Accessor method
String getText(){ return text; }
//Mutator method
void setText(String text){ this.text = text; }
Simple Application
23
2/2/2009
Constructors
24
2/2/2009
Introduction to Methods
Methods
25
2/2/2009
Fields
Example:
d.i = 47;
d.f = 1.1f; // ‘f’ after number indicates float constant
d.b = false;
Fields
26
2/2/2009
mport javax.swing.*;
import java.awt.*;
Simple HelloWorld!
Applet
27
2/2/2009
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
28
2/2/2009
◦ <HTML>
◦ <BODY>
◦ <APPLET CODE=SimpleApplet.class
WIDTH=200 HEIGHT=100>
◦ </APPLET>
◦ </BODY>
◦ </HTML>
29
2/2/2009
30
2/2/2009
The SimpleApplet
class extends Applet
class, which extends
the Panel class,
which extends the
Container class. The
Container class
extends Object,
which is the parent
of all Java API
classes.
Applet : Extending a Class
31
2/2/2009
32
2/2/2009
UML
UML
33