Top Banner
Introduction to Java Introduction to Java INE2720 INE2720 Web Application Software Web Application Software Development Development Essential Materials Essential Materials
47

Introduction to Java INE2720 Web Application Software Development Essential Materials.

Dec 24, 2015

Download

Documents

Linette Banks
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Java INE2720 Web Application Software Development Essential Materials.

Introduction to JavaIntroduction to Java

INE2720INE2720

Web Application Software Web Application Software DevelopmentDevelopment

Essential MaterialsEssential Materials

Page 2: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

OutlineOutline

TruthsTruths / / MythsMyths About Java About Java– Java is Web-Enabled?Java is Web-Enabled?– Java is Safe?Java is Safe?– Java is Cross-Platform?Java is Cross-Platform?– Java is Simple?Java is Simple?– Java is Powerful?Java is Powerful?

Common Java Protocols and PackagesCommon Java Protocols and Packages The Future of JavaThe Future of Java Getting StartedGetting Started SummarySummary

Page 3: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Web-Enabled?Java is Web-Enabled?

Truth:Truth: Web browsers can run Java “applets” Web browsers can run Java “applets”– The Web can be used for The Web can be used for softwaresoftware delivery and delivery and

executionexecution, not just , not just documentdocument delivery and delivery and displaydisplay

– No more installation or updates; just a bookmarkNo more installation or updates; just a bookmark– Large, complex applets best suited for intranets. Large, complex applets best suited for intranets.

Truth:Truth: Java’s network library is easy to use Java’s network library is easy to use– Ordinary mortals can do socket programmingOrdinary mortals can do socket programming– Standard distributed object protocol and Standard distributed object protocol and

Database Management System (DBMS) APIDatabase Management System (DBMS) API

Page 4: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Hubble Space Telescope Hubble Space Telescope Monitoring:Monitoring:“NASA Goddard’s Most Successful SW Project “NASA Goddard’s Most Successful SW Project EverEver.”.”

Page 5: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Web-Enabled?Java is Web-Enabled?

Myth:Myth: Java is Java is onlyonly for the Web for the Web– Java “applets” run in Web pagesJava “applets” run in Web pages– Java “applications” run stand-aloneJava “applications” run stand-alone– Current usage (roughly)Current usage (roughly)

Client (applet): 5%Client (applet): 5% Desktop (application): 45%Desktop (application): 45% Server (servlets/JSP/EJB): 50%Server (servlets/JSP/EJB): 50%

Page 6: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Safe?Java is Safe?

Truth:Truth: Restrictions on permissible Restrictions on permissible operations can be enforcedoperations can be enforced– No “raw” memory manipulation (directly or No “raw” memory manipulation (directly or

indirectly).indirectly). Thus, it is easy to identify prohibited operations.Thus, it is easy to identify prohibited operations.

– Applets, by default, prohibited from:Applets, by default, prohibited from: Reading from (writing to) the local diskReading from (writing to) the local disk Executing local programsExecuting local programs Opening network connections other than to HTTP Opening network connections other than to HTTP

serverserver Discovering private info about user (username, Discovering private info about user (username,

directories, OS patch level, applications installed, etc.). directories, OS patch level, applications installed, etc.).

Page 7: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Safe?Java is Safe?

Myth:Myth: Applets cannot harm your computer Applets cannot harm your computer– Denial of serviceDenial of service– Browser misconfigurationBrowser misconfiguration– Implementation bugsImplementation bugs

Myth:Myth: Java is too restricted to be useful Java is too restricted to be useful– Restrictions apply only to applets, not regular Java Restrictions apply only to applets, not regular Java

programsprograms– Digital signatures support relaxed restrictionsDigital signatures support relaxed restrictions

Myth:Myth: Applets with digital signatures are no Applets with digital signatures are no more or less safe than ActiveXmore or less safe than ActiveX– Relaxed security in applets not “all or nothing” as in Relaxed security in applets not “all or nothing” as in

ActiveXActiveX

Page 8: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

JavaSource Code

Java Bytecode

Compiler

(javac)

Java Bytecode

Execution

JIT Compileror Interpreter

Compile Time Run Time

Java is Cross-Platform?Java is Cross-Platform?

Truth:Truth: Java programs can compile to Java programs can compile to machine-independent bytecodemachine-independent bytecode

