Java Debugging & Profiling Techniques Ethan Henry [email protected] KL Group .
Java Tutorial Ethan Cerami @1998 New York University.
-
Upload
hugh-arnold -
Category
Documents
-
view
215 -
download
1
Transcript of Java Tutorial Ethan Cerami @1998 New York University.
Java TutorialJava TutorialEthan CeramiEthan Cerami
@1998 New York University@1998 New York University
Road MapRoad Map
What is Java?What is Java? Why is Java Important?Why is Java Important?
– Strengths, WeaknessesStrengths, Weaknesses Java Tutorial: Creating an AppletJava Tutorial: Creating an Applet Cool Examples/DemosCool Examples/Demos Future of JavaFuture of Java
I. What is Java?I. What is Java?
Java is a new Internet programming Java is a new Internet programming language.language.
Developed by Sun Microsystems, Developed by Sun Microsystems, Inc.Inc.
Originally developed for Interactive Originally developed for Interactive Television Set-top boxes.Television Set-top boxes.
Rapidly becoming the standard for Rapidly becoming the standard for Internet programming.Internet programming.
Evolution of the WebEvolution of the Web
Phase 1: Everything was in text. Used Phase 1: Everything was in text. Used mainly by academics and government.mainly by academics and government.
Phase 2: Simple, graphical user Phase 2: Simple, graphical user interface.interface.– Mosaic and Netscape. Mosaic and Netscape. – Used by millions of people.Used by millions of people.
Phase 3: Interactive Applications and Phase 3: Interactive Applications and Web Pages.Web Pages.– Where we are today.Where we are today.
AppletsApplets
Applets: mini Java applications Applets: mini Java applications that can be embedded inside a that can be embedded inside a web page.web page.
Clock Applet
Big TextSmaller Text
Some Basic ExamplesSome Basic Examples
Scrolling TickerScrolling Ticker ““Bouncing Heads”Bouncing Heads” Simple Video GamesSimple Video Games
II. Why is Java Important?II. Why is Java Important?
Enables the distribution of applications Enables the distribution of applications across the Internet.across the Internet.
As a language, Java also has many As a language, Java also has many important strengths:important strengths:– Object OrientedObject Oriented– Built-in SecurityBuilt-in Security– Built-in NetworkingBuilt-in Networking– Platform IndependentPlatform Independent– Built-in MultithreadingBuilt-in Multithreading
Feature #1: Object Feature #1: Object OrientedOriented
Object Oriented languages enable Object Oriented languages enable the creation of large applications the creation of large applications that are easy to maintain.that are easy to maintain.
Clock Object
ScrollingTickerObject
WeatherObject
Feature #2: Built-In Feature #2: Built-In SecuritySecurity
If you download an application If you download an application across the Internet, the program across the Internet, the program might do malicious things: might do malicious things: deleting files, reading sensitive deleting files, reading sensitive data, etc.data, etc.
.
Operating System: Read, write, delete files
Java Security SandboxRestricted Access
Feature #3: NetworkingFeature #3: Networking
It is extremely easy to create It is extremely easy to create network applications in Java.network applications in Java.
Java was built from the ground up Java was built from the ground up to work with the Internet.to work with the Internet.
Feature #4: PortableFeature #4: Portable
Java is Platform independent: Java is Platform independent: Runs on any platform - Windows, Runs on any platform - Windows, Macintosh, UNIX.Macintosh, UNIX.
““Write once, run anywhere.”Write once, run anywhere.” Create a single application and it Create a single application and it
can run anywhere on the Internet.can run anywhere on the Internet.
Feature #5: Feature #5: MultithreadingMultithreading
You can create applications that do You can create applications that do more than one thing at a time.more than one thing at a time.
For example, you can have an For example, you can have an animation and a sound at the animation and a sound at the same time.same time.
Important for animations and Important for animations and network applications.network applications.
Java Virtual MachineJava Virtual Machine
C/C++Program
OperatingSystem
Java VirtualMachine
OperatingSystem
JavaApplet
Java PerformanceJava Performance
The Achilles Heal of JavaThe Achilles Heal of Java When Java was first released, it When Java was first released, it
was about 20 times slower than was about 20 times slower than native applications written in C/C+native applications written in C/C++.+.
Now, it’s about half the speed of Now, it’s about half the speed of C/C++. But, it really depends on C/C++. But, it really depends on the Browser and the Platform.the Browser and the Platform.
III. Java TutorialIII. Java Tutorial
Once you understand the basics of Once you understand the basics of Java, creating an Applet is Java, creating an Applet is straightforward.straightforward.
In order to create an applet, you In order to create an applet, you first need to download a Java first need to download a Java Compiler.Compiler.– Download the Java Development Kit Download the Java Development Kit
(JDK) 1.1 from java.sun.com(JDK) 1.1 from java.sun.com
Object Oriented BasicsObject Oriented Basics
Every object has two things:Every object has two things:– Some DataSome Data– Some Methods (or functions)Some Methods (or functions)
For example, a scrolling ticker For example, a scrolling ticker object might have:object might have:– The Text to be displayed.The Text to be displayed.– A method called animate() that tells A method called animate() that tells
the object to start scrolling.the object to start scrolling.
The Applet ObjectThe Applet Object
The Applet objects contains:The Applet objects contains:– Data regarding the Web Browser.Data regarding the Web Browser.– Methods for creating applications.Methods for creating applications.
Some methods:Some methods:– getImage ():getImage (): Retrieves an imageRetrieves an image– paint ():paint (): Paint on a canvasPaint on a canvas– getAudioClip():getAudioClip(): Retrieves a sound fileRetrieves a sound file
Hello World!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);}
}
Import/CommentsImport/Comments
Import statement tells the Compiler to Import statement tells the Compiler to load certain libraries:load certain libraries:– similar to the #include statement in C.similar to the #include statement in C.– import java.applet.*;import java.applet.*;– import java.awt.*; (Abrstract Windowing import java.awt.*; (Abrstract Windowing
Toolkit. Useful for using widgets and Toolkit. Useful for using widgets and graphics)graphics)
Comments are denoted with //Comments are denoted with //– // This is a comment.// This is a comment.
Extending AppletExtending Applet
public class FirstApplet extends public class FirstApplet extends Applet {Applet {
This tells the compiler that you This tells the compiler that you want to create an Applet object. want to create an Applet object. Called FirstApplet.Called FirstApplet.
This really relates to object This really relates to object oriented inheritance (which we oriented inheritance (which we don’t have time to discuss.)don’t have time to discuss.)
Drawing GraphicsDrawing Graphics
paint method:paint method:– Responsible for all graphics painting Responsible for all graphics painting
inside the applet.inside the applet. g.drawString (“Hello World”, 25, g.drawString (“Hello World”, 25,
50);50);
X CoordinateY Coordinate
To View your AppletTo View your Applet
First you need to compile your First you need to compile your applet:applet:– javac FirstApplet.javajavac FirstApplet.java
Then, you need to create a simple Then, you need to create a simple HTML page:HTML page:
<APPLET code="FirstApplet.class" width=150 height=100></APPLET>
Hello World, Version 2.0Hello 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);
}}
To View the Second AppletTo View the Second Applet
HTML Page:HTML Page:
<APPLET code="SecondApplet.class" width=350 height=125></APPLET>
IV. Cool ExamplesIV. Cool Examples The Molecule Viewer:The Molecule Viewer:
– http://java.sun.com/nav/whatis/cherwell.htmlhttp://java.sun.com/nav/whatis/cherwell.html
Wired Stock Graphing Tool:Wired Stock Graphing Tool:– http://stocks.wired.comhttp://stocks.wired.com
3D Ray:3D Ray:– http://www.2nu.com/Wayne/SplattJava/http://www.2nu.com/Wayne/SplattJava/
SplattJava480x300.htmlSplattJava480x300.html Games:Games:
– http://www.comedycentral.com/southpark/http://www.comedycentral.com/southpark/cartman/cartman.htmcartman/cartman.htm
The Future of JavaThe Future of Java
To answer this question, you have To answer this question, you have to look at two elements:to look at two elements:– What can you do with Java? What What can you do with Java? What
kind of added functionality will we kind of added functionality will we see?see?
– Where can you actually run Java? Where can you actually run Java? What comes after the Applet?What comes after the Applet?
Java 1.2Java 1.2
Current Release: Java 1.2 (Beta) Current Release: Java 1.2 (Beta) Most browsers only support Most browsers only support Version 1.0Version 1.0
What’s new in Java 1.2:What’s new in Java 1.2:– Java Foundation Classes (Swing)Java Foundation Classes (Swing)– Java 2D, 3DJava 2D, 3D– Java SoundJava Sound– Java SpeechJava Speech
Java EverywhereJava Everywhere
Java can run on any platform.Java can run on any platform. Embedded Java:Embedded Java:
– Java RingsJava Rings– Java Smart CardsJava Smart Cards– Java TelephonesJava Telephones– Java TelevisionsJava Televisions– Java light switchesJava light switches
One Java or Many?One Java or Many?
Sun wants Java to be an open Sun wants Java to be an open standard that can run on any standard that can run on any platform.platform.
Microsoft hates Java. Has created Microsoft hates Java. Has created a slightly different version that is a slightly different version that is optimized for Windows.optimized for Windows.