Intro. To OOP Concepts and Java Applications Intro. to IDE tools: NetBean IDE 3.6

shopfitterpsithurismΛογισμικό & κατασκευή λογ/κού

10 Νοε 2012 (πριν από 5 χρόνια και 4 μέρες)

233 εμφανίσεις

1

Course Outline
-

ISM4234

Intro. To OOP Concepts and Java Applications

Intro. to IDE tools: NetBean IDE 3.6


Text

Book
:

Java

Program

Design

1
.
5
,


by

James

Cohoon

&

Jack

D
.




McGraw

Hill

2004
,

ISBN

0
-
07
-
304467
-
9
.

References
:

Big

Java,

Programming

and

Practice,





by

Cay

Horstmann,

John

Wiley

&

Sons,

Inc
.
,

ISBN

0471
-
40248
-
6
.

The

Essential

JAVA

Class

Reference

For

Programmers



By Brian Durney, Prentice Hall, ISBN 0
-
13
-
093385
-
6


Tutorial for Sun ONE Studio 4, by Y. Liang, Prentice Hall 2002.


ISBN 0
-
13
-
141080
-
6; or Forte for Java, Community Edition, Getting Started

Guide,
http://forte.sun.com/ffj/documentation/release3/getstartedce30.pdf
)

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Course Outline


OOP with Java



Why

Java

?

Object

Oriented
;

Portable
;

Multithreaded
;

Robust

&

high

Performance




Introduce

the

fundamentals

of

Object
-
Oriented

Programming
.




Building

Java

applications,

applets

and

utilizing

Java

2

API
.




Introducing

the

principles

of

Object
-
oriented

programming





Classes



Data

type,

Methods,

Scope
;


Inheritance
;

Polymorphism
;

Interfaces
.


Information

hiding,



Arrays
;

Strings
;

Files

and

Streams
;

Graphics

and

Multimedia
;



Exception

handling
;

Multithreading
;

Database

connectivity
.




Control

Structures
;

Common

Algorithms
;

Recursion
;

Collections
.




Homework formatting



Source code (*.java) and Compiled executable file (*.class) and other source files



Screen captured file (show your input and output as results)



Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu




Java Environment




Java Class Libraries (API)




Object
-
Oriented Analysis and Design




Tour of the Chapters of the Book


Computer System Review

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Java Environment

Java source

code

Machine

code

Java

bytecode

Java

interpreter

Bytecode

compiler

Java

compiler

Java Translation and Execution

Phase2
: Compile the source code file


into welcome.class by using
javac welcome.java



( to a target program)

Phase1
: Editing a source file
-

welcome.java

Phase3
: Class loading into memory for
-



Application: java welcome; (translation & execution)


Applet: appletviewer welcome (Web Browser)

Phase4
: The bytecodes loaded from internet or
network are verified.

Phase5
: The bytecode compiler interprets the verified bytecode
into machine code one at a time and as an executable program.

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu



Java Class Libraries


Way to learn Java programming:



writing your own classes;



using classes in extensive Java class libraries (Java API)


Java Class Libraries are known as Java API





(Application Programming Interfaces)



A
class library

is a collection of classes used for developing program



Java programs consist of classes



Classes consist of methods that perform tasks and return information



Java standard class library

that is part of Java development environment


(for example: the
System

class and the
String

class)


Other class libraries can be obtained through third party vendors, or you
can create them yourself

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Object
-
Oriented Analysis and Design
(OOAD)


OOP Object
-
oriented Programming such as Java



C

programmers concentrate on writing functions.



Java programmers concentrate on creating their own

user
-
defined types


classes and components.


OOAD



involves analyzing and designing your system from an object
-
oriented

point of view.


OOD Object
-
oriented Design



provides a more natural and intuitive way to views the design process


by modeling real
-
world objects, their attributes, their behavior



