17
Introduction to Programming

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

Embed Size (px)

Citation preview

Page 1: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Introduction to Programming

Page 2: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

The Programming Process

Create/EditProgram

CompileProgram

ExecuteProgram

Compile Errors? Run-Time Errors?

SourceProgram

ObjectProgram

Page 3: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Programming

No matter what kind of computer you have, it works by following specific steps

These steps are called the computer’s program

A large part (but not all) of CS 21a is about how to write programs

Page 4: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Object-Oriented Programming Several years ago, Ateneo was the first school

in the Philippines (and one of the first in the world) to teach Java as the first programming language for CS and MIS majors

Now Java is a well-accepted teaching language, and very highly in-demand in industry

Among others … one advantage of Java is that it makes learning Object-Oriented Programming (OOP) easier than with other languages

Page 5: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

What is Object-oriented Programming? Programs are written as systems of interacting

objects Objects are “things” that can have state and

properties and can “do” certain actions Began in the 1960’s with Simula, a language

for writing simulations Popularized in the 80’s by Smalltalk, then C++

in the late 80’s, and then Java in the late-90’s Allows you to write very complex and large

systems, as well as maximize reuse and flexibility

Page 6: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Object-oriented Programming

Object-oriented design makes it easy to understand and define the program

Makes writing big, complex programs easier Little pieces compose complex systems Just like in real life (e.g., cells make up

living things)

Page 7: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Introduction to Java

Page 8: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Java 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

Page 9: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

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 (?)

Page 10: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

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

Page 11: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Simple Java Application

File: Hello.java// Hello World application

public class Hello

{

public static void main( String args[] )

{

System.out.println( “Hello world” );

}

}

Page 12: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

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

Page 13: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Simple Java AppletFile: HelloAgain.java

import javax.swing.*;import java.awt.*;public class HelloAgain extends JApplet{ public void paint( Graphics g ) { g.drawString( “Hello”, 50, 50 ); }}

Page 14: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

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

Page 15: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

Sample .html Document

File: HA.html

<h1> My Sample Applet </h1><applet code=“HelloAgain.class” height=200

width=100></applet>

Page 16: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

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)

Page 17: Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program

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