成果南大面試lecture1 2012_第1頁
成果南大面試lecture1 2012_第2頁
成果南大面試lecture1 2012_第3頁
成果南大面試lecture1 2012_第4頁
成果南大面試lecture1 2012_第5頁
已閱讀5頁,還剩51頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

IntroductiontoJavaProgramming

Lecture1

IntroductiontoOOPandJava

1-2

IntroductiontoJavaProgramming

Objectives

IntroductiontoOOP

Object-OrientedConcepts

Object-OrientedProgramming

JavaBasic

Javahistory&features

Javalanguage&platform

Javaprogram

1-3

IntroductiontoJavaProgramming

Programs=Object/Class+…+Object/ClassObject/Class=Data/Operation

TypesofProgramming

ProceduralProgramming

Emphasisonproceduralabstraction

Top-downdesign,step-wiserefinement

Suitedforprogramminginthesmall

Programs=DataStructures+Algorithms

Object-orientedProgramming

Emphasisondataabstraction

Bottom-updesign,reusablelibraries

Suitedforprogramminginthelarge

1-4

ObjectsandClasses:Example

Fielddefinitions

Fieldvalues

myCar:Car

colour=bluemodel=FiestafuelCapacity=45

Car

colour:Stringmodel:StringfuelCapacity:int

start():voidstop():void

move(direction:String):void

Car(colour:String,model:String,fuelCapacity:int)

<<instanceOf>>

start():voidstop():void

move(direction:String):void

IntroductiontoJavaProgramming

IntroductiontoJavaProgramming

1-5

Classes&objects

1-6

KindsofClassRelationships

Therearethreebasickindsofclassrelationships

Association

Aggregation(―partof‖)

Apetalispart-ofarose

Allowsonetoconstructnewclassesfromexistingone

Generalization(―kindof‖、“isa‖)

Aroseisakind-ofaflower

Generalizationprovidestheabilitytocreatesubclasses

Subclassessharethestructureoftheparentclass

1-7

Association

“have”,“isrelatedto”,“isassociatedwith”...

Thisisthemostgeneraltypeofrelationship.

1-8

“isdefinedbythe

collectionof”,...(wholeandpartscanexistseparately)

IntroductiontoJavaProgramming

Composition/Partitionvs.Aggregation

“ispartof”,“iscomposedof”,...(wholecannotexistwithouttheparts)

IntroductiontoJavaProgramming

1-9

Generalization

“isa”(IS-A),“akindof”(AKO)

1-10

Inheritance

Theterm,inheritance,isusedinmanyobjectoriented(OO)programminglanguagestodescribethegeneralizationrelationship

Inheritanceisarelationshipwhereoneclasssharesthestructureorbehaviordefinedinoneclass(singleinheritance)ormore(multipleinheritance)

Theprocessofproducingnewclasseswithinheritedattributescreatesasuperclassandsubclasses

1-11

Abstraction

Abstractionistheprocessofcapturingtheessentialwhilesuppressingthedetail

Withoutabstraction,theprogrammermustfaceanoverwhelminglevelofdetail

ProceduralAbstraction:top-downrefinement

DataAbstraction:Data+operation--class

1-12

Encapsulation

Programminglanguagesenforceabstractionvia

encapsulation

Encapsulationisaninformationhidingmechanismthathidesdetailedinternalinformationaboutanabstraction

–Themechanicaldevicesofyourcarareencapsulated(hidden)bythechassisofthecar

AnADTforcesaseparationbetweenhowaclassofobjectsisusedandhowthatclassofobjectsisinternallyimplemented

1-13

Polymorphism

Polymorphismmeans"havingmanyforms―,allowingobjectclassestoresponddifferently,dependingontheirtype

Methodswiththesamenamemaydodifferentthings,dependsontheobjectclasstheyareassociatedwith

PolymorphisminJava

Overloading

Overriding

1-14

OOPandProceduralProgramming

Inproceduralprogramstheblocksarepiecesofcodewhichareexecutedastheprogramisrun

Inobject-orientedprogramsobjectshavelivesoftheirown–theycanbecreated,copied,destroyedorevenlost!