OOD encapsulates data (attributes and functions (behavior into

objects)


Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu



Tour of the Chapters of the Book


Chapter 1

Background


Chapter 2 Java Basics


Chapter 3 Using Objects


Chapter 4 Being Classy


Chapter 5 Decisions


Chapter 6 Iteration


Graphics Interlude I: GUI
-
Based Programming


Chapter 7 Programming with Methods & Classes


Chapter 8 Array and Collections


Chapter 9 Inheritance and Polymorphism



Graphics Interlude II: GUI
-
Based Programming


Chapter 10 Exceptions


Chapter 11 Recursive Problem Solving


Chapter 12 Threads


Chapter 13 Testing and Debugging

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Development Environments


There are many development environments which develop
Java software:


Sun Java Software Development Kit (SDK)


Sun One Studio (Forte) and NetBeans 3.6/4.0


Borland JBuilder


MetroWork CodeWarrior


Microsoft Visual J++


Symantec Café


IBM VisualAge for Java



Though the details of these environments differ, the basic
compilation and execution process is essentially the same

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Java Program Structure


In the Java programming language:


Java created in 1995 by SUN has become a quite
popular object
-
oriented language


A program is made up of one or more
classes


A class contains one or more
methods


A method contains program
statements



These terms will be explored in detail throughout the course



A Java application always contains a method called
main



A Java applet always contains a method called
init

or
start

or
paint

to start
a program without
main

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Java Program Structure

public class MyProgram

{










}

// comments about the class

class header

class body

Comments can be added almost anywhere

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Java Program Structure

public class MyAppProgram

{






}

public static void main (String[] args)

{



}

// comments about the class

// comments about the method

method header

method body

public class MyAppletProgram extends JApplet

{






}

public void init ( )

{



}

// comments about the method

method body

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Identifiers


Identifiers

are user
-
defined names for class, data and methods. They are
the words a programmer uses in a program


An
Identifier

can be made up of letters, digits, the underscore character
(_), and the dollar sign, such as:



number, number2m amount_of_sale, $amount.


The following Identifiers are not valid:



1number (cannot begin with a digit), amount of sale, &amount


Java is
case sensitive
, therefore

Total
and

total
are different
identifiers


Sometimes we choose
Identifiers

ourselves when writing a program
(such as
Lincoln
)


Sometimes we are using another programmer's code, so we use the
Identifiers

that they chose (such as
println
)


Often we use special
Identifiers

called
reserved words

that already have
a predefined meaning in the language


A reserved word cannot be used in any other way

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Reserved Words

The Java reserved words:

abstract

boolean

break

byte

byvalue

case

cast

catch

char

class

const

continue

default

do

double

else

extends

false

final

finally

float

for

future

generic

goto

if

implements

import

inner

instanceof

int

interface

long

native

new

null

operator

outer

package

private

protected

public

rest

return

short

static

super

switch

synchronized

this

throw

throws

transient

true

try

var

void

volatile

while

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


White Space


Spaces, blank lines, and tabs are collectively called
white space


White space

is used to separate words and symbols
in a program


Extra
white space

is ignored


A valid Java program can be formatted many
different ways


Programs should be formatted to enhance
readability, using consistent indentation

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Syntax and Semantics


The
syntax rules

of a language define how we can put
symbols, reserved words, and identifiers together to make a
valid program



The
semantics

of a program statement define what that
statement means (its purpose or role in a program)



A program that is syntactically correct is not necessarily
logically (semantically) correct



A program will always do what we tell it to do, not what we
meant

to tell it to do

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Errors


A program can have three types of errors



The compiler will find problems with syntax and other
basic issues (
compile
-
time errors
)


If compile
-
time errors exist, an executable version of the
program is not created



A problem can occur during program execution, such as
trying to divide by zero, which causes a program to
terminate abnormally (
run
-
time errors
)



A program may run, but produce incorrect results (
logical
errors
)

17

Intro. to Java Applications



Writing A First Program in Java




Welcome1.java




Compiling the Source File into
-






Welcom1.class




Execute The Compiled Program


Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Writing A First Program


// Save the following code to file in C:
\
temp
\
myjava
\
Welcome1.java


public class Welcome1 {



// main method begins execution of Java application


public static void main( String args[] )


{


System.out.println( "Welcome to Java Programming!" );



}





// end method main


}






// end class Welcome1

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Compiling the Source File

(Download ftp://itom.fau.edu/sqiu/Docs/HowToJavaCompiler.doc]


Set path = … ; c:
\
jdk1.4
\
bin
(to ensure system can
find Java tools)

where the compiler javac.exe in


(for window 95/98: edit autoexec.bat file under root of c:
\
)




C:
\
> cd c:
\
temp
\
myjava



Compile your newly created java file:


C:
\
temp
\
myjava > javac Welcome1.java


Now, the compiled bytecode file

Welcome1.class is created.

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Executing the Bytecode File




Load a dos window by running cmd.exe

(or command.exe


win95/98)






C:
\
> cd c:
\
temp
\
myjava





Run the compiled file:




C:
\
temp
\
myjava > java Welcome1


21

Intro. to Java Applets



Writing A First Applet Program in Java








WelcomeApplet.java




Compiling the Source File into
-









WelcomApplet.class




Executing Program trough a HTML file








WelcomApplet.html

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Writing A First Applet

// save the folloeing code to file WelcomeApplet.java
-

A first applet in Java.





import java.awt.Graphics;

// import class Graphics





// Java extension packages

import javax.swing.JApplet; // import class JApplet


public class WelcomeApplet extends JApplet {



// draw text on applet’s background


public void paint( Graphics g )


{



// call inherited version of method paint


super.paint( g );




// draw a String at x
-
coordinate 25 and y
-
coordinate 25


g.drawString( "Welcome to Java Programming!", 25, 25 );



}

// end method paint


}


// end class WelcomeApplet


Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Compiling the Source File


Set path = … ; c:
\
jdk1.4
\
bin
(to ensure system can find
Java tools)
where the compiler javac.exe is in


(for window 95/98: edit autoexec.bat file under root of c:
\
)



C:
\
> cd c:
\
temp
\
myjava


Compile your newly created java file:


C:
\
temp
\
myjava > javac WelcomeApplet.java


Now, the compiled bytecode file




WelcomeApplet.class is created.

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Executing the Bytecode File


Create a HTML file above


WelconApple.html



To load the applet into a Web Browser (or
using appletviewer)


Load a dos window by running cmd.exe



C:
\
> cd c:
\
temp
\
myjava


C:
\
temp
\
myjava >




appletviewer WelcomeApplet

<html>

<applet code = "WelcomeApplet.class" width = "300" height = "45">

</applet>

</html>

Week 1

05/16/2006


Course ISM4234
-
004


Dr. Simon Qiu


Assignment 1


Reading: Chapter 1
-
2



1
-
1. Follow the instruction of how to use Java compiler to
install a java JDSK v.1.4.1 to your computer and test it.


1
-
2. Write and run a simple Java program that displays a
greeting: “Welcome to Java World!”


1
-
3. Write and run a simple Applet program that displays a
greeting: “Welcome to Java World!”