1 / 44

Introduction to JAVA

Introduction to JAVA. Instructor : Simon Hui & Louis Wong Industrial Centre The Hong Kong Polytechnic University Sep, 2002. Physics. Optics http://158.132.155.24/javaintro/physics/physics_1.htm Plane Pendulum http://158.132.155.24/javaintro/physics/physics_2.htm Interference

mirra
Download Presentation

Introduction to JAVA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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/physics_1.htm • Plane Pendulum http://158.132.155.24/javaintro/physics/physics_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=ax2+bx+c • Manipulate Math with Java http://www.ies.co.jp/math/java/index.html E.g Calculus Derivative of y=x2

  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/courses/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. 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. Java vs JavaScript

  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 1 public class JavaApplication { Line 2public 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 1import java.awt.*; Line 2import java.applet.Applet; Line 3public class JavaApplet extends Applet{ Line 4public void paint(Graphics g) { Line 5g.drawString("HelloWorld",25,50); Line 6} Line 7} HTML Code <Applet code=“JavaApplet.class” Width=200 Height=200 file=“abc.jpg”> </Applet>

  18. Java Applet (HTML Interface) • HTML may pass information to Java via applet tag. HTML: <Applet code=“JavaApplet.class” Width=200 Height=200 file=“abc.jpg”> </Applet> 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. Java 2 Enterprise Edition • 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/

  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("<html>"); out.println("<body>"); out.println("<head>"); out.println("<title>Hello World!</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Hello World!</h1>"); out.println("</body>"); out.println("</html>"); } }

  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 <%@ page session=false %> Line2 <% Line3 String title = "Hello, world!"; Line4 %> Line5 <head> Line6 <title><%= title %></title> Line7 </head> Line8 <body bgcolor=white> Line9 <h1><%= title %></h1> Line10 </body>

  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

  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 Interferencehttp://ciu.ic.polyu.edu.hk/course/offline/Wave%20Interference.htm • NTNU Virtual Physics Laboratoryhttp://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 • Snapple Good Fruit! Bad Fruit http://www.snapple.com/play/fruit.htm

More Related