National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.

Slides:



Advertisements
Similar presentations
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
Advertisements

Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Introduction to Java The objectives of this chapter are: To describe the key aspects of Java To describe the Java software development kit (SDK) To explain.
Object Orientated Programming
IC211 Object Oriented Programming Overview of Java.
Java: History and Introduction (Lecture # 1). History… Java – Based on C and C++ – Developed in 1991 for intelligent consumer electronic devices – Green.
Introduction to Java Kiyeol Ryu Java Programming Language.
Introduction to Java Programming, 4E
For more Lectures and Notes Visit
Lab 1 Instructor: Jolanta Soltis.
Introduction to Java.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
LESSON 1 INTRODUCTION Compiled By: Edwin O. Okech [Tutor, Amoud University] JAVA PROGRAMMING.
Java PAL.  Contains the development kit and the runtime environment ( aka the Java Virtual Machine )  Download Link:
CMSC 202 Computer Science II for Majors Fall 2009 Introduction.
Getting Started What is Java? A programming language –Fully buzzword-compliant: A simple, object oriented, distributed, interpreted, robust, secure,
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 1
Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps.
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
BA22001 Introduction to Java Instructor: Jingwu He.
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
CSCI 224 Introduction to Java Programming. Course Objectives  Learn the Java programming language: Syntax, Idioms Patterns, Styles  Become comfortable.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
CMSC 202 Computer Science II for Majors Object-Oriented Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
1.  At the end of this slide, student can:  Explore tools, features, properties and interface of the Textpad.  Creating a new project.  Open and run.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
POS 406 Java Technology And Beginning Java Code
Introduction to Java Programming with Forte Y. Daniel Liang.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
Object Oriented Programming Lecture 3. Introduction  In discussing Java, some items need to be clarified  The Java programming language  The Java virtual.
Session 1 Introduction to Java. Objectives Java Simplified / Session 1 / 2 of 32 Explain the history of Java Explain Java in brief List the types of Java.
4-Nov-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic 1: The Java Environment Maj Joel.
Lecture.1: Getting Started With Java Jiang (Jen) ZHENG May 9 th, 2005.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1. An Introduction A Programming Language A Technology Java Development Kit Java API One Language: Three Editions Standard Edition Enterprise Edition.
The Java Platform, The Java Language, JDK, IntelliJ
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
introductory lecture on java programming
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
Introduction to JAVA Programming
Introduction to Java Programming, 4E Y. Daniel Liang.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CMSC 202 Computer Science II for Majors Fall 2010 Introduction Version 9/101.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
Object Oriented Programming in
Java™ 2 Platform Getting Started.
Introduction Enosis Learning.
Introduction to Java Dept. Business Computing University of Winnipeg
(Computer fundamental Lab)
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Introduction to Java Programming 講師 : 曾學文

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Outline Course Introduction Java Introduction Your First Cup of Java Your Turn

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering 3 Course Introduction 上課時間 ~ :00 ~ 12:00 講師:曾學文 課程網頁

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Course Introduction 課程適合對象 對於 Java 程式設計有興趣的初學者 課程目的 藉由基本 Java 程式設計概念開始,循序漸進地帶領學員 進入 Java 程式設計的殿堂。課堂上將著重於基本程式設 計觀念以及實作經驗,將藉由大量地練習範例中,讓學 員清楚了解 Java 程式設計的方法。期許學員能於課程結 束後,具有初步的程式撰寫能力,並且最重要的是具有 自行進修進階程式設計技巧。 課程進度表 依照課程情況做動態調整

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Course Introduction 參考書目 The Java Tutorial 3rd Edition Java How to Program 4th Edition ( Prentice Hall ) Thinking in Java, 3rd Edition Java 2 教學手冊 SDK 1.4 版( Beginning Java 2 SDK 1.4 Edition ),蔡 明志、陳彥仲譯,碁峰出版

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Course Introduction 成績評量 上課情況(缺曠課、課堂實例練習) 平均分數達 70 以上將給予結業證書 作業繳交情況 程式評分標準 完成程式基本項目且正確執行: 80 分 完成進階項目或加強功能:每項酌予加分 嚴禁抄襲 Questions?

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering The Origin of Java Internet arises in around Different computers run on different operating systems wish to communicate with each other more easily. A new programming language which can run across different platforms is desired. Java is developed and maintained by Sun Microsystem. The first Java platform is released at 5/23/1995. Java platforms are upgraded year by year. Java 1.0 and 1.1 is called Java 1. Java 1.2, 1.3, 1.4, and 1.5 is called Java 2.

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Related Terms about Java Java application Standalone Java programs run on PC. e.g., Borland JBuilder, Intellij IDEA are writen in Java. Java Applet Java programs embedded in the Web page. The functionalities of Java Applet are restricted due to the security reasons. Java script Client-side script language running by browser. Java Server Pages (JSP) Server-side script language running on the web server.

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Important Features of Java Portability Java programs are compiled into Java byte code instead of machine-dependent code. The Java byte code is interpreted by Java Virtual Machine (JVM) upon execution. Various Hardware Windows Java Applications JVM Various Hardware Linux JVM Java Applications

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Important Features of Java Garbage Collection You don’t need to address the problems of memory allocation and de-allocation. The garbage collector in JVM is responsible for managing the memory usage. Well-organized language structure The core Java library is implemented based on the object- oriented design. Some Java-specific features (e.g., interface) increase the reusability of your program.

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Important Features of Java Advanced built-in data structures and classes. Vector, Hashtable, …, etc. Union and find for set operations. Object serialization. Support of multi-thread programming and exception handling Java provides synchronized block for managing multi-thread execution. The programmers are forced to handle exception (e.g., I/O error) in the Java language.

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Important Features of Java 其它語言 程式開始執行後所有物件就一起載入。 一旦開始執行,就無法做出任何變更。 Java 語言 當需要某個物件時,才將該物件載入。 這種特質,讓動態抽換物件變得可能。 動態載入( Dynamic Loading )

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Important Features of Java 何謂多工 (Multi-tasking) 例如,撰寫網路程式,模擬程式。 Java 利用 “ 執行緒 ” (Thread) 來實作多工 可將一個程式分成數份, 讓各部份能同時被執行。

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Important Features of Java 安全性 Bytecode 的驗證 Java 編譯器是藉由產出與電腦架構無關的 Bytecode 指令,以達到 上述功能。 它們能輕易地在任何機器上解譯,並且動態地轉換成 原生模式的機器碼。 傳遞名稱防護 只要有一個名稱在載入時發生和別處一樣的衝突, Class Loader 將會載入本地端的版本,而拒絕載入遠端的版本 檔案存取的限制 瀏覽器不會讓 Applet 讀取不被用戶允許的文件系統 。 不使用指標 Java 與 C/C++ 之間最大的不同點之一在於 Java 不用指標器 (Pointer) , 能排除發生記憶體被蓋寫 (Overwriting Memory) 和毀損資料 (Corrupting Data) 之可能性

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Important Features of Java 安全性 在 Java 中執行一個程式需經歷層層把關,而且活動範圍 還會被侷限在特定空間。 Java 位元碼 (Byte Code) 有被竄 改過嗎? 別亂跑,我帶 你到正確的記 憶體位置。 很好!一切 正常!但只 准你在特定 範圍活動。

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Java 2 Platforms Java 2 stands for the Java programs developed by jdk1.2 or by later version. SERVER DESKTOP SMART- CARDS PDA’s & SMART- PHONES

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Java 2 Platforms Java 2 Platform Standard Edition (J2SE) Core Java Technology Provide the compiling and execution environment to build the standard Java application. Java 2 Platform Enterprise Edition (J2EE) Provide a component-based approach to the design, development, assembly, and deployment of enterprise applications (e.g., JSP, Servlet, Java Beans). Java 2 Platform Micro Edition (J2ME) The core libraries are modified to meet the restricted requirements of embedded device.

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering A System Implemented in Java

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Programming Tools You can write a J2SE application with a text editor and the Java 2 Software Development Kit (SDK) SDK provides the compiling and executing environment. Latest version: J2SE 5.0 in Java 2 Runtime Environment (JRE) provides only the executing environment. Java Integrated Development Environment (IDE) Borland JBuilder Enterprise 2006 Intellij IDEA 5.0 JCreator

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Java 2 SDK Standard Edition v1.3

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering How to Learn A Programming Language as Quickly as Possible Know how to declare variables and arrays. Know how to write if-then-else. Know how to write loops. Know how many existing functions are available for this language. Know how to debug.

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Your First Cup of Java A Checklist The Java 2 SDK, Standard Edition A text editor: UltraEdit, Vim Steps Create a source file Compile the source file into a bytecode file Run the program contained in the bytecode file

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering How to write, compile and execute Java Java Program Compiler JVM Java byte code Various Hardware Windows Java Applications JVM JVM interprets the byte code into machine-dependent code xxx.java xxx.class

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Create a Source File /** * The HelloWorldApp Class implements an application that * displays “Hello World!” to the standard output. */ public class HelloWorldApp { public static void main ( String[] args ){ //Display “Hello World!” System.out.println("Hello World!"); } 程式進入點 用一般文字編輯器 存檔成 HelloWorldApp.java

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Compile the source file into a bytecode file 開始功能表 執行,打入 “cmd” 進入 Command Prompt 模式 選擇進入程式所在的資料夾

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Compile the source file into a bytecode file 編譯程式 javac HelloWorldApp.java 會產生一個叫做 HelloWorldApp.class 的 bytecode file

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Run the Program 在相同資料夾下,輸入下面指令 java HelloWorldApp

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Error Explanations 指令找不到或是 Class 找不到 【我的電腦】  【內容】  【進階】  【環境變數】 path 環境變數 : D:\j2sdk1.4.2_08\bin classpath 環境變數 :.;D:\j2sdk1.4.2_08\jre\lib\ext\abc.jar ( 外掛 Library)

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering A Closer Look at HelloWorldApp 程式註解 給程式設計師看的, compiler 會跳過註解的部分,所以註 解部分不會被執行。 Java 語言支援三種不同的程式註解方式 /* text */ 多行註解 /** documentation */ 可利用 javadoc 工具將 /** */ 之間的文字抽出,直接作成說明文 件 // 文字 單行註解

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering A Closer Look at HelloWorldApp Defining a Class 藍色粗體字部份即為主類別 (Class) 。 Java 程式至少要有一個類別,才能順利執行。 主類別名稱習慣上與檔名相同。 ( 若為 public ,則必須相同 ) /** * The HelloWorldApp class implements an application that * Displays “Hello World!” to the standard output */ public class HelloWorldApp { public static void main ( String[] args ){ System.out.println(“Hello World!”);// Print the string }

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering A Closer Look at HelloWorldApp 程式進入點 藍色粗體字部份即為進入點,為一個程式開始執行的地方。 Java 的進入點名稱為 “main()” 函數 /** * The HelloWorldApp class implements an application that * displays “Hello World!” to the standard output */ public class HelloWorldApp { public static void main ( String[] args ){ System.out.println(“Hello World!”);// Print the string }

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering A Closer Look at HelloWorldApp main(String[] args)voidstaticpublic { 程式碼寫在此處 } main: 進入點的函數名稱。一定要取名為 “main” (String[] args): 傳遞給 main 的參數。所有的宣告與名稱一定要如此寫。 void: main 的傳回值。 void 代表不傳回任何值。 static: 宣告 main 是一個靜態函數。可以讓整個 HelloWorld class 使用,而非只 有 HelloWorld 的物件可以呼叫而已。 public: 允許任何 class 呼叫這個 main method {}: 將您想執行的程式填在此處。注意 !! Java 每行程式後方都要以分號 “;” 分開。

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering A Closer Look at HelloWorldApp 在螢幕上印字 System.out.println System 類別 out 變數 println 程序 System: java 提供的一個類別,其中定義了所有與標準輸出入的相關動作。 out: System 類別中的一個變數。其型態為 PrintStream 類別 println: PrintStream 類別內的一個程序,由於 out 變數本身指向一個 PrintStream 物件,所以我們得以透過 out 呼叫 println 程序。 範例: System.out.println(“We are”+ “studying”+ “Java!!”);

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering 程式寫作習慣 程式敘述 ; 程式敘述結束符號 程式區塊 以 {} 符號包圍 習慣先括好後,再繼續往下寫 程式碼的縮排 擅用 Tab 鍵 方便找出錯誤

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering 跳脫字元 Escape Characters \’ :單引號 \” :雙引號 \\ :反斜線 \b :倒退一格 \n :換行 \t : tab 鍵 例: System.out.println(“A\tB\tC”); 例: System.out.println(“\”Java\””);

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Your Turn Practice Set up your programming environment. Write a program showing the following messages 1 st line: Your Student Number, eg. JS nd line: Your Name, eg. 王大明 3 rd line: “Hello everyone!”

National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information Engineering Your Turn 寫一隻 Java 程式在螢幕上顯示初以下圖形: 試著使用 System.out.print() 加上跳脫字元 ***** ** ***** ** *****