1-15

WhatisJava?

Javaisaprogramminglanguage

generalpurpose

object-oriented

Javaisadevelopmentenvironment

JavaAPIs

Javaisanapplicationenvironment

JavaVirtualMachine

Javaisadeploymentenvironment

PlatformIndependence

1-16

TheFeaturesofJavaLanguage

[SUN]TheJavaLanguage:

simple

object-oriented

network-savvy

interpreted

robust

Secure

architecture-neutral

high-performance

multithreaded

dynamiclanguage

1-17

Simple

SyntaxisbasedontheC、C++

TheOOconceptsarethesameasSmalltalk

Nopointers

Garbagecollection

Small:40kb(run),125kb

1-18

Object-oriented

JavaisahybridofpriorOOlanguages:

SimilaritiestoC++:

Syntax

Accesscontrol(public,private,protected)

SimilaritiestoSmalltalk:

Allbindingisdynamic

Everythingisanobject(well,almost)

SimilaritiestoAda:

Stronglytyped

Nomultipleinheritance

JavahasOOfeatures:

Inheritance,Encapsulation,Polymorphism

1-19

Network-savvy

Distributeddata&distributedcomputing

TCP/IPLib

URL

Servlet

Usingthecoreclassesinmakesnetworkcomputingsimple

1-20

Interpreted

ThecompliertranslatesJavasourcecodeintobytecode;theinterpreterprocessesbytecodewhenyourunaJavaprogram

IntroductiontoJavaProgramming

IntroductiontoJavaProgramming

1-21

High-performance

Bytecode MachineCode

Compiler

JIT(JustinTime)Compiler

HotspotPerformanceEngine

1-22

Robust

TheJavaplatformensuresthatprogramsruncorrectlyanddonotbreakwhentheunexpectedhappens

Stronglytyping

Lackofpointer

Garbagecollection

Exceptionhandling

1-23

Secure

Lackofmemoryaccessdirectly

Bytecodeverification

Appletsinthesandbox

SecurityManager

IntroductiontoJavaProgramming

1-24

Architecture-neutralandPortable

Providesarchitectureneutralityinpartbyallowingnoimplementation-definedfeaturesbytecodeisportablebecauseitrunsonallimplementationsoftheJVM

IntroductiontoJavaProgramming

IntroductiontoJavaProgramming

1-25

Multithreaded

Multithreadingcanbelooselydefinedasthesimultaneousexecutionofmultipleprocesseswithinaprogram

Javaisinherentlymulti-threaded

Forexample,multipleappletscanrunonthesamewebpagewitheachappletreceivingmoreorlessequalCPUtime

1-26

Dynamic

Dynamicloadingclasses

Dynamicbinding

Dynamicsoftwaredevelopmentprocess

1-27

OverviewOfTheJavaPlatform

TheJavaplatformincludes:

JavaVirtualMachine(JVM)

Anumberofpackagesthatsupportthecomplier,interpreter,andrun-timeenvironmentforJava(APIs)

IntroductiontoJavaProgramming

1-28

BriefHistoryofJava

1991:CreatedbyJamesGoslinget.al.atSunMicrosystems

"TheGreenTeam"–Calledthelanguage'Oak'

1994:BillJoy"HotJava"browser

1995:NetscapeagreestosupportJavainNetscapebrowsers

January1996:firstofficial

releaseJDK1.0

Web:applets,security,URL,networking

GUI:AbstractWindows

Toolkit(AWT)

IntroductiontoJavaProgramming

IntroductiontoJavaProgramming

1-29

JDKVersions

JDK1.02(1995)

JDK1.1(1996)

majorchanges

Java2SDKv1.2(a.k.aJDK1.2,1998)

Java2SDKv1.3(a.k.aJDK1.3,2000)

Java2SDKv1.4(a.k.aJDK1.4,2002)

Java2SDKv1.5(a.k.aJDK1.5,2004)

Java2SDKv1.6(a.k.aJDK1.5,2006)

1-30

Java2Architecture

1-31

Java2(1)

J2SE(Java2StandardEdition)

BasicJavaspecificationfordesktopcomputerdevelopment

RunsintheJVM

J2EE(Java2EnterpriseEdition)

Multi-tier,highlyavailable,secure,reliableandscalable

RequiresdifferentJavaenterprisetechnologies

RunsintheJVM

J2ME(Java2MicroEdition)

set-topbox,JavaCard,etc….

RunsintheKVM

1-35

JavaIDETools(1)

JavaDeveloper’sKits(JDK)

Compiler javac

InterpreterDebuggerAppletViewer

Generatorofheadfile

DocumentAdministrator

java

jdb

appletviewerjavahjavadoc

JavaarchivefileGenerator jar

1-36

JavaIDETools(2)

Eclipse

InpriseJBuilder

MicrosoftVisualJ++

SymantecCafé

SunJavaWorkshop

1-37

JDK&JRE

JDK:JavaDeveloper’sKits

Developer

JRE:JavaRuntimeEnviroment

User

1-38

DifferencesBetweenJavaandC++

No―goto‖statement.

No(explicit)pointers!

Automaticgarbagecollection.

Nomultipleinheritance.

EverythinginJavaisdefinedwithinclasses.

Noheaderfiles!

1-39

JavaPrograms

DifferentenvironmentsrequiredifferentkindsofJavaprograms:

Applications: canrunstandaloneonacomputerofanysize,andcanbeanythingfromlargesuitesofsoftwaretosimpleutilities

Applets: areprogramsthatcanbelaunchedfromHTML

documents(client-sidecodethatrunsinaWebbrowser)

—Servlets:runonJava-enabledWebserversandgenerateHTMLdocumentsthataresenttotheclientbrowserfordisplay(sever-sidecodethatrunsinaWebserver)

JavaBeans:areJavaclassesorgroupsofJavaclassesthatconformtoastrictsetofstandards(reusablecomponentsthatcanbemanipulateprogrammatically)

JavaMIDlet:arerunonthemobilephone

ASampleJavaApplicationProgram

1-40

IntroductiontoJavaProgramming

IntroductiontoJavaProgramming

1-41

Applications(1)

foo.java

Javaprogram

sourcecode

1-42

Applications(2)

foo.java

javac

Javacompiler

1-43

Applications(3)

foo.java

javac

foo.class

Programbytecode

1-44

Applications(4)

foo.java

javac

foo.class

java

Javabytecodeinterpreter

1-45

Applets(1)

foo.java

javac

SameprocedureasforApplications

foo.class

1-46

Applets(2)

foo.java

javac

foo.class

Netscape

Yourfavoritebrowser

1-47

YourFirstJavaApplication(1)

/*Displayamessage*/publicclassHelloWorld{

publicstaticvoidmain(String[]args){

System.out.println("HelloWorld!");

}

}

HelloWorld.java

1-48

YourFirstJavaApplication(2)

/*Displayamessage*/publicclassHelloWorld{

publicstaticvoidmain(String[]args){

System.out.println("HelloWorld!");

}

}

Thiswillbethe

nameoftheresulting.classfile

HelloWorld.java

IntroductiontoJavaProgramming

IntroductiontoJavaProgramming

1-49

YourFirstJavaApplication(3)

C:\>javacHelloWorld.javaC:\>javaHelloWorld

1-50

YourFirstJavaApplication(4)

C:\>javacHelloWorld.javaC:\>javaHelloWorld

Thisproduces

HelloWorld.class

1-51

YourFirstJavaApplication(5)

C:\>javacHelloWorld.java

C:\>javaHelloWorld

ThisrunsHelloWorld.class

1-52

YourFirstJavaApplet(1)

importjava.applet.Applet;importjava.awt.Graphics;

publicclasshelloXextendsApplet{publicvoidpaint(Graphicsg){

g.drawString("Helloworld!",50,25);

}

}

helloX.java

1-53

YourFirstJavaApplet(2)

C:\>javachelloX.java

Thisproduceshello.class(likebefore)

butthen...

1-54

YourFirstJavaApplet(3)

<HTML>

<HEAD>

<TITLE>

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論