01Java Intro

Information about 01Java Intro

Published on November 20, 2007

Author: Savina

Source: authorstream.com

Content

Java is Web-Enabled?:  Java is Web-Enabled? Myth: Java is only for the Web Java “applets” run in Web pages Java “applications” run stand-alone Current usage (roughly) Client (applet): 5% Desktop (application): 45% Server (servlets/JSP/EJB): 50% Java is Safe?:  Java is Safe? Truth: Restrictions on permissible operations can be enforced No “raw” memory manipulation (directly or indirectly). Thus, it is easy to identify prohibited operations. Applets, by default, prohibited from: Reading from the local disk Writing to the local disk Executing local programs Opening network connections other than to HTTP server Discovering private info about user (username, directories, OS patch level, applications installed, etc.). Java is Cross-Platform?:  Compile Time Run Time Java is Cross-Platform? Truth: Java programs can compile to machine-independent bytecode Truth: All major operating systems have Java runtime environments Most bundle it (Solaris, MacOS, Windows 2000, OS/2) Java is Cross-Platform?:  Java is Cross-Platform? Myth: Safety and machine independence can be achieved with no performance penalty Current systems are about 20% slower than C++ Upcoming releases claim to lower or eliminate that gap Expect the gap to stay at 10% or more Myth: Java is interpreted Early releases were interpreted Many major “Just in Time” (JIT) compilers HotSpot and “native” compilers even faster (IBM, Symantec, TowerJ, etc.) Java is Cross-Platform?:  Truth: Java has a portable graphics library “Native look & feel” -- Java 1.1 UI controls adapt to OS 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?:  Java is Cross-Platform? Myth: Write Once Run Anywhere Cross-platform code can be achieved, but you must test on all platforms you will deliver on. Java applications can execute local code The graphics library behaves slightly differently on different platforms The behavior of the thread scheduler is only loosely defined Myth: Java will kill Microsoft There is also no longer immediate danger of the reverse (Microsoft killing Java) Microsoft wavered between trying to fight Java and joining it and making money by dominating the market. With .NET, they are back to fighting it again. Java is Simple?:  Java is Simple? Truth: Java greatly simplifies several language features Java has automatic memory management Does Windows and takes out the garbage No dangling pointers. No memory leaks. A problem for real-time programs Java simplifies pointer handling No explicit reference/dereference operations Everything is a pointer (like Lisp) No makefiles No header files C++ syntax streamlined Java is Powerful?:  Java is Powerful? Truth: Java has a rich set of standard libraries Networking Threads (lightweight processes) Distributed objects Database access Graphics: GUI controls and drawing Data structure library Arbitrary precision integral and fixed-point arithmetic Digital signatures Serialization (transmitting/reassembling data structures) File and stream compression Java is Powerful?:  Java is Powerful? Myth: Java will increase programmer productivity for all applications by XXX%. Myth: Java will kill C++ Myth: All software should be written in Java Unix utilities: C Small/medium Windows-only programs: Visual Basic String parsing: Perl High-performance, single-platform OO systems: C++ Air traffic control, aircraft flight software: Ada Knowledge-based systems: Lisp/CLOS Key Java Packages and Protocols:  Key Java Packages and Protocols Core Technologies JDBC RMI Jini (Device Networking) JavaBeans Swing Java 2D Standard Extensions Servlets and JavaServer Pages (JSP) Enterprise Java Beans Java 3D Java Packages and Protocols: JDBC (Java DataBase Connectivity):  Java Packages and Protocols: JDBC (Java DataBase Connectivity) Standardizes mechanism for making connection to database server Requires server-specific driver on client. No change to server. Standardizes mechanism for sending queries Either regular or parameterized queries (stored procedures) Standardizes data structure of query result Assumes relational data, so data structure is a table Does not standardize SQL syntax Queries are simply strings Server extensions and enhancements supported Java Packages and Protocols: Remote Method Invocation (RMI):  Java Packages and Protocols: Remote Method Invocation (RMI) Built-in Distributed Object Protocol RMI lets a developer access a Java object and manipulate it in the normal manner. Behind the scenes, each function call really goes over the network to a remote object. Arbitrary Java data structures can be sent over the network with little or no special packaging, due to Java’s “serialization” mechanism Similar to a simplified CORBA, but restricted to Java-to-Java communication Jini RMI-based protocol for self-documenting services. Allows real “plug and play” devices -- no separate drivers Jury is out on eventual success. Security and industry adoption are open questions. Java Packages and Protocols: JavaBeans:  Java Packages and Protocols: JavaBeans JavaBeans is to Java as ActiveX is to Visual C++. Lets you package a Java program as a software “component” Visual tools can modify/manipulate it without knowing anything about it in advance For example, you can drop a Bean into Visual Café, IBM VisualAge for Java, Inprise (Borland) JBuilder, Sybase PowerJ, Metrowerks CodeWarrior, Sun JavaWorkshop, etc., and it is automatically available from their tool palette for drag-and-drop development Better security and portability than ActiveX More ActiveX components available Java Packages and Protocols: Swing:  Java Packages and Protocols: Swing Standard GUI-control (widget) library in Java 2 Many more built-in controls Much more flexible and customizable Includes many small features aimed at commercial applications Tooltips, tabbed panes, on-line help, HTML support, dockable toolbars, multi-document interface, etc. Look and feel can be changed at run time Java Packages and Protocols: Servlets and JavaServer Pages (JSP):  Java Packages and Protocols: Servlets and JavaServer Pages (JSP) Servlets: Java’s answer to CGI Efficient: thread, not process, per request Convenient: HTTP headers, cookies, etc. Powerful: persistence, session tracking, etc. Secure: no buffer overflows or shell escapes Supported by virtually all Web servers: Native support: Netscape/iPlanet, IBM WebSphere, Oracle 8i/9i and Oracle Application Server, BEA WebLogic, Silverstream, Sapphire/Web, etc. Via add-on engine: Apache, Microsoft IIS and Personal WebServer, Netscape FastTrack, O’Reilly WebSite, StarNine WebSTAR for MacOS, etc. JavaServer Pages (JSP) Convenient and efficient way to combine servlets and HTML. Portable alternative to ASP & ColdFusion. Java Packages and Protocols: Enterprise JavaBeans (EJB):  Java Packages and Protocols: Enterprise JavaBeans (EJB) EJBs are to server components what regular JavaBeans are to application components Standardizes access to services like load balancing, persistence, failover, etc. Builds on JavaBeans, CORBA, and RMI “under the hood” Potentially accessible via non-Java programs Application Servers Supporting EJB BEA WebLogic, IBM WebSphere, Netscape, Oracle, Progress SW Apptivity, NetDynamics, Sybase, Bluestone Saphire/Web etc. Basic Hello World Application:  Basic Hello World Application “Application” is Java lingo for a stand-alone Java program Note that the class name and the filename must match A file can contain multiple classes, but only one can be declared public, and that one’s name must match the filename File HelloWorld.java: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world."); } } Basic Hello World Application (Continued):  Basic Hello World Application (Continued) Compiling: javac HelloWorld.java Running: java HelloWorld Output: Hello, world. Command Line Arguments:  Command Line Arguments File ShowArgs.java: public class ShowArgs { public static void main(String[] args) { for(int i=0; i<args.length; i++) { System.out.println("Arg " + i + " is " + args[i]); } } } Command Line Arguments, Results:  Command Line Arguments, Results Compiling and Running: > javac ShowArgs.java > java ShowArgs fee fie foe fum Arg 0 is fee Arg 1 is fie Arg 2 is foe Arg 3 is fum Basic Hello WWW Applet:  Basic Hello WWW Applet File HelloWWW.java: import java.applet.Applet; import java.awt.*; public class HelloWWW extends Applet { public void init() { setBackground(Color.gray); setForeground(Color.white); setFont(new Font("SansSerif", Font.BOLD, 30)); } public void paint(Graphics g) { g.drawString("Hello, World Wide Web.", 5, 35); //5=left, 35=bottom } } Basic Hello WWW Applet (Continued):  Basic Hello WWW Applet (Continued) File HelloWWW.html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>HelloWWW: Simple Applet Test.</TITLE> </HEAD> <BODY> <H1>HelloWWW: Simple Applet Test.</H1> <APPLET CODE="HelloWWW.class" WIDTH=400 HEIGHT=40> <B>Error! You must use a Java enabled browser.</B> </APPLET> </BODY> </HTML> Basic Hello WWW Applet (Continued):  Basic Hello WWW Applet (Continued) Compiling: javac HelloWWW.java Running: Load HelloWWW.html in a Java-enabled browser Customizing Applets with PARAM:  Customizing Applets with PARAM import java.applet.Applet; import java.awt.*; public class Message extends Applet { private int fontSize; private String message; public void init() { setBackground(Color.black); setForeground(Color.white); fontSize = getSize().height - 10; setFont(new Font("SansSerif", Font.BOLD, fontSize)); // Read heading message from PARAM entry in HTML. message = getParameter("MESSAGE"); } public void paint(Graphics g) { if (message != null) g.drawString(message, 5, fontSize+5); } } Customizing Applets with PARAM, cont.:  Customizing Applets with PARAM, cont. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>The Message Applet</TITLE> </HEAD> <BODY BGCOLOR="WHITE"> <H1>The <CODE>Message</CODE> Applet</H1> <P> <APPLET CODE="Message.class" WIDTH=325 HEIGHT=25> <PARAM NAME="MESSAGE" VALUE="Tiny"> <B>Sorry, these examples require Java</B> </APPLET> <P> <APPLET CODE="Message.class" WIDTH=325 HEIGHT=50> <PARAM NAME="MESSAGE" VALUE="Small"> <B>Sorry, these examples require Java</B> </APPLET> ... </BODY> </HTML> Customizing Applets with PARAM, Result:  Customizing Applets with PARAM, Result Summary:  Summary Java is a complete language, supporting both standalone applications and Web development Java is compiled to bytecode and can be run on any platform that supports a Java Virtual Machine Java 2 Platform is available in a Standard Edition, Enterprise Edition, or Micro Edition Compiling: use “javac” Executing standalone programs: use “java” Executing applets: load HTML file in browser

