1 / 29

Java Tutorial Ethan Cerami @1998 New York University

Java Tutorial Ethan Cerami @1998 New York University. Road Map. What is Java? Why is Java Important? Strengths, Weaknesses Java Tutorial: Creating an Applet Cool Examples/Demos Future of Java. I. What is Java?. Java is a new Internet programming language.

hogg
Download Presentation

Java Tutorial Ethan Cerami @1998 New York University

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. Java Tutorial Ethan Cerami @1998 New York University

  2. Road Map • What is Java? • Why is Java Important? • Strengths, Weaknesses • Java Tutorial: Creating an Applet • Cool Examples/Demos • Future of Java

  3. I. What is Java? • Java is a new Internet programming language. • Developed by Sun Microsystems, Inc. • Originally developed for Interactive Television Set-top boxes. • Rapidly becoming the standard for Internet programming.

  4. Evolution of the Web • Phase 1: Everything was in text. Used mainly by academics and government. • Phase 2: Simple, graphical user interface. • Mosaic and Netscape. • Used by millions of people. • Phase 3: Interactive Applications and Web Pages. • Where we are today.

  5. Applets • Applets: mini Java applications that can be embedded inside a web page. Big Text Smaller Text Clock Applet

  6. Some Basic Examples • Scrolling Ticker • “Bouncing Heads” • Simple Video Games

  7. II. Why is Java Important? • Enables the distribution of applications across the Internet. • As a language, Java also has many important strengths: • Object Oriented • Built-in Security • Built-in Networking • Platform Independent • Built-in Multithreading

  8. Feature #1: Object Oriented • Object Oriented languages enable the creation of large applications that are easy to maintain. Scrolling Ticker Object Clock Object Weather Object

  9. Feature #2: Built-In Security • If you download an application across the Internet, the program might do malicious things: deleting files, reading sensitive data, etc. . Operating System: Read, write, delete files Java Security Sandbox Restricted Access

  10. Feature #3: Networking • It is extremely easy to create network applications in Java. • Java was built from the ground up to work with the Internet.

  11. Feature #4: Portable • Java is Platform independent: Runs on any platform - Windows, Macintosh, UNIX. • “Write once, run anywhere.” • Create a single application and it can run anywhere on the Internet.

  12. Feature #5: Multithreading • You can create applications that do more than one thing at a time. • For example, you can have an animation and a sound at the same time. • Important for animations and network applications.

  13. Java Virtual Machine Java Applet C/C++ Program Java Virtual Machine Operating System Operating System

  14. Java Performance • The Achilles Heal of Java • When Java was first released, it was about 20 times slower than native applications written in C/C++. • Now, it’s about half the speed of C/C++. But, it really depends on the Browser and the Platform.

  15. III. Java Tutorial • Once you understand the basics of Java, creating an Applet is straightforward. • In order to create an applet, you first need to download a Java Compiler. • Download the Java Development Kit (JDK) 1.1 from java.sun.com

  16. Object Oriented Basics • Every object has two things: • Some Data • Some Methods (or functions) • For example, a scrolling ticker object might have: • The Text to be displayed. • A method called animate() that tells the object to start scrolling.

  17. The Applet Object • The Applet objects contains: • Data regarding the Web Browser. • Methods for creating applications. • Some methods: • getImage (): Retrieves an image • paint (): Paint on a canvas • getAudioClip(): Retrieves a sound file

  18. Hello World! import java.applet.*; import java.awt.*; // This applet prints Hello public class FirstApplet extends Applet { // The method paints the applet public void paint (Graphics g) { g.drawString ("Hello, World!", 25, 50); } }

  19. Import/Comments • Import statement tells the Compiler to load certain libraries: • similar to the #include statement in C. • import java.applet.*; • import java.awt.*; (Abrstract Windowing Toolkit. Useful for using widgets and graphics) • Comments are denoted with // • // This is a comment.

  20. Extending Applet • public class FirstApplet extends Applet { • This tells the compiler that you want to create an Applet object. Called FirstApplet. • This really relates to object oriented inheritance (which we don’t have time to discuss.)

  21. Drawing Graphics • paint method: • Responsible for all graphics painting inside the applet. • g.drawString (“Hello World”, 25, 50); X Coordinate Y Coordinate

  22. To View your Applet • First you need to compile your applet: • javac FirstApplet.java • Then, you need to create a simple HTML page: <APPLET code="FirstApplet.class" width=150 height=100></APPLET>

  23. Hello World, Version 2.0 import java.applet.*; import java.awt.*; // This applet prints Hello, Version 2.0 public class SecondApplet extends Applet { // The method paints the applet public void paint (Graphics g) { g.setColor (Color.pink); g.fillOval (10,10,330,100); g.setColor (Color.black); g.drawOval (10,10,328,100); g.setFont (new Font("Helvetica", Font.BOLD, 48)); g.drawString ("Hello, World", 40, 75); } }

  24. To View the Second Applet • HTML Page: <APPLET code="SecondApplet.class" width=350 height=125></APPLET>

  25. IV. Cool Examples • The Molecule Viewer: • http://java.sun.com/nav/whatis/cherwell.html • Wired Stock Graphing Tool: • http://stocks.wired.com • 3D Ray: • http://www.2nu.com/Wayne/SplattJava/SplattJava480x300.html • Games: • http://www.comedycentral.com/southpark/cartman/cartman.htm

  26. The Future of Java • To answer this question, you have to look at two elements: • What can you do with Java? What kind of added functionality will we see? • Where can you actually run Java? What comes after the Applet?

  27. Java 1.2 • Current Release: Java 1.2 (Beta) Most browsers only support Version 1.0 • What’s new in Java 1.2: • Java Foundation Classes (Swing) • Java 2D, 3D • Java Sound • Java Speech

  28. Java Everywhere • Java can run on any platform. • Embedded Java: • Java Rings • Java Smart Cards • Java Telephones • Java Televisions • Java light switches

  29. One Java or Many? • Sun wants Java to be an open standard that can run on any platform. • Microsoft hates Java. Has created a slightly different version that is optimized for Windows.

More Related