Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
We will describe the basic structure of simple Java programs in this chapter. We will also describe the steps you follow to run Java programs. We expect you to actually run these sample programs to verify that your computer (either your own or the one at the school’s computer center) is set up properly to run the sample programs presented in the book. It is important to verify this now. | Chapter 2 Getting Started with Java Chapter 2 Objectives After you have read and studied this chapter, you should be able to Identify the basic components of Java programs. Write simple Java programs. Describe the difference between object declaration and object creation. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Objectives, cont. After you have read and studied this chapter, you should be able to Describe the process of creating and running Java programs. Use the Date, SimpleDateFormat, String, and JOptionPane classes from the standard Java packages. Develop Java programs using the incremental development approach. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 2.1 The First Java Program This first program displays a window on the screen. The size of the window is 300 x 200 pixels, and the default title is My First Java Program. The fundamental OOP concept illustrated by the program: An object-oriented program uses objects. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 2.1 The First Java Program /* Chapter 2 Sample Program: Displaying a Window File: Ch2Sample1.java */ import javax.swing.*; class Ch2Sample1 { public static void main(String[ ] args){ JFrame myWindow; myWindow = new JFrame(); myWindow.setSize(300, 200); myWindow.setTitle(“My First Java Program”); myWindow.setVisible(true); } } ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Fig. 2.1 Result of running the Ch2Sample1 program. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Fig. 2.2 The program diagram for the Ch2Sample1 program. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Fig. 2.3 The program diagram for the Ch2Sample1 program that shows the dependency relationship. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 2.1 The First Java Program To use an . | Chapter 2 Getting Started with Java Chapter 2 Objectives After you have read and studied this chapter, you should be able to Identify the basic components of Java programs. Write simple Java programs. Describe the difference between object declaration and object creation. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Objectives, cont. After you have read and studied this chapter, you should be able to Describe the process of creating and running Java programs. Use the Date, SimpleDateFormat, String, and JOptionPane classes from the standard Java packages. Develop Java programs using the incremental development approach. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. 2.1 The First Java Program This first program displays a window on the screen. The size of the window is 300 x 200 pixels, and the default title is My First Java Program. The fundamental OOP concept illustrated by the program: An .