Related presentations


Other presentations created by Savina

Agriculture and Village life
04. 10. 2007
0 views

Agriculture and Village life

212angiosperms
12. 12. 2007
0 views

212angiosperms

notes northafricaswasia
25. 10. 2007
0 views

notes northafricaswasia

accesstf2006
25. 10. 2007
0 views

accesstf2006

COLOSSEUM
31. 10. 2007
0 views

COLOSSEUM

paint
06. 11. 2007
0 views

paint

The Triangular Trade
07. 11. 2007
0 views

The Triangular Trade

Intervertebral
19. 11. 2007
0 views

Intervertebral

3GR
01. 12. 2007
0 views

3GR

innovative
17. 12. 2007
0 views

innovative

ECML05 OLTutorial
05. 11. 2007
0 views

ECML05 OLTutorial

Facebook b
24. 12. 2007
0 views

Facebook b

La Rome antique
30. 10. 2007
0 views

La Rome antique

whyfamine
31. 12. 2007
0 views

whyfamine

oxymoron sediments
01. 01. 2008
0 views

oxymoron sediments

cryptography presentation
02. 01. 2008
0 views

cryptography presentation

robotics part1
04. 01. 2008
0 views

robotics part1

Dunkle
07. 01. 2008
0 views

Dunkle

Earth Science Review
09. 10. 2007
0 views

