JAVA Software Development Paradigm Advance OO Programming

indexadjustmentInternet και Εφαρμογές Web

13 Νοε 2013 (πριν από 3 χρόνια και 5 μήνες)

131 εμφανίσεις

JAVA Software Development Paradigm

Advance OO Programming

Software Layers

Device drivers

Operating system

Applications

BIOS, firmware

The Internet Terms


Browser


provides convenient way to download and display information from the
Internet


Search engine


indexes and helps find the Internet documents that contain specified
keywords and phrases


Portal


a large popular web site that has a collection of links arranged by category


Host


a computer connected to a network


Server


a computer on a network that provides a particular service (e.g., e
-
mail
server)


URL


U
niform (or Universal)
R
esource
L
ocator, an address of a document or a
resource on the Internet


2
-
4

Software Development


Emphasis on
efficiency


fast algorithms


small program size


limited memory use



Often cryptic code


Not user
-
friendly


Emphasis on


programmer’s
productivity


team development


reusability of code


easier maintenance


portability


Better documented


User
-
friendly


1950
-
1960's
:

Now
:

2
-
5

Programming Languages

1940 1950 1960 1970 1980 1990 2000

Machine

code

Assembly
languages

Fortran

Basic

Pascal

Scheme

C

C++

Java

LISP

Smalltalk Smalltalk
-
80

C#

Logo

Python

2
-
6

Software Development Tools


Editor


programmer writes
source code


Compiler


translates the source
into object code
(instructions specific to a
particular CPU)



Linker


converts one or several
object modules into an
executable program


Debugger


steps through the
program “in slow motion”
and helps find logical
mistakes (“bugs”)

History


James Gosling and Sun Microsystems


Oak


Java, May 20, 1995, Sun World


HotJava


The first Java
-
enabled Web browser


JDK Evolutions


J2SE, J2ME, and J2EE

Characteristics of Java

Java is


simple
: familiar, C++ like syntax


object
-
oriented
: require at least one class


Distributed:
socket programming, library
for TCP/IP
protocols,
easily established network connection


Robust & Secure:
Java Virtual Machine, Applet


architecture
-
neutral & Portable:
Byte Code


Performance:
high,

Just
-
in
-
time compilation


Multithreaded:
RMI, Threads


Dynamic:
automatic memory management (Garbage
Collection)


JDK Versions


JDK 1.02 (1995)


JDK 1.1 (1996)


Java 2 SDK v 1.2 (a.k.a JDK 1.2, 1998)


Java 2 SDK v 1.3 (a.k.a JDK 1.3, 2000)


Java 2 SDK v 1.4 (a.k.a JDK 1.4, 2002)


Future ? 2014 … JAVA 3 Platform!

http://java.sun.com/javase/index.jsp

JDK Editions


Java Standard Edition (J2SE)


J2SE can be used to develop client
-
side standalone applications or
applets.


Java Enterprise Edition (J2EE)


J2EE can be used to develop server
-
side applications such as Java
servlets and Java ServerPages.


Java Micro Edition (J2ME).


J2ME can be used to develop applications for mobile devices such
as cell phones.



This course focuses on J2SE to introduce Java
programming.

Java IDE Tools


NetBeans 7.0.1


Forte by Sun MicroSystems


Borland JBuilder


Microsoft Visual J++


WebGain Café


IBM Visual Age for Java


Eclipse


And others…

2
-
12

Java IDE


GUI front end for JDK


Integrates editor, javac, java, appletviewer,
debugger, other tools:


specialized Java editor with syntax highlighting,
autoindent, tab setting, etc.


clicking on a compiler error message takes you to
the offending source code line


Usually JDK is installed separately and an
IDE is installed on top of it.

2
-
13

Compiled Languages:

Edit
-
Compile
-
Link
-
Run

Editor

Source

code

Compiler

Object

code

Linker

Executable

program

Editor

Source

code

Compiler

Object

code

Editor

Source

code

Compiler

Object

code



2
-
14

Interpreted Languages:

Edit
-
Run

Editor

Source

code

Interpreter



2
-
15

Compiler vs. Interpreter


Compiler:


checks syntax


generates
machine
-
code
instructions




not needed to run
the executable
program


the executable
runs faster


Interpreter:


checks syntax


executes appropriate
instructions while
interpreting the
program statements


must remain installed
while the program is
interpreted


the interpreted
program is slower

2
-
16

Java’s Hybrid Approach:

Compiler + Interpreter


A Java compiler converts Java source code
into instructions for the Java Virtual Machine.


These instructions, called
bytecodes
, are the
same for any computer / operating system.


Byte code is analogous to machine code,
interpreted by JVM in platform specific
machine code.

2
-
17

Java’s Compiler + Interpreter

