Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Lecture 16: Dolores Zage. WWW n Was a method for distributing passive information n added forms and image maps n interaction was only a new way to.

Similar presentations


Presentation on theme: "Java Lecture 16: Dolores Zage. WWW n Was a method for distributing passive information n added forms and image maps n interaction was only a new way to."— Presentation transcript:

1 Java Lecture 16: Dolores Zage

2 WWW n Was a method for distributing passive information n added forms and image maps n interaction was only a new way to get at the same information n enter Java, and the capability for Web pages of containing Java applets

3 Java applet n is a dynamic and interactive program that can run inside a Web page displayed by a Java-capable browser n Small programs that u create animations u multimedia presentations u real-time video games u multi-user networked games u ream interactivity u most anything a small program can do

4 What is Java? n OO programming language developed by Sun Microsystems n modeled after C++ n small, simple, portable across platforms and operating systems n complete full-fledge programming language n HotJava (Sun’s browser) was completely written in Java

5 Applets and Applications n Applets- Java programs that are downloaded over the WWW and executed by a Web browser on the reader’s machine n applications - more general programs, do not require a browser to run. n A single Java program can be both, depending on how you write that program and the capabilities that program uses.

6 Platform-Independent n Most significant advantages that Java has over other programming languages n at both the source and the binary level n Java’s foundation class libraries make it easy to write code that can be moved from platform to platform without the need to rewrite it to work with that platform

7 Bytecodes n Binary files are also platform-independent n use a form called bytecodes n bytecodes are a set of instructions that looks like some machine codes, but that is not specific to any one processor

8 Traditional versus Java compilation ------- ----- ------ ---- Traditional Code Compiler (Pentium) Compiler (Power PC) Java Compiler (SPARC) Java Compiler (Pentium) Java Compiler (PowerPC) Compiler (SPARC) Binary File (Pentium) Binary File (Power PC) Binary File (SPARC) Java Bytecode (Platform Independent) Java Interpreter (Pentium) Java Interpreter (PowerPC) Java Interpreter (SPARC) Java Code ----- -- ----- --- ------

9 Bytecodes n Programs can run on any platform and any operating or window system as long as the Java interpreter is available n Disadvantage - execution speed.

10 Creating the Hello World Java Application Class HelloWorld { Public static void main (String args[]) { System.out.println(“Hello World!”); } All of the program is enclosed in a class definition! Main is the first routine that is run when the program is executed

11 Creating and Executing “Hello World” n Use your favorite editor n filename Helloworld.java n compile the source file using the Java compiler (Suns -- javac Helloworld.java) n if no errors - end up with a file called Helloworld.class - this is the bytecode file n then use the Java interpreter to execute n java Helloworld

12 To create an applet n Creating applets may be more complex than creating an application because of the special rules for how they behave in a browser n for example, Hello World as an applet u need to make space for your message u use graphics operations to paint the message to the screen

13 Creating the Hello World Java Applet import java.awt.Graphics; Class HelloWorldApplet extends java.applet.Applet { Public void paint (Graphics g) { g.drawString(“Hello World!”, 5, 25); } Enables this applet to interact with the JDK classes for creating applets and drawing graphics on the screen Applets use several standard methods to take the place of main, which include init(), start() and paint()

14 Creating and Executing “Hello World” n Use your favorite editor n filename HelloworldApplet.java n compile the source file using the Java compiler (Suns -- javac HelloworldApplet.java) n if no errors - end up with a file called HelloworldApplet.class - this is the bytecode file n now use inside of a web page

15 Using the Hello World Java Applet Hello to Everyone! My Java applet says:


Download ppt "Java Lecture 16: Dolores Zage. WWW n Was a method for distributing passive information n added forms and image maps n interaction was only a new way to."

Similar presentations


Ads by Google