Earth Science Review

Lect24
02. 01. 2008
0 views

Lect24

Lect5
26. 11. 2007
0 views

Lect5

20070731150020Anita Wreford
23. 11. 2007
0 views

20070731150020Anita Wreford

25 Connections V5 p1
02. 11. 2007
0 views

25 Connections V5 p1

FalckeActive
29. 11. 2007
0 views

FalckeActive

OSU StateBoard Feb23
24. 10. 2007
0 views

OSU StateBoard Feb23

Alfonsi uampy EOI551
06. 11. 2007
0 views

Alfonsi uampy EOI551

6apr asbury tsmcern
29. 10. 2007
0 views

6apr asbury tsmcern

WAS meeting 2003F
12. 11. 2007
0 views

WAS meeting 2003F

pres 2800
20. 02. 2008
0 views

pres 2800

ssm feb04
24. 02. 2008
0 views

ssm feb04

USDA Sulfur Poster
05. 03. 2008
0 views

USDA Sulfur Poster

DFASTransformation
31. 10. 2007
0 views

DFASTransformation

OrganicAgriculture20 05
27. 03. 2008
0 views

OrganicAgriculture20 05

christine lee
30. 03. 2008
0 views

christine lee

McNabs Island Presentation
18. 12. 2007
0 views

McNabs Island Presentation

concepts2
03. 01. 2008
0 views

concepts2

2180overhead02
13. 04. 2008
0 views

2180overhead02

softwood
29. 10. 2007
0 views

softwood

IENE Athens Nov 2006
23. 11. 2007
0 views

IENE Athens Nov 2006

Renacimiento
01. 10. 2007
0 views

Renacimiento

Presentacion Folleto VW
16. 11. 2007
0 views

Presentacion Folleto VW

romanrepublic
01. 11. 2007
0 views

romanrepublic

aship
05. 11. 2007
0 views

aship

Criptografia
05. 01. 2008
0 views

Criptografia

Outlining
16. 11. 2007
0 views

Outlining

TNC 050225
21. 11. 2007
0 views

TNC 050225

Pan Awareness Vedanta
13. 12. 2007
0 views

Pan Awareness Vedanta