Editor

:

7

K

Hello.java



Compiler

:

Hello.class





Interpreter

Hello,

World
!





:

Interpreter

2
-
18

JDK


J
ava
D
evelopment
K
it


javac


Java compiler


java


Java interpreter


appletviewer


tests applets without a
browser



javadoc


generates HTML
documentation (“docs”)
from source


jar


packs classes into jar
files (packages)


All these are command
-
line tools,
no GUI

2
-
19

Types of Programs


Console
applications






GUI applications


Applets

2
-
20

Console Applications

C:
\
javamethods
\
Ch02>
path=%PATH%;C:
\
Program Files
\
Java
\
jdk
1.5.0_07
\
bin

C:
\
javamethods
\
Ch02>
javac Greetings2.java

C:
\
javamethods
\
Ch02>
java Greetings2

Enter your first name:
Josephine

Enter your last name:
Jaworski

Hello, Josephine Jaworski

Press any key to continue...



Simple text dialog:

prompt


input, prompt


input ...


result

2
-
21

Command
-
Line Arguments

C:
\
javamethods
\
Ch02>
javac Greetings.java

C:
\
javamethods
\
Ch02>
java Greetings Josephine Jaworski

Hello, Josephine Jaworski

public class Greetings

{


public static void main(String[ ] args)


{


String firstName =
args[ 0 ]
;


String lastName =
args[ 1 ]
;


System.out.println("Hello, " + firstName + " " + lastName);


}

}

Command
-
line
arguments are
passed to
main

as an array of
String
s.

2
-
22

Command
-
Line Args (cont’d)


Can be used in GUI applications, too


IDEs provide ways to set them (or
prompt for them)

Josephine Jaworski

2
-
23

GUI Applications

Menus

Buttons

Clickable
panel

Slider

2
-
24

HelloApplet.java

import java.awt.*;

import javax.swing.*;

public class HelloApplet
extends JApplet

{


public void init( )


{


...


}


< ...
other code
>

}

No
main

in applets: the
init

method is called by JDK’s
appletviewer

or the browser

Getting Started with Java
Programming


A Simple Java
Application

public class First

{

public static void main(String[]
args
)

{

System.out.println
("
Aslam

u
Alikum
");

}

}


Compiling Programs


Executing Applications

Creating and Compiling Programs





On command
line


javac

file.java



Source Code

Create/Modify Source Code

Compile Source Code

i.e. javac Welcome.java

Bytecode

Run Byteode

i.e. java Welcome

Result

If compilation errors

If runtime errors or incorrect result

Executing Applications


On command line


java classname

Java
Interpreter
on Windows
Java
Interpreter
on Sun Solaris
Java
Interpreter
on
Linux
Bytecode
...
Example

javac Welcome.java


java Welcome


output:...

3
-
29

Classes and Source Files


Each class is stored in a separate file


The name of the file must be the same as the
name of the class, with the extension
.java


public class Car

{


...

}

Car.java

By convention, the
name of a class
(and its source file)
always starts with
a capital letter.


(In Java, all names are case
-
sensitive.)

2
-
30

Why Bytecodes?


Platform
-
independent


Load from the Internet faster than source
code


Interpreter is faster and smaller than it would
be for Java source


Source code is not revealed to end users


Interpreter performs additional security
checks, screens out malicious code


2
-
31

OOP
-

O
bject
-
O
riented
P
rogramming


An OOP program models a world of active objects.


An object may have its own “memory,” which may
contain other objects.


An object has a set of methods.


A method can change the object’s state, send
messages to other objects, and create new
objects.


An object belongs to a particular class, and the
functionality of each object is determined by its
class.


A programmer creates an OOP application by
defining classes.


2
-
32

The Main OOP Concepts:


Inheritance
: a
subclass

extends a
superclass
;
the objects of a subclass inherit features of
the superclass and can redefine them or add
new features.


Event
-
driven programs
: the program
simulates asynchronous handling of events;
methods are called automatically in response
to events.


2
-
33

Inheritance


A programmer can define hierarchies of
classes


More general classes are closer to the top

Person

Child

Adult

Baby

Toddler

Teen

2
-
34

OOP Benefits


Facilitates team development


Easier to reuse software components and
write reusable software


Easier GUI (
G
raphical
U
ser
I
nterface) and
multimedia programming



2
-
35

Review:


What are some of the current software
development concerns?


What are editor, compiler, debugger used
for?


How is a compiler different from an
interpreter?


Name some of the benefits of Java’s
compiler+interpreter approach.


Define IDE.


2
-
36

Review (cont’d):


What is a console application?


What are command
-
line arguments?


What is a GUI application?


What is the difference between a GUI
application and an applet?


What is OOP?


Define inheritance.