Computer Programming with JAVA

21
Computer Programming with JAVA Chapter 1 Introduction and A Taste of Java

description

Computer Programming with JAVA. Chapter 1 Introduction and A Taste of Java. Contents. Object-Oriented Programming History of the Java Language A First Java Program Compiling and Running a Java Program. Object-Oriented Programming. What are Objects ? All things around us - PowerPoint PPT Presentation

Transcript of Computer Programming with JAVA

Page 1: Computer Programming with JAVA

Computer Programming with JAVA

Chapter 1Introduction and A Taste of Java

Page 2: Computer Programming with JAVA

Computer Programming with Java

2

Contents

Object-Oriented Programming History of the Java Language A First Java Program Compiling and Running a Java Program

Page 3: Computer Programming with JAVA

Computer Programming with Java

3

Object-Oriented Programming

What are Objects? All things around us

• Ability to perform actions• Status

OOP (or Paradigm) A programming methodology (paradigm) that

views a program as this sort of world consisting of objects that interact with each other by means of actions.

Methods, data

Page 4: Computer Programming with JAVA

Computer Programming with Java

4

Object-Oriented Programming (1)

Objects• A program construction that has data associated with it

and that can perform certain actions Methods

• The actions performed by objects Class

• A type or kind of object

What is difference between OOP and Procedural-Oriented Programming? Code reusability Efficiency

Page 5: Computer Programming with JAVA

Computer Programming with Java

5

A Brief History of the Java Language

A brief history of the Java 1990:

• Gosling, J. and Naughton, P. 1991: Green Project

• *7 system by 1st Person Inc. named by Oak• Research settop box and VOD with Green (O.S.) • Gosling, J., designing a programming language for

home appliances• Java byte code: Intermediate language for

inexpensive portability 1991: WWW, 1992: Web browser

Page 6: Computer Programming with JAVA

Computer Programming with Java

6

A Brief History of the Java Language (1)

1994: • NCSA Mosaic, WebRunner (HotJava) browser, applet

1995: • adapted for New technology for WWW• Netscape and MS agreed license of Java

1996: • Java 1.0.2

Page 7: Computer Programming with JAVA

Computer Programming with Java

7

A Taste of Java

Features JAVA : A simple, Object-Oriented, distributed, interpreted,

robust, secure, machine-independent (portable), high-performance, multi-thread, and dynamic language

• Simple : No operator overloading, multiple inheritance, memory management, header file, structure, union, enumeration, pointer arithmetic, template, preprocessing, user-defined type conversion.

• Object-Oriented• Distributed : WWW• Robust : no memory management, exception

handling, error checking in compile-time.

Page 8: Computer Programming with JAVA

Computer Programming with Java

8

A Taste of Java (1)• secure : public-key, restricted client resource

access• 자바 애플릿은 클라이언트 내의 디스크를 read/write 할 수 없다 .• 자바 애플릿은 클라이언트의 다른 응용프로그램을 실행시킬 수 없다 .• 자바 애플릿은 다운로드된 서버 외에는 접속할 수 없다 .

• Machine-Independent (portable)• “Write Once Run Everywhere”

• Compiled : compiled into byte code• Interpreted : bytecodes are interpreted by Java

Virtual Machine• Multi-Thread

Page 9: Computer Programming with JAVA

Computer Programming with Java

9

Java Compiler

Applet Store

Java AppletBytecode verifier

Class loader

Java Run-time interpreter

Just-in-Time

Compiler

Hardware platform

Java Bytecodes Java

Bytecodes

Server Client

Security model in Java

Page 10: Computer Programming with JAVA

Computer Programming with Java

10

Sourcecode

Pentium

Mac

Unix

Pentiumexecutable

code

Macexecutable

code

Unixexecutable

Sourcecode

Pentium

Mac

Unix

PentiumJava Interpreter

MacJava Interpreter

UnixJava Interpreter

JavaBytecodes

Machine-independent Property

Page 11: Computer Programming with JAVA

Computer Programming with Java

11

A Taste of Java (2)

Types of Java program Applet

• To be sent to another (remote) location on the WWW and run there.

Application• Running on your (local) computer. main()

Byte Code Executable code in the Java Machine-independent, neutral, intermediate

code

Page 12: Computer Programming with JAVA

Computer Programming with Java

12

A Taste of Java (3)

Difference between C++ and Java

J ava C++Inheritance Single Multiple

Garbage Collection Automatic ManualOperator overloading o

String Built-in class Character arrayType conversion Automatic Manual

Page 13: Computer Programming with JAVA

Computer Programming with Java

13

Java Development Kit JDK

contains the software and tools that developers need to compile, debug, and run applets and applications written using the Java programming language.

JDK 1.0 Just reflect the feature of language itself and

the one of Applet Sun didn’t pass through the alpha, beta version, and

just were intended on displaying the bug-modified version

problem : huge bugs and insufficient GUI

Page 14: Computer Programming with JAVA

Computer Programming with Java

14

Java Development Kit (1)

JDK 1.1 Event-driven model, light component

framework JDBC, RMI, JavaBeans, Globalization, Localization API Object Serialization Servlet Api, Enterprise JavaBeans 자바가 Server 측에 수용되는데 밑거름이 됨

Page 15: Computer Programming with JAVA

Computer Programming with Java

15

Java Development Kit (2)

JDK 1.2 JDBC, RMI 등의 기반 API 들을 개선 2-Dimension Imagiing 과 Printing, GUI

component Security Model CORBA 의 지원 (org.*) 주로 client 측의 S/W 를 위한 API 완성

Page 16: Computer Programming with JAVA

Computer Programming with Java

16

Java Development Kit (3) Java 2 Platform

Java 1.2 의 정식 버젼 API 관련

• Swing, 2D API, drag&drop API, JFC

Security 관련• Policy-Based Access Control

프로그래밍 관련• 강력한 자료구조코딩을 위한 collection framework• 참조객체지원• Reflection 과 Serialization 에 대한 성능 개선

HotSpot 은 포함되지 않음

Page 17: Computer Programming with JAVA

Computer Programming with Java

17

public class FirstProgram{public static void main(String[] args){

System.out.println("Hello out there.");System.out.println("Want to talk some more?");System.out.println("Answer y for yes or n for no.");

char answerLetter;answerLetter = SavitchIn.readLineNonwhiteChar();if(answerLetter == 'y')

System.out.println("Nice weather we are having.");

System.out.println("Good-bye");

System.out.println("Press enter key to end program.");String junk;junk = SavitchIn.readLine();

}}

Display 1.4: A Simple Java Program

Page 18: Computer Programming with JAVA

Computer Programming with Java

18

Spelling Rules Identifier

A name in a programming language• e.g.) a class or variable name

Rules It must consist entirely of letters, digits (0-9), and

underscore character (_) The first character cannot be a digit No identifier can contain a space or any other character

such as a period or an *. There is no limit to the length of a name Case-Sensitive

• e.g.) mystuff, myStuff, Mystuff

Page 19: Computer Programming with JAVA

Computer Programming with Java

19

Spelling Rules (1) Unicode

• It can include characters that are used in other languages

It must avoid the reserved words (or keywords) and built-in classes and their member

Page 20: Computer Programming with JAVA

Computer Programming with Java

20

Compiling and Running a Java Program

Compiling javac MyClass.java

Running java MyClass

Page 21: Computer Programming with JAVA

Computer Programming with Java

21

Display 1.3: Compiling and Running a Java Program

Java source (.java)(FirstProgram.java)

Java Compiler(javac)

Java Bytecodes (FirstProgram.class)

Java Interpreter(java)