Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Java Programming CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.

Similar presentations


Presentation on theme: "Introduction to Java Programming CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University."— Presentation transcript:

1 Introduction to Java Programming CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University

2 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 7 The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program Object Program

8 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 11 Sample.html Document File: HA.html My Sample Applet

12 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Intro Java Slide 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


Download ppt "Introduction to Java Programming CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University."

Similar presentations


Ads by Google