Current location - Music Encyclopedia - Chinese History - Java programming directory
Java programming directory
Chapter 1 Java language

Introduction to Java language 1. 1 1

The emergence of Java language

Composition of Java language 1. 1.2 1

Install 1.2 development environment 3

1.3 Simple Java application 4

1.3. 1 Java application example 4

1.3.2 Using Java Core API Document7

Exercise 9

Chapter II Object-Oriented Programming Technology 1 1

2. 1 Basic concepts of object-oriented programming technology 1 1

2. 1. 1 What is an object-oriented programming method 1 1?

2. 1.2 What are classes and objects 12?

2. 1.3 Important features of object-oriented 14

Comparison of OOP ability between Java and C++ 16

Exercise 18

Chapter 3 Identifiers and Basic Data Types 19

3. The basic grammatical unit of1Java is 19.

3. 1. 1 blanks, comments and statements 19

3. 1.2 Keyword 2 1

3. 1.3 Identifier 2 1

3.2 Java coding style 22

3.3 Basic data types of Java 23

Variables and constants 23

Basic data type 23

3.3.3 Description and Assignment of Variables 28

Exercise 30

Chapter 4 Expressions and Process Control Statements 3 1

4. 1 expression 3 1

4. 1. 1 operand and operator 3 1

4. 1.2 expression promotion and type conversion 40

4.2 Process Control Statement 43

4.2. 1 expression statement 43

4.2.2 Area 44

4.2.3 Branch Statement 45

4.2.4 Loop statement 52

4.2.5 Interrupt and Continue Presentation 54

Exercise 56

Chapter 5 Classes and Objects 60

5. 1 class definition and object creation 60

5. 1. 1 class definition format 60

5. Creation and Initialization of1.2 Object 63

5.2 Construction Method 64

5.2. 1 Construction method and its overload 64

5.2.2 Default Construction Method 66

5.3 Definition Method 67

Method definition format 68

5.3.2 Pass 7 1

5.4 Inheritance of categories 72

5.4. 1 Definition of inheritance

5.4.2 Polymorphism and Transformation Object 74

5.5 Continue to discuss Java keywords 77

5.5. 1 static 77

5.5.2 Final and Summary 79

5.5.3 Ben and Super 84

5.6 Method Rewriting 86

5.6. 1 Overview of method rewriting 86

5.6.2 Rules for applying rewriting 89

5.6.3 Call the parent class constructor 89

5.7 Interface 90

5.7. 1 Fuzziness in Multiple Inheritance 90

5.7.2 Definition of Interface 9 1

5.7.3 Implementation of Interface 9 1

5.8 Java package 94

5.8. The concept of1Java package 94

Import declaration 95

5.9 Internal Grade 97

5.9. The concept of1inner class 97

5.9.2 Anonymous classes 99

Exercise 100

Chapter 6 Array, Container and String 107

6. 1 array 107

6. 1. 1 array description and initialization 107

6. Use of1.2 array 1 14

6.2 Container and pipe string 1 18

6.2. 1 container 1 18

6.2.2 String 1 19

Exercise 123

Chapter 7 Exceptions in Java Language 126

7. 1 exception example 126

7.2 Exception handling 130

7.2. 1 Exception Handling Related Reports 130

7.2.2 Male * * * Exception 132

7.3 Throwing Statement 133

7.4 Create your own exception 135

Exercise 137

Chapter 8 Graphical User Interface Design 140

8. 1 AWT and slewing 140

8. 1. 1 AWT package and Swing package 140

8. 1.2 Components, containers and content pane 14 1

8.2 Rotary components 143

8.2. 1 button 143

Label 146

8.2.3 combo box 148

Text component 150

Menu component 150

Dialog box 152

8.3 Layout Manager 153

8.3. 1 General Layout Manager 154

8.3.2 Other Layout Manager 156

8.4 Interface Design Details 160

8.4. 1 control component appearance 16 1

8.4.2 Prompting tools and mnemonics 162

8.5 Event Handling 162

8.5. 1 Brief introduction to the incident 162

8.5.2 Event handling of component 164

8.5.3 Event Type 176

Event adapter 179

Exercise 180

Chapter 9 Java applet 182

9. 1 Writing applet 182

9. 1. 1 applet example 182

9. 1.2 applet design process 183

9.2 methods used in applet 183

Basic method 184

9.2.2 Method of Displaying Applet 184

9.3 HTML document 185

Mark 185

9.3.2 Reading applet parameters 186

9.3.3 applet and URL 187

9.4 multimedia processing in applet188

9.4. 1 Display images in applets 188.

9.4.2 Play sound in applet 189.

9.5 Event handling of applet 189

Exercise 19 1

Chapter 10 Java data stream 192

The basic concept of 10. 1 data stream 192

10. 1. 1 input data stream 193

10. 1.2 output data stream 193

10.2 basic byte data stream class 193

10.2. 1 file data stream 193

10.2.2 Filter data stream 195

10.3 basic character stream 195

10.4 file processing 20 1

10.4. 1 file class 20 1

10.4.2 Random Access File 202

Exercise 203

Chapter 1 1 Thread 204

1 1. 1 threads and multithreading 204

1 1. 1

1 1. 1.2 thread structure 205

1 1.2 thread status 205

1 1.3 Create Thread 206

1 1.3. 1 inherited thread class 206.

1 1.3.2 implements the runnable interface 208.

1 1.4 thread control 209

1 1.4. 1 start of thread 2 10

1 1.4.2 Thread Scheduling 2 10

1 1.4.3 Pause Thread 2 12

1 1.4.4 Interthread communication 2 12

Exercise 2 13

Chapter 12 Network Functions of Java 2 16

12. 12 16 Overview

Introduction to the basic concepts of12.1.165438

12. 1.2 Use InetAddress 2 17.

12.2 Uniform Resource Locator 2 18

Concept of Uniform Resource Locator 2 18

12.2.2 Create URL 2 18.

12.2.3 URL related exception 2 18

12.2.4 get URL object properties 2 19

12.2.5 read in URL data 220

12.3 socket interface 22 1

1 Basic concept of socket 222

12.3.2 Basic steps of socket communication 223

12.3.3 socket communication programming 223

Exercise 225

After nearly 20 years' development and perfection, the reference 226 Java language has become more and more powerful and widely used. From programs in handheld devices such as mobile phones to various enterprise applications, Java can be seen. Java has become a world-class programming language and the first choice tool for programmers.

In foreign higher education, Java language has been included in the teaching plan of computer undergraduate. Moreover, some professional basic courses also use Java language as a description tool, such as data structure, calculation methods and other courses. The situation in China is similar. Many key universities have set up Java language courses for undergraduates majoring in computer science. This trend has gradually expanded from key universities to ordinary universities, and more and more schools have offered this course. Many schools have taken Java as the first programming language for related majors.

While Java language is gradually entering the classroom of colleges and universities, we also find that ordinary colleges and universities are relatively short of teaching materials that can be used as Java language courses. It is true that there are many reference books in Java language on the market, and the quality is quite high. However, due to different audiences, quite a few of them are not suitable as teaching materials, especially the first programming language course for undergraduates in ordinary universities. Therefore, we decided to write this book, hoping to provide help for undergraduate teaching in colleges and universities. In addition, this book can also be used as a reference book for professionals to learn the Java language. I hope this book can become a paving stone for readers to enter the Java hall.

This book is divided into 12 chapters. After briefly introducing the characteristics of Java language, the second chapter focuses on the basic concepts and methods of object-oriented programming. At the same time, considering that many readers may already know C++ language, let's make a simple comparison between C++ and Java language. The concept of object-oriented programming is independent of languages, but the implementation details of various languages are different. The content of this chapter aims to help readers who have not been exposed to object-oriented programming technology.