1 / 13

Introduction to Java Programming

Introduction to Java Programming. CS 21a: Introduction to Computing I First Semester, 2013-2014. Programming. Recall that a program is defined as: a sequence of instructions for a computer A large part (but not all) of CS 21a is about how to write programs in a programming language (Java).

azize
Télécharger la présentation

Introduction to Java Programming

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. Introduction to Java Programming CS 21a: Introduction to Computing I First Semester, 2013-2014

  2. Programming • Recall that a program is defined as:a sequence of instructions for a computer • A large part (but not all) of CS 21a is about how to write programs in a programming language (Java)

  3. The Java Programming Language • Java: an object-oriented programming language that is • simple • safe • platform independent • designed for the internet • Many universities use Java as the introductory programming language for beginning programmers • Ateneo adopted Java for CS 21a in 1997

  4. Java (a brief history) • 1991 • Sun Microsystems develops a language (based on C) for consumer electronic devices • 1993 • WWW explodes in popularity • increased need for "dynamic" Web pages • 1995 • Sun formally announces Java for web use

  5. 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

  6. Simple Java Application File: Hello.java // Hello World application public class Hello { public static void main( String args[] ) { System.out.println( "Hello world" ); } }

  7. The Programming Process Compile Errors? Run-Time Errors? Create/Edit Program Compile Program Execute Program Source Program Object Program

  8. Creation, Compilation, and Execution • Create Java program C:\> edit Hello.java • Hello.java file is created • 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

  9. Simple Java Applet File: HelloAgain.java import javax.swing.*; import java.awt.*; public class HelloAgain extends JApplet { public void paint( Graphics g ) { g.drawString( "Hello", 50, 50 ); } }

  10. 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

  11. Sample .html Document File: HA.html <h1> My Sample Applet </h1> <applet code="HelloAgain.class" height=200 width=100> </applet>

  12. 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)

  13. 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 JApplet) • contains method/function declarations

More Related