Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to JAVA Instructor : Simon Hui & Louis Wong Industrial Centre The Hong Kong Polytechnic University Sep, 2002.

Similar presentations


Presentation on theme: "Introduction to JAVA Instructor : Simon Hui & Louis Wong Industrial Centre The Hong Kong Polytechnic University Sep, 2002."— Presentation transcript:

1 Introduction to JAVA Instructor : Simon Hui & Louis Wong Industrial Centre The Hong Kong Polytechnic University Sep, 2002

2 Physics Optics http://158.132.155.24/javaintro/physics/physic s_1.htm Plane Pendulum http://158.132.155.24/javaintro/physics/physic s_2.htm Interference http://members.tripod.com/~vsg/interfer.htm

3 Mathematics Javasketchpad http://home.netvigator.com/~wingkei9/javagsp /javagsp.html E.g the graph of y=ax 2 +bx+c Manipulate Math with Java http://www.ies.co.jp/math/java/index.html E.g Calculus Derivative of y=x 2

4 Chemistry Thermochemistry and the microscopic behavior of molecules http://mc2.cchem.berkeley.edu/Java/ E.g Molecules in Motion Orientation of d-orbitals http://wwwchem.uwimona.edu.jm:1104/cours es/CFTpt2.html

5 Overview The growth in the popularity of the Internet. Internet application. E.g. Client and server programming. Request middleware to communicate between clients and database. Need Active content. Specific browser configuration.

6 What is Java? A programming language. Well suited for use with the Internet. Create an active and dynamic content web pages. Client/server programming.

7 What is Java? Used for middleware to communicate between client and server. Write once run anywhere. Similar to C++, C.

8 Java Features Simple Object-Oriented Distributed Multithreaded Secure Portable Free of charges

9 Advantages of Java Platform independence Similar to syntax of C++ Fully object oriented (multiple inheritances) Secure Dynamic Multithreaded

10 Java vs JavaScript Java vs JavaScript For various programming. A compiled language. Compiled into Applet (separate from HTML). Programming language Web programming only. Not a compiled language. Embedded directly in HTML. Scripting language.

11 Java Virtual Machine Developed by Sun Microsystems Run Java Program Act as an interface between Java binary code and the microprocessor. Installed in local computer.

12 Java Virtual Machine Compiled the Java program to bytecode. The bytecode can run on any platform. Virtual Machine interprets the bytecode one instruction at a time.

13 Advantages of Java Virtual Machine Java code is really small, ideal for transmission over the network. Programmers can design it as simple as they want. Platform independence

14 Java Application Stand-alone program No initial window E.g *.exe (Dos/windows)

15 Java Application (Example) Line 1public class JavaApplication { Line 2 public static void main(String[] args){ Line 3 System.out.println("Welcome to Java Online Course!"); Line 4 } Line 5}

16 Java Applet Run within browser Defined in java.applet package which contains a set of objects. Example http://www.cityline.com.hk

17 Java Applet (Example) JAVA Source Code Line 1 import java.awt.*; Line 2 import java.applet.Applet; Line 3 public class JavaApplet extends Applet{ Line 4 public void paint(Graphics g) { Line 5 g.drawString("HelloWorld",25,50); Line 6 } Line 7 } HTML Code

18 Java Applet (HTML Interface) HTML may pass information to Java via applet tag. HTML: Java: getParameter(“file”); getParameter(“width”);

19 General Web Architecture for Web-based Application

20 Middle tier Presentation Layer –Generates web pages, including dynamic content. –Interprets web pages submitted from the client. Business Logic Layer –Performs validations and handles interaction with the database.

21 Client Layer and Data Layer Client Layer –Renders web pages. Data Layer –Stores data between transactions.

22 Java 2 Enterprise Edition

23 Released in mid of 1999. Provide a comprehensive view of Java middle tier solution. Implement Presentation Layer. –Servlets –JavaServer Pages (JSP) Implement Business Logic layer. –JavaBeans Provide for access by non-web clients. –J2EE’s Remote Method Invocation (RMI)

24 What is CGI? Create dynamic content of web pages. Execute in real-time by the web server.

