1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Java methods: Object-oriented programming and data structures (2nd AP edition): Chapter 2 - Maria Litvin, Gary Litvin

32 27 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 32
Dung lượng 389,56 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chapter 2 - An introduction to software engineering. This chapter gives a glimpse of how software development evolved from artisanship into a professional engineering discipline. At the same time, students will get familiar with Java development tools and run their first programs.

Trang 1

An Introduction to Software

Engineering

Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing All

rights reserved Chapter 2

Java Methods

Object-Oriented Programming

and Data Structures

Maria Litvin ● Gary Litvin

2nd AP edition with GridWorld

Trang 2

Objectives:

• Understand the software development

process, tools, and priorities

• Understand compilers and interpreters

• Learn about Java Virtual Machine, bytecode

• Learn to set up and run simple console

applications, GUI applications, and applets in Java

• Learn basic facts about OOP

Trang 3

Software Today:

1,580,000,000

Trang 4

• Graphics / arts / digital photography

Trang 5

• Often cryptic code

Trang 6

y languag

Smalltalk-C#

Log o

Python Cobol

D

Fortres s Groovy

Trang 7

 translates the source

into object code

• Debugger

 steps through the program “in slow motion” and helps find logical mistakes (“bugs”)

Trang 9

Compil er

Object code

le program

Edito

r

Source code

Compil er

Object code

Edito

r

Source code

Compil er

Object code

Trang 10

Interpreted Languages:

Edit-Run

Edito r

Source code

Interpret

Trang 11

while the program is interpreted

 the interpreted program is slower

Trang 12

Java’s Hybrid Approach:

Compiler + Interpreter

• A Java compiler converts Java source

code into instructions for the Java

Virtual Machine.

These instructions, called bytecode, are

the same for any computer / operating system

• A CPU-specific Java interpreter

interprets bytecode on a particular

computer

Trang 13

 

Interpreter

Trang 14

• Interpreter is faster and smaller than it would

be for Java source

• Source code is not revealed to end users

• Interpreter performs additional security

checks, screens out malicious code

Trang 16

JDK (cont’d)

• Developed by Sun Microsystems (now Oracle); free download

• All documentation is online

• Many additional Java resources on the Internet

http://www.oracle.com/technetwork/java/javase/downloads/

Trang 17

Java IDE

• GUI front end for JDK

• Integrates editor, javac, java, appletviewer, debugger, other tools:

 specialized Java editor with syntax highlighting, autoindent, tab setting, etc.

the offending source code line

• Usually JDK is installed separately and an

IDE is installed on top of it

Trang 18

Types of Programs

• Console applications • GUI applications

• Applets

Trang 19

Console Applications

C:\javamethods\Ch02> path=%PATH%;C:\Program

Files\Java\jdk 1.5.0_07\bin

C:\javamethods\Ch02> javac Greetings2.java

C:\javamethods\Ch02> java Greetings2

Enter your first name: Josephine

Enter your last name: Jaworski

Hello, Josephine Jaworski

Press any key to continue

• Simple text dialog:

prompt input, prompt input result

Trang 20

Command-Line Arguments

C:\javamethods\Ch02> javac Greetings.java

C:\javamethods\Ch02> java Greetings Josephine

Jaworski

Hello, Josephine Jaworski

public class Greetings

{

public static void main(String[ ] args)

{

String firstName = args[ 0 ];

String lastName = args[ 1 ];

System.out.println("Hello, " + firstName + " " + lastName);

}

}

line

Command-arguments are passed

to main

as an array

of Strings.

Trang 21

Command-Line Args (cont’d)

• Can be used in GUI applications, too

• IDEs provide ways to set them (or

prompt for them)

Josephine Jaworski

Trang 22

Scanner kboard = new Scanner(System.in);

System.out.print("Enter your first name:

");

String firstName = kboard.nextLine( );

System.out.print("Enter your last name:

");

String lastName = kboard.nextLine( );

System.out.println("Hello, " + firstName + " " + lastName);

System.out.println("Welcome to Java!");

}

}

Promp ts

Trang 23

Slider

Trang 24

HelloGui window = new HelloGui( );

// Set this window's location and size:

// upper-left corner at 300, 300; width 200, height

100

window.setBounds(300, 300, 200, 100);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CL OSE);

window.setVisible(true);

}

}

GUI libraries

Trang 25

No main in applets: the

init method is called by

JDK’s appletviewer or the

browser

Trang 26

• An object may have its own “memory,”

which may contain other objects

• An object has a set of methods that can

process messages of certain types

Trang 27

OOP (cont’d)

• A method can change the object’s state, send messages to other objects, and create new objects

• An object belongs to a particular class, and the functionality of each object is determined

by its class

• A programmer creates an OOP application by defining classes

Trang 28

The Main OOP Concepts:

Inheritance: a subclass extends a superclass;

the objects of a subclass inherit features of

the superclass and can redefine them or add new features

• Event-driven programs: the program

simulates asynchronous handling of events; methods are called automatically in response

to events

Trang 30

OOP Benefits

• Facilitates team development

• Easier to reuse software components and write reusable software

• Easier GUI (Graphical User Interface) and multimedia programming

Trang 32

Review (cont’d):

• What is a console application?

• What are command-line arguments?

• What is a GUI application?

• What is the difference between a GUI application and an applet?

• What is OOP?

• Define inheritance

Ngày đăng: 04/11/2020, 23:13

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN