Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Introduction to Java Programming Paradigms 1 Computing in the 1990s The Internet and the WWW Graphical User Interfaces (GUIs) Object-oriented Programming (OOP) 2 The Internet A global network of computers The World Wide Web (WWW) users retrieve documents remote programs may be invoked Need language platforms that are: network-aware portable secure 3 Graphical User Interfaces Users interact with an application through visual objects: Mouse and pointer facilitate certain actions: Windows, Buttons, Text fields, etc. click, drag, drop, etc. “Visual Programming” focus is on handling UI objects and events 4 Object-Oriented Programming Program (revised definition): Object: collection of interacting objects a thing that has identity, state, and behavior instance of a class OOP: focus is on developing classes that specify state (variables) and behavior (functions)5 Enter Java 1991 1993 Sun Microsystems develops a language (based on C) for consumer electronic devices WWW explodes in popularity increased need for “dynamic” Web pages 1995 Sun formally announces Java for web use6 What is Java? Java is a general purpose programming language that is: object-oriented interpreted, architecture-neutral, portable distributed (network-aware), secure simple, robust multi-threaded high-performance (?) 7 Two Types of Java Programs Applications general-purpose programs standalone executed through the operating system Applets programs meant for the WWW embedded in a Web page normally executed through a browser 8 Simple Java Application File: Hello.java // Hello World application public class Hello { public static void main(String args[]) { System.out.println(“Hello world”); } } 9 Compilation and Execution Compile using javac (compiler) C> javac Hello.java Hello.class file is produced Execute using java (interpreter) C>java Hello requires a Hello.class file 10 Simple Java Applet File: HelloAgain.java import java.awt.*; import java.applet.Applet; public class HelloAgain extends Applet { public void paint(Graphics g) { g.drawString(“Hello”,50,50); } } 11 Executing Applets After compiling the java program: Embed an “applet tag” in an .html document that references the .class file Open the .html document using a browser or the appletviewer 12 Sample .html Document File: HA.html <h1> My First Applet </h1> <applet code=“HelloAgain.class” height=200 width=100> </applet> 13 What is HTML? Hypertext Markup Language Underlying language of Web pages A means of providing formatting instructions for presenting content Text-based .html documents: collection of content and controls (tags) 14 Java Program Structure Java Program (optional) import declarations class declaration Class class name should match its file name may extend an existing class (such as Applet) contains method/function declarations 15