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