《JAVA OOP开发》英文版 Chapter 2 Java Programming Basics

Chapter 2 Java Programming Basics ntroduction to Object-Oriented Programming with Java 2000 McGraw-Hl‖ Chapter 2-1
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java-- Wu Chapter 2 - 1 Chapter 2 Java Programming Basics

Chapter 2 objectives After you have read and studied this chapter, you should be able to Identify the basic components of Java programs Distinguish two types of Java programs-applications and applets e Write simple Java applications and applets e Describe the difference between object declaration and object creation e Describe the process of creating and running Java programs. e Use mainWindow and message Box classes from the javabook package to write Java applications Use the graphics class from the standard Java package C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2-2
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 2 Chapter 2 Objectives After you have read and studied this chapter, you should be able to Identify the basic components of Java programs. Distinguish two types of Java programs-applications and applets. Write simple Java applications and applets. Describe the difference between object declaration and object creation. Describe the process of creating and running Java programs. Use MainWindow and MessageBox classes from the javabook package to write Java applications. Use the Graphics class from the standard Java package

The First Java Application r a program to display a window on the screen r The size of the window is slightly smaller than the screen, and the window is positioned at the center of the screen with a default title sample Java Application r The fundamental OoP concept illustrated by the program An object-oriented program uses objects. C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 2-3
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 3 The First Java Application A program to display a window on the screen. The size of the window is slightly smaller than the screen, and the window is positioned at the center of the screen with a default title Sample Java Application. The fundamental OOP concept illustrated by the program: An object-oriented program uses objects

Program MyFirstApplication Program MyFirstApplication This program displays a window on the screen. The window i positioned at the center of the screen, and the size of the almost as big as the screen class MyFirstApplication public static void main(string[] args) Mainwindow mainwindow Declare a name mainWindow new Mainwindow()i create an object lainWindow. setvisible( true )i Make it visible C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2-4
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 4 Program MyFirstApplication /* Program MyFirstApplication This program displays a window on the screen. The window is positioned at the center of the screen, and the size of the window is almost as big as the screen. */ import javabook.*; class MyFirstApplication { public static void main(String[ ] args) { MainWindow mainWindow; mainWindow = new MainWindow(); mainWindow.setVisible( true ); } } Declare a name Create an object Make it visible

Object Diagram for MyFirstApplication MyFirstApplication main Window Main Window main true setvisible C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 2-5
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 5 Object Diagram for MyFirstApplication MyFirstApplication main MainWindow mainWindow setVisible true

Flow of the My FirstApplication Program MainWindow mainWindow; mainWindow new Mainwindow()i mainWindow. setvisible( true )i mainWindow MainWindow State-of-Memory Diagram C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 6 Flow of the MyFirstApplication Program MainWindow mainWindow; mainWindow = new MainWindow(); mainWindow.setVisible( true ); mainWindow MainWindow State-of-Memory Diagram

Object Declaration Class Name This class must be defined Object Name before this declaration can One object is declared be stated here MainWindow mainWindow MO Account customer ore Examples Student Jan, jim, jon, Vehiclecar. car2 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 2-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 7 More Examples Object Declaration Class Name This class must be defined before this declaration can be stated. Object Name One object is declared here. MainWindow mainWindow; Account customer; Student jan, jim, jon; Vehiclecar1, car2;

Object creation Object Name Class Name Argument Name of the objectve An instance of this class is No arguments are used are creating here created mainWindow new MainWindow More customer=new Customer() Examples Jon new Student( John Java) car new Vehicle(): C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 8 Object Creation Class Name An instance of this class is created. Object Name Name of the object we are creating here. mainWindow = new MainWindow ( ) ; Argument No arguments are used here. More Examples customer = new Customer( ); jon = new Student(“John Java” ); car1 = new Vehicle( );

Distinction between declaration and creation Customer customer i customer new Cus tomer()i customer new Cus tomer( )i customer Created with the Created with the second first new Customer Customer new. Reference to the first Customer object is lost C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2-9
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 9 Distinction Between Declaration and Creation Customer customer; customer = new Customer( ); customer = new Customer( ); customer Customer Customer Created with the first new. Created with the second new. Reference to the first Customer object is lost

Sending a message object Name Name of the object to Method Name Argument which we are sending a The name of the message The argument we are message we are sending passing with the message mainWindow. setVisible( true) More account deposit( 200.0) Examples student setName(john) car l. startEngine() C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2-10
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 2 - 10 Sending a Message Method Name The name of the message we are sending. Object Name Name of the object to which we are sending a message. mainWindow . setVisible ( true ) ; Argument The argument we are passing with the message. More Examples account.deposit( 200.0 ); student.setName(“john”); car1.startEngine( );
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《JAVA OOP开发》英文版 Chapter 1 Introduction to Object-oriented Programming and Software Development.ppt
- 《JAVA OOP开发》英文版 Introduction to Computers and Programming Languages.ppt
- 《Windows DNA应用程式》 面向对象分析与设计讲义.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第四章 第四讲 分支结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十二章 文件.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十一章 复杂数据类型及排序.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第六讲 数组.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第六讲 数组.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第七章(7-2)指针与指针变量.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第五章 循环结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第二章 数据类型与运算符.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第二讲 数据类型与算术运算.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第九讲 函数.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第九章 函数.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第三章 运算符与表达式.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第三讲 运算与顺序结构.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第七章 指针.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第七讲 数据存储机制.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第一章 C语言基础.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第一讲 C语言基础.doc
- 《JAVA OOP开发》英文版 Chapter 3 Numerical Data.ppt
- 《JAVA OOP开发》英文版 Chapter 4 Defining Instantiable Classes.ppt
- 《JAVA OOP开发》英文版 Chapter 5 Processing Input with Applets.ppt
- 《JAVA OOP开发》英文版 Chapter 6 Selection statements.ppt
- 《JAVA OOP开发》英文版 Chapter 7 Repetition Statements.ppt
- 《JAVA OOP开发》英文版 Chapter 8 Characters and strings.ppt
- 《JAVA OOP开发》英文版 Chapter 9 objectives.ppt
- 《JAVA OOP开发》英文版 Chapter 10 Sorting and Searching.ppt
- 《JAVA OOP开发》英文版 Chapter 11 File Input and Output.ppt
- 《JAVA OOP开发》英文版 Chapter 12 Reusable classes and packages.ppt
- 《JAVA OOP开发》英文版 Chapter 13 GUI Objects and Event-Driven Programming.ppt
- 《JAVA OOP开发》英文版 Chapter 14 Inheritance and Polymorphism.ppt
- 《JAVA OOP开发》英文版 Chapter 15 Case Study Class Roster Maintenance program.ppt
- 《JAVA OOP开发》英文版 Chapter 16 Chapter 16 Recursive algorithms.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第一章 绪论.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第七章 牛行接与应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第三章 MCS-51单片机指令系统.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第九章 A/D、D/A转换接口.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第二章 MCS-51学机组成理.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第五章 输入/输出与中断.ppt