Download presentation
Presentation is loading. Please wait.
2
Java Tutorial Ethan Cerami @1998 New York University
3
Road Map n What is Java? n Why is Java Important? –Strengths, Weaknesses n Java Tutorial: Creating an Applet n Cool Examples/Demos n Future of Java
4
I. What is Java? n Java is a new Internet programming language. n Developed by Sun Microsystems, Inc. n Originally developed for Interactive Television Set-top boxes. n Rapidly becoming the standard for Internet programming.
5
Evolution of the Web n Phase 1: Everything was in text. Used mainly by academics and government. n Phase 2: Simple, graphical user interface. –Mosaic and Netscape. –Used by millions of people. n Phase 3: Interactive Applications and Web Pages. –Where we are today.
6
Applets n Applets: mini Java applications that can be embedded inside a web page. Clock Applet Big Text Smaller Text
7
Some Basic Examples n Scrolling Ticker n “Bouncing Heads” n Simple Video Games
8
II. Why is Java Important? n Enables the distribution of applications across the Internet. n As a language, Java also has many important strengths: –Object Oriented –Built-in Security –Built-in Networking –Platform Independent –Built-in Multithreading
9
Feature #1: Object Oriented n Object Oriented languages enable the creation of large applications that are easy to maintain. Clock Object Scrolling Ticker Object Weather Object
10
Feature #2: Built-In Security n 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
11
Feature #3: Networking n It is extremely easy to create network applications in Java. n Java was built from the ground up to work with the Internet.
12
Feature #4: Portable n Java is Platform independent: Runs on any platform - Windows, Macintosh, UNIX. n “Write once, run anywhere.” n Create a single application and it can run anywhere on the Internet.
13
Feature #5: Multithreading n You can create applications that do more than one thing at a time. n For example, you can have an animation and a sound at the same time. n Important for animations and network applications.
14
Java Virtual Machine C/C++ Program Operating System Java Virtual Machine Operating System Java Applet
15
Java Performance n The Achilles Heal of Java n When Java was first released, it was about 20 times slower than native applications written in C/C++. n Now, it’s about half the speed of C/C++. But, it really depends on the Browser and the Platform.
16
III. Java Tutorial n Once you understand the basics of Java, creating an Applet is straightforward. n 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
17
Object Oriented Basics n Every object has two things: –Some Data –Some Methods (or functions) n For example, a scrolling ticker object might have: –The Text to be displayed. –A method called animate() that tells the object to start scrolling.
18
The Applet Object n The Applet objects contains: –Data regarding the Web Browser. –Methods for creating applications. n Some methods: –getImage ():Retrieves an image –paint ():Paint on a canvas –getAudioClip():Retrieves a sound file
19
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); }
20
Import/Comments n 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) n Comments are denoted with // –// This is a comment.
21
Extending Applet n public class FirstApplet extends Applet { n This tells the compiler that you want to create an Applet object. Called FirstApplet. n This really relates to object oriented inheritance (which we don’t have time to discuss.)
22
Drawing Graphics n paint method: –Responsible for all graphics painting inside the applet. n g.drawString (“Hello World”, 25, 50); X Coordinate Y Coordinate
23
To View your Applet n First you need to compile your applet: –javac FirstApplet.java n Then, you need to create a simple HTML page:
24
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); }
25
To View the Second Applet n HTML Page:
26
IV. Cool Examples n The Molecule Viewer: –http://java.sun.com/nav/whatis/cherwell.html n Wired Stock Graphing Tool: –http://stocks.wired.com n 3D Ray: –http://www.2nu.com/Wayne/SplattJava/Spl attJava480x300.html n Games: –http://www.comedycentral.com/southpark/ cartman/cartman.htm
27
The Future of Java n 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?
28
Java 1.2 n Current Release: Java 1.2 (Beta) Most browsers only support Version 1.0 n What’s new in Java 1.2: –Java Foundation Classes (Swing) –Java 2D, 3D –Java Sound –Java Speech
29
Java Everywhere n Java can run on any platform. n Embedded Java: –Java Rings –Java Smart Cards –Java Telephones –Java Televisions –Java light switches
30
One Java or Many? n Sun wants Java to be an open standard that can run on any platform. n Microsoft hates Java. Has created a slightly different version that is optimized for Windows.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.