Java Programming Ideas (4th Edition) Scanning Edition

Java Programming Ideas - Essentials

Java basics must-have books!

It is not difficult to see that this book is a classic from the awards it has won and the comments from readers all over the world. The author of this book has many years of teaching experience, has unique and in-depth insights into C, C++ and Java languages, and explains each obscure and abstract concept with easy-to-understand and small and direct examples. This book has 22 chapters, including operators, control execution flow, access control, reusable classes, polymorphism, interfaces, error handling through exceptions, strings, generics, arrays, in-depth research on containers, Java I/O system, Enumerate types, concurrency, and graphical user interfaces. These rich contents include the basic grammar and advanced features of the Java language, suitable for reading by Java programmers at all levels, and are also taught by colleges and universities...

Chapter 1: Introduction to Objects
  This chapter is mainly to help us understand the overall picture of object-oriented programming, and it is more of a background and supplementary material for introduction. In fact, Mengxin should skip this chapter, because this chapter does not talk about grammar-related knowledge. Of course, you can read this chapter back and forth after reading the subsequent chapters of this book, which will help us understand the object The importance of , and how to use objects for programming.

Alan Kay once summarized five basic characteristics of Smalltalk, the first successful object-oriented language and one of the languages ​​​​on which Java is based. These characteristics represent a pure object-oriented programming approach:

Everything is an object. In theory, you can abstract any conceptual component of the problem you want to solve (a dog, a building, a service, etc.) and represent it as an object in your program.
A program is a collection of objects that tell each other what to do by sending messages. To request an object, a message must be sent to the object. More specifically, think of a message as a request to invoke a method on a particular object.
Each object has its own storage made up of other objects. In other words, new types of objects can be created by creating objects that contain existing objects.
Every object has its type. According to the general saying, "every object is an instance of a certain class (class)", the most important difference between each class and the characteristics of other classes is "what kind of messages can be sent to it".
All objects of a particular type can receive the same message.
Chapter 2: Everything is an Object
Manipulating Objects by Reference
  Every programming language has its own way of manipulating elements in memory. Sometimes, the programmer must pay attention to what type of data will be processed. Do you directly manipulate the elements, or use some kind of indirect representation of special syntax (such as pointers in C/C++) to manipulate objects?

All of this is simplified in Java. Everything is treated as an object, so a single fixed syntax can be used. Although everything is seen as an object, the manipulated identifier is actually a "reference" to the object. Think of the situation as operating a TV (object) with a remote control (reference). As long as you hold this remote, you can stay connected to your TV. When someone wants to change the channel or turn down the volume, it is the remote control (reference) that actually controls the TV (object). If you want to move around the room while still being able to control the TV, you only need to carry the remote (reference) instead of the TV (object). In addition, even without a TV, the remote control can exist independently. In other words, you have a reference, you do not necessarily need to have an object associated with it.

When the program
  is running, how is the object placed and arranged? In particular, how is memory allocated? Knowledge of these areas will help you a lot. There are five different places where data can be stored:
1) Registers. This is the fastest memory because it's in a different place than the other memory -- inside the processor. But the number of registers is extremely limited, so registers are allocated as needed. You have no direct control, nor can you feel any indication of the presence of registers in your program (C and C++, on the other hand, allow you to suggest to the compiler how registers are allocated).
2) Stack. Located in general purpose RAM (Random Access Memory), but has direct support from the processor via the stack pointer. If the stack pointer moves down, new memory is allocated; if it moves up, that memory is freed. This is a fast and efficient method of allocating storage, second only to registers. When a program is created, the Java system must know the exact lifetime of all items stored on the stack in order to move the stack pointer up and down. This constraint limits the flexibility of the program, so while some Java data is stored on the stack—especially object references—Java objects are not.
3) Heap. A common memory pool (also located in the RAM area) used to store all Java objects. The advantage of the heap is that it is different from the stack: the compiler does not need to know how long the stored data will live on the heap. Therefore, there is a lot of flexibility in allocating storage on the heap. When you need an object, you only need to write a simple line of code with new, and when this line of code is executed, it will automatically allocate storage in the heap. Of course, there is a price to pay for this flexibility: heap storage allocation and cleanup may take more time than stack storage allocation (if it is indeed possible to create objects on the stack in Java as in C++ ).
4) Constant storage. Constant values ​​are usually stored directly inside the program code, which is safe because they can never be changed. Sometimes, in an embedded system, the constant itself is isolated from other parts, so in this case, it is an option to store it in ROM (read-only memory).
5) Non-RAM storage. If the data lives entirely outside the program, it can be independent of any control of the program and can exist even when the program is not running. Two basic examples of these are stream objects and persistent objects. In stream objects, the object is converted into a stream of bytes, usually sent to another machine. In "persistent objects", objects are stored on disk so that they retain their state even if the program terminates. The trick with this type of storage is turning objects into things that can be stored on other media, and then restored to regular, RAM-based objects when needed. Java provides support for lightweight persistence, while mechanisms such as JDBC and Hibernate provide more complex support for storing and reading object information in the database.

insert image description here
insert image description here

insert image description here

insert image description here

Summary: Download the scanned version

提示:这里对文章进行总结:

no advertising

There are concerns that require a full scanned versionjava progressreplyprogramming ideasTake it yourself, and finally wish you all success in your studies, come on!

insert image description here
no advertising

Guess you like

Origin blog.csdn.net/qq_42429369/article/details/130816478
Recommended