25 Implementing CGI C C++ Perl ASP (Active Server Page)

26 What is Servlets? Released in 1997. Create web pages with dynamic content Extend the capabilities of Web servers. Standard, server-side Java application that extends the capabilities of a Web Server.

27 What is Servlets? A replacement for CGI scripts. Run inside the Java Virtual Machine on the server. Run on all major web servers. Do not require support for Java in the browser. E.g. https://ebanking.hangseng.com/https://ebanking.hangseng.com/

28 How to create web page with dynamic content? Parse/decode the user-submitted HTML form, handle cookie, etc. Access database directly. Derive their dynamic content via Enterprise Java Beans (runs on an application server).

29 Advantages of Servlets Portability and flexibility Security Performance

30 Example import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorldExample extends HttpServlet { ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(" "); out.println(" Hello World! "); out.println(" "); out.println(" Hello World! "); out.println(" "); }

31 What is JavaServer Page? Released in 1999. Provides another Java-based solution for generating dynamic web pages. Is an extension of the Java Servlet. Mix static HTML with server-side scripting.

32 What is JavaServer Page? Uses XML-like tags and scriptlets written in the Java programming. No a single line of Java code. Example http://www.citibank.com.hk/cgi-bin/bv.cgi/eng/index.jsp

33 Example Line1 Line2<% Line3String title = "Hello, world!"; Line4%> Line5 Line6 Line7 Line8 Line9 Line10

34 Example Surrounds by Provides a number of server-side tags. More simpler than Java servlets

35 Flow of JSP model A request is sent directly to a JSP page. The JSP engine automatically creates, compiles, and executes servlets to implements the behavior of the combined HTML and embedded Java code.

36 Flow of JSP model JSP code can control interactions with JavaBeans components for business and data logic processing Display the results in dynamically generated HTML mixed with a static HTML code.

37 Difference between JSP and Servlets? Translate the JSP into a Servlet. Put HTML and JSP code together and let web server do the translation to servlet code.

38 Java’s Version VersionNo. of classes No. of Packages ReleasedComment 1.02128Jan 1996 1.150423Feb 1997 1.2152059Dec 1998Called “Java 2, Release 1.2” 1.3184076May 2000Called “Java 2, Release 1.3, Standard Edition”

39 Java’s Editor SUN Microsoft

40 Java’s Editor: SUN Java Enterprise Edition (J2EE) –Large Enterprise Web applications Java Standard Edition (J2SE) –Standard Java applet and application Java Micro Edition (J2ME) –For running on small or embedded consumer products, including pagers, cellular phones, digital set-top boxes and etc.

41 Java’s Editor: Microsoft Visual Java ++ 6.0 –Introduces the window Foundation Class for Java (WFC) –Is a new application framework accesses the Microsoft Window API –Writes full-features windows application with the Java programming language.

42 Resources for development Java Boutique http://javaboutique.internet.com Java Resources – The complete webmaster http://abiglime.com/webmaster/articles/java.htm JPowered.com http://www.jpowered.com

43 Educational Resources Interactive Physics and Math with Java http://www.lightlink.com/sergey/java/index.html Molecular dynamic simulation with Java http://ws05.pc.chemie.tu-darmstadt.de/research/molcad/java Constructive and Destructive Wave Interference http://ciu.ic.polyu.edu.hk/course/offline/Wave%20Interference. htm http://ciu.ic.polyu.edu.hk/course/offline/Wave%20Interference. htm NTNU Virtual Physics Laboratory http://www.phy.ntnu.edu.tw/class/demolab/indexTree.html http://www.phy.ntnu.edu.tw/class/demolab/indexTree.html

44 Game writing in Java Maze in 3D http://users.nbn.net/%7Emr_g/java/Maze3D/arcade /maze/maze.htm http://users.nbn.net/%7Emr_g/java/Maze3D/arcade /maze/maze.htm Snapple Good Fruit! Bad Fruit http://www.snapple.com/play/fruit.htm


Download ppt "Introduction to JAVA Instructor : Simon Hui & Louis Wong Industrial Centre The Hong Kong Polytechnic University Sep, 2002."

Similar presentations


Ads by Google