Truth:Truth: All major operating systems have All major operating systems have Java runtime environmentsJava runtime environments– Most bundle it (Solaris, MacOS, Windows 2k, Most bundle it (Solaris, MacOS, Windows 2k,

OS/2)OS/2)

Page 9: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Mars Pathfinder Data Mars Pathfinder Data ViewerViewer

Page 10: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Cross-Platform?Java is Cross-Platform?

Myth:Myth: Safety and machine independence can be Safety and machine independence can be achieved with no performance penaltyachieved with no performance penalty– Current systems are about 20% slower than C++Current systems are about 20% slower than C++– Upcoming releases claim to lower or eliminate that gapUpcoming releases claim to lower or eliminate that gap

Page 11: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

•Truth: Java has a portable graphics library “Native look & feel” -- Java 1.1 UI controls adapt to OS

“Pluggable look & feel” -- Java 2 controls can change looks

•Myth: The graphics library has everything most applications need. AWT (Java 1.0 and 1.1) was weak. JFC/Swing (Java 2) much more complete and powerful.

Java is Cross-Platform?Java is Cross-Platform?

Page 12: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

1212

Java Foundation Classes Java Foundation Classes (JFC)(JFC)Improve Graphics Improve Graphics ConsiderablyConsiderably

More GUI ControlsMore GUI Controls More More

customizable customizable PluggablePluggable

Look and Feel Look and Feel Native Native

Fonts Fonts Richer Richer

Drawing Drawing Operations Operations

Page 13: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Cross-Platform?Java is Cross-Platform?

Myth:Myth: Write Once Run Anywhere Write Once Run Anywhere– Cross-platform code can be achieved, but you must Cross-platform code can be achieved, but you must

test on all platforms you will deliver on.test on all platforms you will deliver on. Java applications can execute local codeJava applications can execute local code The graphics library behaves slightly differently on The graphics library behaves slightly differently on

different platformsdifferent platforms The behavior of the thread scheduler is only loosely The behavior of the thread scheduler is only loosely

defineddefined

Myth:Myth: Java will kill Microsoft Java will kill Microsoft– There is also no longer immediate danger of the There is also no longer immediate danger of the

reverse (Microsoft killing Java)reverse (Microsoft killing Java)– Microsoft wavered between trying to fight Java and Microsoft wavered between trying to fight Java and

joining it and making money by dominating the joining it and making money by dominating the market. With .NET, they are back to fighting it again.market. With .NET, they are back to fighting it again.

Page 14: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Simple?Java is Simple?

Truth:Truth: Java greatly simplifies several Java greatly simplifies several language featureslanguage features– Java has automatic memory Java has automatic memory

managementmanagement Does Windows and takes out the garbageDoes Windows and takes out the garbage No dangling pointers. No memory leaks.No dangling pointers. No memory leaks.

– Java simplifies pointer handlingJava simplifies pointer handling No explicit reference/dereference No explicit reference/dereference

operationsoperations

– No makefilesNo makefiles– No header filesNo header files

Page 15: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Powerful?Java is Powerful?

Truth:Truth: Java has a rich set of standard libraries Java has a rich set of standard libraries– NetworkingNetworking– Threads (lightweight processes)Threads (lightweight processes)– Distributed objectsDistributed objects– Database accessDatabase access– Graphics: GUI controls and drawingGraphics: GUI controls and drawing– Data structure libraryData structure library– Arbitrary precision integral and fixed-point Arbitrary precision integral and fixed-point

arithmeticarithmetic– Digital signaturesDigital signatures– Serialization (transmitting/reassembling data Serialization (transmitting/reassembling data

structures)structures)– File and stream compressionFile and stream compression

Page 16: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

MEL - Master Environmental MEL - Master Environmental Library Library Star Office - Star Office - MS Office MS Office CompetitorCompetitor

http://mel.dmso.mil/mel-bin/java_query

Page 17: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java is Powerful?Java is Powerful?

Myth:Myth: Java will increase programmer Java will increase programmer productivity for all applications by XXX%.productivity for all applications by XXX%.

Myth:Myth: Java will kill C++ Java will kill C++ Myth:Myth: All software should be written in Java All software should be written in Java

– Unix utilities: CUnix utilities: C– Small/medium Windows-only programs: Visual BasicSmall/medium Windows-only programs: Visual Basic– String parsing: PerlString parsing: Perl– High-performance, single-platform OO systems: C++High-performance, single-platform OO systems: C++– Air traffic control, aircraft flight software: AdaAir traffic control, aircraft flight software: Ada– Knowledge-based systems: Lisp/CLOSKnowledge-based systems: Lisp/CLOS– Java also a good alternative for many of theseJava also a good alternative for many of these

Page 18: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

Java and C++Java and C++

Although Java will certainly not kill off C++, Java and C++ do compete for some of the same territory.

Hmm, does The C++ Report think that the way to keep your C++ code robust is to port it to Java?

Page 19: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

1919

Key Java Packages Key Java Packages and Protocolsand Protocols

Core TechnologiesCore Technologies– JDBCJDBC– RMI (and Jini)RMI (and Jini)– JavaBeansJavaBeans– SwingSwing– Java 2DJava 2D

Standard ExtensionsStandard Extensions– Servlets Servlets

(and JavaServer Pages)(and JavaServer Pages)– Enterprise Java Beans (and JNDI)Enterprise Java Beans (and JNDI)– Java 3DJava 3D

Page 20: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

2020

Java Packages and Protocols:Java Packages and Protocols:JDBC (Java DataBase JDBC (Java DataBase Connectivity)Connectivity)

Standardizes mechanism for making Standardizes mechanism for making connection to database serverconnection to database server– Requires server-specific driver on client. No change Requires server-specific driver on client. No change

to server.to server. Standardizes mechanism for sending queriesStandardizes mechanism for sending queries

– Either regular or parameterized queries (stored Either regular or parameterized queries (stored procedures)procedures)

Standardizes data structure of query resultStandardizes data structure of query result– Assumes relational data, so data structure is a tableAssumes relational data, so data structure is a table

Does Does notnot standardize SQL syntax standardize SQL syntax– Queries are simply stringsQueries are simply strings– Server extensions and enhancements supportedServer extensions and enhancements supported

Page 21: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

2121

Java Packages and Protocols:Java Packages and Protocols:Remote Method Invocation Remote Method Invocation (RMI)(RMI) Built-in Distributed Object ProtocolBuilt-in Distributed Object Protocol

– RMI lets a developer access a Java object and RMI lets a developer access a Java object and manipulate it in the normal manner. Behind the manipulate it in the normal manner. Behind the scenes, each function call really goes over the scenes, each function call really goes over the network to a remote object.network to a remote object.

– Arbitrary Java data structures can be sent over the Arbitrary Java data structures can be sent over the network with little or no special packaging, due to network with little or no special packaging, due to Java’s “serialization” mechanismJava’s “serialization” mechanism

– Similar to a simplified CORBA, but restricted to Similar to a simplified CORBA, but restricted to Java-to-Java communicationJava-to-Java communication

JiniJini– RMI-based protocol for self-documenting services.RMI-based protocol for self-documenting services.– Allows real “plug and play” -- no separate driversAllows real “plug and play” -- no separate drivers– Jury is out on eventual success. Security and industry Jury is out on eventual success. Security and industry

adoption are open questions.adoption are open questions.

Page 22: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

2222

Java Packages and Java Packages and Protocols:Protocols:JavaBeansJavaBeans JavaBeans is to Java as ActiveX is to JavaBeans is to Java as ActiveX is to

Visual C++. Visual C++. – Lets you package a Java program Lets you package a Java program

as a software “component”as a software “component”– Visual tools can modify/manipulate Visual tools can modify/manipulate

it without knowing anything about it without knowing anything about it in advanceit in advance

For example, you can drop a Bean into For example, you can drop a Bean into Visual Café, IBM VisualAge for Java, Visual Café, IBM VisualAge for Java, Inprise (Borland) JBuilder, Sybase PowerJ, Inprise (Borland) JBuilder, Sybase PowerJ, Metrowerks CodeWarrior, Sun JavaWorkshop, etc., Metrowerks CodeWarrior, Sun JavaWorkshop, etc., and it is automatically available from their tool and it is automatically available from their tool palette for drag-and-drop developmentpalette for drag-and-drop development

– Better security and portability than ActiveXBetter security and portability than ActiveX– More ActiveX components availableMore ActiveX components available

Page 23: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

2323

Java Packages and Java Packages and Protocols:Protocols:SwingSwing Standard GUI-control (widget) library in Java Standard GUI-control (widget) library in Java

22 Many more built-in controlsMany more built-in controls Much more flexible and customizableMuch more flexible and customizable Includes many small features aimed at Includes many small features aimed at

commercial applications commercial applications – Tooltips, tabbed panes, on-line Tooltips, tabbed panes, on-line

help, HTML support, dockable help, HTML support, dockable toolbars, multi-document toolbars, multi-document interface, etc.interface, etc.

Look and feel can be Look and feel can be changed at run timechanged at run time

Page 24: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

2424

Java Packages and Java Packages and Protocols:Protocols:Java 2DJava 2D Standard drawing library in Java 2Standard drawing library in Java 2 Many new drawing attributesMany new drawing attributes

– Fill patterns and imagesFill patterns and images– Arbitrary fontsArbitrary fonts– Pen thicknesses and dashing patternsPen thicknesses and dashing patterns– Color mixing rules and transparencyColor mixing rules and transparency

Coordinate transformationsCoordinate transformations– Floating-point coordinate systemFloating-point coordinate system– Mapping from memory coords to Mapping from memory coords to

screen or printer coordsscreen or printer coords– Affine transforms: translate, scale, Affine transforms: translate, scale,

rotate, and shearrotate, and shear

Page 25: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

2525

Java Packages and Java Packages and Protocols:Protocols:Java 3DJava 3D Standard extension to JavaStandard extension to Java

– Not part of “core” Java language like Java 2DNot part of “core” Java language like Java 2D Built on top of Direct3D or OpenGL, Built on top of Direct3D or OpenGL,

depending on platformdepending on platform Scene-graph based model, not primarily Scene-graph based model, not primarily

immediate-mode renderingimmediate-mode rendering

Page 26: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

2626

Java Packages and Protocols:Java Packages and Protocols:Servlets and JavaServer Pages Servlets and JavaServer Pages (JSP)(JSP)

Servlets: Java’s answer to CGIServlets: Java’s answer to CGI– Efficient:Efficient: thread, not process, per request thread, not process, per request– ConvenientConvenient: HTTP headers, cookies, etc.: HTTP headers, cookies, etc.– Powerful:Powerful: persistence, session tracking, etc. persistence, session tracking, etc.– Secure:Secure: no buffer overflows or shell escapes no buffer overflows or shell escapes

Supported by virtually all Web servers:Supported by virtually all Web servers:– Native support: Netscape/iPlanet, IBM WebSphere, Native support: Netscape/iPlanet, IBM WebSphere,

Oracle 8i/9i and Oracle Application Server, BEA Oracle 8i/9i and Oracle Application Server, BEA WebLogic, Silverstream, Sapphire/Web, etc. WebLogic, Silverstream, Sapphire/Web, etc.

– Via add-on engine: Apache, Microsoft IIS and Via add-on engine: Apache, Microsoft IIS and Personal WebServer, Netscape FastTrack, O’Reilly Personal WebServer, Netscape FastTrack, O’Reilly WebSite, StarNine WebSTAR for MacOS, etc.WebSite, StarNine WebSTAR for MacOS, etc.

JavaServer Pages (JSP)JavaServer Pages (JSP)– Convenient and efficient way to combine servlets Convenient and efficient way to combine servlets

and HTML. Portable alternative to ASP & and HTML. Portable alternative to ASP & ColdFusion.ColdFusion.

Page 27: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

2727

Java Packages and Java Packages and Protocols:Protocols:Enterprise JavaBeans (EJB)Enterprise JavaBeans (EJB) EJBs are to server components EJBs are to server components

what regular JavaBeans are to what regular JavaBeans are to application componentsapplication components

Standardizes access to Standardizes access to services like load balancing, services like load balancing, persistence, failover, etc. persistence, failover, etc.

Builds on JavaBeans, CORBA, and RMI Builds on JavaBeans, CORBA, and RMI “under the hood”“under the hood”

Potentially accessible via non-Java programsPotentially accessible via non-Java programs Application Servers Supporting EJBApplication Servers Supporting EJB

– BEA WebLogic, IBM WebSphere, Netscape, Oracle, BEA WebLogic, IBM WebSphere, Netscape, Oracle, Progress SW Apptivity, NetDynamics, Sybase, Progress SW Apptivity, NetDynamics, Sybase, Bluestone Saphire/Web etc.Bluestone Saphire/Web etc.

Page 28: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

The Future of JavaThe Future of Java

Core languageCore language– Java 2 (aka JDK 1.2-1.4) released for Windows in Dec Java 2 (aka JDK 1.2-1.4) released for Windows in Dec

‘98. Richer set of GUI controls, better drawing model, ‘98. Richer set of GUI controls, better drawing model, extensive data structure library (“collections”), better extensive data structure library (“collections”), better audio support, standard CORBA interface, better audio support, standard CORBA interface, better performance. Last core language change for several performance. Last core language change for several years.years.

Standard extensionsStandard extensions– Servlets, JSP, Jini, JAXP, etc. Continue to evolve rapidly.Servlets, JSP, Jini, JAXP, etc. Continue to evolve rapidly.

Java on the server: current growth is hereJava on the server: current growth is here Java for small devices and embedded appsJava for small devices and embedded apps

– Java 2 Micro Edition (PDAs, cell phones, etc.), JavaCardJava 2 Micro Edition (PDAs, cell phones, etc.), JavaCard– Future of Real-Time Java is still unknown (www.rtj.org)Future of Real-Time Java is still unknown (www.rtj.org)

Legal battles over?Legal battles over?

Page 29: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

The Future of Java:The Future of Java:More GrowthMore Growth

0

100,000,000

200,000,000

300,000,000

400,000,000

500,000,000

600,000,000

700,000,000

800,000,000

900,000,000

1,000,000,000

1996

1997

1998

1999

2000

Web Documents On-Line Java Programs On-Line

0

200,000

400,000

600,000

800,000

1,000,000

1,200,000

1/96

5/96

9/96

1/97

5/97

Page 30: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

The Future of Java:The Future of Java:More JobsMore Jobs Even in economic downturn, most Even in economic downturn, most

companies that do large amounts of companies that do large amounts of software development have shortages of software development have shortages of Java developersJava developers

IBM has over 2,500 professionals involved IBM has over 2,500 professionals involved

with Java product developmentwith Java product development Seen on a blackboard in the background Seen on a blackboard in the background

of a video clip at the JavaOne conference:of a video clip at the JavaOne conference: if (you.canRead(this))if (you.canRead(this)) you.canGet(new Job(!problem));you.canGet(new Job(!problem));

Page 31: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3131

Which Java Version Which Java Version Should Should You Use?You Use? AppletsApplets

– Use JDK 1.1 if you want to support the WWW at large.Use JDK 1.1 if you want to support the WWW at large.– Internet Explorer 4.0 and later and Netscape 4.06 and Internet Explorer 4.0 and later and Netscape 4.06 and

later support JDK 1.1. Netscape 6 supports JDK 1.3.later support JDK 1.1. Netscape 6 supports JDK 1.3.– Java Plug-In is required if you want to use Java 2 on a Java Plug-In is required if you want to use Java 2 on a

browser other than Netscape 6.browser other than Netscape 6. ApplicationsApplications

– For standard applications use JDK 1.3 or 1.4 (known as For standard applications use JDK 1.3 or 1.4 (known as Java 2, Standard Edition)Java 2, Standard Edition)

Common ApproachCommon Approach– Use JDK 1.4 everywhere, but bookmark the JDK 1.1 API Use JDK 1.4 everywhere, but bookmark the JDK 1.1 API

to check available methods when writing applets.to check available methods when writing applets. For class, it is fine to use JDK 1.4 and Internet Explorer 5.For class, it is fine to use JDK 1.4 and Internet Explorer 5.

Page 32: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3232

JDK 1.1JDK 1.1

Page 33: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3333

Java 2Java 2

Page 34: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3434

Getting Started: Nuts and Getting Started: Nuts and BoltsBolts

Install a Java-Enabled BrowserInstall a Java-Enabled Browser– Netscape NavigatorNetscape Navigator

http://home.netscape.com/download/http://home.netscape.com/download/

– Microsoft Internet ExplorerMicrosoft Internet Explorer http://www.microsoft.com/ie/download/http://www.microsoft.com/ie/download/

Install JavaInstall Java– JDK 1.3: http://java.sun.com/j2se/1.3/JDK 1.3: http://java.sun.com/j2se/1.3/

If you install after installing browser, system will If you install after installing browser, system will install plugin automatically.install plugin automatically.

– JDK 1.4: http://java.sun.com/j2se/1.4/JDK 1.4: http://java.sun.com/j2se/1.4/– JDK 1.1: JDK 1.1:

http://java.sun.com/products/jdk/1.1/http://java.sun.com/products/jdk/1.1/

Page 35: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3535

Getting Started: Getting Started: DetailsDetails Create the FileCreate the File

– Write and save a file (say Write and save a file (say Test.javaTest.java) that defines ) that defines public class public class TestTest

– File and class names are case sensitive and must File and class names are case sensitive and must match exactlymatch exactly

Compile the programCompile the program– Compile Test.java throughCompile Test.java through

> javac Test.java> javac Test.java This step creates a file called Test.classThis step creates a file called Test.class

– If you get a “deprecation” warning, this means you If you get a “deprecation” warning, this means you are using a Java construct that has a newer are using a Java construct that has a newer alternative (ie it still works but is not recommended)alternative (ie it still works but is not recommended)

Use “javac -deprecation Test.java” for an explanation, Use “javac -deprecation Test.java” for an explanation, then look the newer construct up in the on-line API then look the newer construct up in the on-line API

Page 36: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3636

Getting Started: Getting Started: DetailsDetails(Continued)(Continued) Run the programRun the program

– For a stand-alone application, run it For a stand-alone application, run it with with

> java Test> java Test

Note that the command is Note that the command is javajava, not , not javacjavac, , and that you refer to and that you refer to TestTest, not , not Test.classTest.class

– For an applet that will run in a browser, For an applet that will run in a browser, run it by loading the HTML page that run it by loading the HTML page that refers to it refers to it

Page 37: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3737

Basic Hello World Basic Hello World ApplicationApplication ““Application” is Java lingo for a stand-alone Java Application” is Java lingo for a stand-alone Java

programprogram– Note that the class name and the filename Note that the class name and the filename mustmust match match– A file can contain multiple classes, but only one can be A file can contain multiple classes, but only one can be

declared public, and that one’s name must match the declared public, and that one’s name must match the filenamefilename

File HelloWorld.java:File HelloWorld.java:public classpublic class HelloWorldHelloWorld {{ publicpublic staticstatic voidvoid mainmain(String[] args) (String[] args)

{{ System.out.println("Hello, world.");System.out.println("Hello, world."); }}}}

Page 38: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3838

Basic Hello World Basic Hello World Application Application (Continued)(Continued) Compiling:Compiling: javacjavac HelloWorld.java HelloWorld.java

Running:Running: javajava HelloWorld HelloWorld

Output:Output: Hello, world.Hello, world.

Page 39: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

3939

Command Line Command Line ArgumentsArguments File ShowArgs.java:File ShowArgs.java:

public public class class ShowArgs {ShowArgs {

public public staticstatic void void main(String[] args) {main(String[] args) {

for(int i=0; i<args.length; i++) {for(int i=0; i<args.length; i++) {

System.out.println("Arg " + i + " is " + args[i]);System.out.println("Arg " + i + " is " + args[i]);

}}

}}

}}

Differences from CDifferences from C– In Java, String is a real typeIn Java, String is a real type– Java arrays have an associated lengthJava arrays have an associated length– The filename is not part of the command line The filename is not part of the command line

argumentsarguments

Page 40: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

4040

Command Line Command Line Arguments, ResultsArguments, Results Compiling and Running:Compiling and Running:

> javac ShowArgs.java> javac ShowArgs.java

> java ShowArgs fee fie foe fum> java ShowArgs fee fie foe fumArg 0 is feeArg 0 is feeArg 1 is fieArg 1 is fieArg 2 is foeArg 2 is foeArg 3 is fumArg 3 is fum

Page 41: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

4141

Basic Hello WWW Basic Hello WWW AppletApplet File HelloWWW.java:File HelloWWW.java:

importimport java.applet.Applet; java.applet.Applet;importimport java.awt.*; java.awt.*;

publicpublic classclass HelloWWW HelloWWW extends Appletextends Applet { { publicpublic voidvoid init() { init() { setBackground(Color.gray);setBackground(Color.gray); setForeground(Color.white);setForeground(Color.white); setFont(new Font("SansSerif", Font.BOLD, 30));setFont(new Font("SansSerif", Font.BOLD, 30)); }} publicpublic voidvoid paint(Graphics g) { paint(Graphics g) { g.drawString("Hello, World Wide Web.", 5, 35);g.drawString("Hello, World Wide Web.", 5, 35); }}} }

Page 42: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

4242

Basic Hello WWW Basic Hello WWW Applet (Continued)Applet (Continued) File HelloWWW.html:File HelloWWW.html:

<HTML><HEAD><HTML><HEAD> <TITLE>HelloWWW: Simple Applet Test.</TITLE><TITLE>HelloWWW: Simple Applet Test.</TITLE></HEAD></HEAD>

<BODY><BODY><H1>HelloWWW: Simple Applet Test.</H1><H1>HelloWWW: Simple Applet Test.</H1>

<APPLET CODE="HelloWWW.class" WIDTH=400 <APPLET CODE="HelloWWW.class" WIDTH=400 HEIGHT=40>HEIGHT=40>

<B>Error! You must use a Java enabled <B>Error! You must use a Java enabled browser.</B>browser.</B>

</APPLET></APPLET></BODY></HTML></BODY></HTML>

Page 43: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

4343

Basic Hello WWW Basic Hello WWW Applet (Continued)Applet (Continued) Compiling:Compiling:

javac HelloWWW.javajavac HelloWWW.java

Running:Running:Load Load HelloWWW.htmlHelloWWW.html in a Java-enabled browser in a Java-enabled browser

Page 44: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

4444

Customizing Applets with Customizing Applets with PARAMPARAMimportimport java.applet.Applet; java.applet.Applet;importimport java.awt.*; java.awt.*;

publicpublic class Message extends Applet { class Message extends Applet { private int fontSize;private int fontSize; private String message;private String message; publicpublic void init() { void init() { setBackground(Color.black);setBackground(Color.black); setForeground(Color.white);setForeground(Color.white); fontSize = getSize().height - 10; fontSize = getSize().height - 10; setFont(new Font("SansSerif", Font.BOLD, setFont(new Font("SansSerif", Font.BOLD,

fontSize));fontSize)); // Read heading message from PARAM entry in // Read heading message from PARAM entry in

HTML.HTML. message = getParameter("MESSAGE");message = getParameter("MESSAGE"); }} publicpublic void paint(Graphics g) { void paint(Graphics g) { if (message != null)if (message != null) g.drawString(message, 5, fontSize+5);g.drawString(message, 5, fontSize+5); }}}}

Page 45: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

4545

Customizing Applets Customizing Applets with PARAM, cont.with PARAM, cont.

<html><head><html><head> <title>The Message Applet</title><title>The Message Applet</title></head></head><body><body><h1>The <code>Message</code> Applet</h1><h1>The <code>Message</code> Applet</h1><p><p><applet<applet code="Message.class"code="Message.class" width=325 height=25> width=325 height=25> <<paramparam name="MESSAGE" name="MESSAGE" valuevalue="Tiny"="Tiny">> <b>Sorry, these examples require Java</b><b>Sorry, these examples require Java</b></applet></applet><p><p><applet code="Message.class" width=325 height=50><applet code="Message.class" width=325 height=50> <<paramparam name="MESSAGE" name="MESSAGE" valuevalue="Small">="Small"> <b>Sorry, these examples require Java</b><b>Sorry, these examples require Java</b></applet></applet>......</body></html></body></html>

Page 46: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

4646

SummarySummary

Java is a complete language, supporting both Java is a complete language, supporting both standalone applications and Web developmentstandalone applications and Web development

Java is compiled to bytecode and can be run Java is compiled to bytecode and can be run on any platform that supports a Java Virtual on any platform that supports a Java Virtual MachineMachine

Java 2 Platform is available in a Standard Java 2 Platform is available in a Standard Edition, Enterprise Edition, or Micro EditionEdition, Enterprise Edition, or Micro Edition

Most browsers support only JDK 1.1Most browsers support only JDK 1.1 Compiling: use “javac”Compiling: use “javac” Executing standalone programs: use “java”Executing standalone programs: use “java” Executing applets: load HTML file in browserExecuting applets: load HTML file in browser

Page 47: Introduction to Java INE2720 Web Application Software Development Essential Materials.

INE2720 – Web Application Software INE2720 – Web Application Software DevelopmentDevelopment

All copyrights reserved by C.C. Cheung All copyrights reserved by C.C. Cheung 2003.2003.

4747

ReferencesReferences

CWP: Chapter 6CWP: Chapter 6 http://java.sun.comhttp://java.sun.com

The End.The End. Thank you for patience!Thank you for patience!