Java Programming Ideas Learning (1)

Source: Internet
Author: User

SmalltalkThis is the first successful object-oriented programming language and the basic language of Java. The five basic features of Smalltalk (Java's base language):(1) Everything is an object. The object can be imagined as a new variable; it holds the data, but it can be required to manipulate itself. Theoretically, all conceptual components can be presented from the problem to be solved, and then expressed as an object in the program.
(2) A program is a combination of a large set of objects; Through messaging, each object knows what to do. To make a request to an object, "send a message" to that object. More specifically, the message can be imagined as a call request, which invokes a subroutine or function that belongs to the target object.
(3) Each object has its own storage space, which can accommodate other objects. Alternatively, a new object can be created by encapsulating the existing object. Therefore, although the concept of objects is very simple, but in the program can achieve arbitrary high degree of complexity.
(4) Each object has a type. Each object is a "instance" of a "class", according to the syntax. Where the class
is a synonym for "type". The most important feature of a class is "what message can be sent to it?" ”。
(5) All objects of the same class can receive the same message. This is actually a statement that has no meaning, and we will understand it soon. Because an object of type ' circle ' also belongs to an object of type shape, a circle can receive shape messages entirely. This means that the program code can command the "shape" uniformly, so that it automatically controls all objects that conform to the "shape" description, which naturally includes "circles." This feature, known as the "replaceable" object, is one of the most important concepts of OOP. InterfaceA request to an object is defined by its "interface" (Interface), and the object's "type" or "class" specifies its interface form. The equivalence or correspondence between "type" and "interface" is the basis of object-oriented programming. Interface "(INTERFACE) specifies which requests can be made on a particular object. There are two reasons why we control access to members. The first reason is to prevent programmers from touching what they should not touch-often the design idea of internal data types. The second reason for access control is to allow the library designer to modify the internal structure without worrying about the impact it will have on the client programmer. For example, we might have designed a simple form class in the first instance to simplify development. Later, it was decided to rewrite it to make it run faster. If the interface and implementation methods have been isolated, and protected separately, can be assured that this point, only require users to relink.
"Public" means that any subsequent definition can be used by any person. Private means that no one else can access the subsequent definition information except for itself, the creator of the type, and the internal function member of that type. Private has erected a wall between you and the client programmer. If someone tries to access a private member, they get a compile-time error. "Friendly" (friendly) involves the concept of "wrapper" or "package"--the method that Java uses to build libraries. If something is "friendly", it means it can only be used within the scope of the package (so this level of access is sometimes called "wrapper access"). "Protected" (protected) is similar to "private", except that an inherited class can access a protected member, but not a private member. InheritanceThe simplest way to reuse a class is simply to use the object of that class directly. But you can also place an object of that class into a new class. We call this "create a member object".
The organization of the object has great flexibility. The new class's member objects are usually set to private, and client programmers using this class cannot access them. In this way, we can modify those members calmly without disturbing the customer code.
The meaning of inheritance: after we have tried to make a data type, it would be frustrating if we had to create a new type to achieve roughly the same functionality. However, it is much more desirable to use ready-made data types to "clone" them and then add and modify them as appropriate. "Inheritance" was designed to address this goal.
There are two ways to separate the newly derived classes from the original base classes. The first approach is simple: Add a new function (function) to the derived class. These new functions are not part of the underlying class interface. When doing this, it is common to realize that the underlying class does not meet our requirements, so we need to add more functions. This is one of the simplest and most basic ways to use inheritance, and most of the time it solves our problems perfectly. However, it is necessary to carefully investigate whether your base class really needs these additional functions.
Equivalence of inheritance and similar relationships: But in many cases, we must add new interface elements to the derived type. So it not only expands the interface, but also creates a new type. This new type can still be replaced by the underlying type, but this substitution is not perfect because the new function cannot be accessed in the underlying class. We call this a "similar" relationship; the new type has an interface of the old type, but it also contains other functions, so it cannot be said that they are completely equivalent. For example, let's consider the condition of a refrigerator. Suppose our room is connected with a variety of controllers for refrigeration, i.e. we have the necessary "interfaces" to control refrigeration. Now that the machine is faulty, we replace it with a new type of cold and hot air-conditioning, which can be used both in winter and in summer. Cold, hot air conditioning "similar" chillers, but can do more things. As our rooms are equipped with only refrigeration equipment, they are limited to dealing with the refrigeration parts of the new machine. The interface of the new machine has been extended, but the existing system does not know anything other than the original interface.
The process of treating a derived type as its basic type is called "upcasting" (upstream styling) when a message is sent to an object, and if you do not know what the other person's specific type is, the action taken is also correct, as in the case of "polymorphism" (polymorphism). For object-oriented programming languages, the method they use to implement polymorphism is called "dynamic binding".abstract base classes and interfaceswhen designing a program, we often want the base class to provide only one interface for its own derived classes. That is, we do not want anyone else to actually create an object of the underlying class, just go back and sculpt it to use their interface. To achieve this, the class needs to be "abstracted"-using the abstract keyword. If someone tries to create an object of an abstract class, the compiler will block them. This tool can effectively enforce a special design.
We can use "parameterized types", which are classes that compilers can customize automatically, and can mate with specific types.
Violation control "The error control scheme is built into the programming language, sometimes even built into the operating system." Java's violation control mechanism differs from most programming languages. Because in Java, the offending control module is encapsulated from the start, so it must be used! If you do not write some code to properly control the violation, you will get a compile-time error hint. This ensures the continuity of the program and makes error control easier. Note that violation control does not belong to an object-oriented feature, although in object-oriented programming languages, the violation is usually represented by an object. Prior to the advent of object-oriented languages, violation control existed. single-Root structureIn object-oriented program design, it is very important that the introduction of C + + is that all classes should ultimately inherit from a single underlying class. In Java (like almost all other OOP languages), the answer to this question is yes, and the name of the final base class is simple, an "Object". This "single-root structure" has many advantages.
All objects in a single structure have a common interface, so they eventually belong to the same type. Another scenario (just like C + +)
Is that we cannot guarantee that everything belongs to the same basic type. ThreadsThreads: In some cases, interrupts are necessary for tasks that are very real-time in nature. However, there are many other problems that only require dividing the problem into a separate running program fragment, allowing the entire program to respond more quickly to the user's request. In a program, these stand-alone fragments are called threads, and the concept of programming with it is called multithreaded processing.
The multithreading mechanism of Java has been built into the language, which makes a potentially more complex problem easier. Support for multithreading is supported at the object level, so an execution thread can be expressed as an object. Java also provides a limited resource locking scheme. It can lock any object's memory (memory is actually one of many shared resources), so only one thread can use a specific memory space at a time. To achieve this, the synchronized keyword is used. Other types of resources must be explicitly locked by the programmer, which usually requires the programmer to create an object that represents a lock that all threads must check when accessing that resource. client/server computingThe basic idea of client/server system is that we can centralize information resources in a unified place. Typically, the data is stored in a database, and the information is delivered to the other person or machine according to the request. A key to client/server overview is that the information is "centrally stored". So we can easily change the information and then distribute the modified information to the consumers of the information. The combination of elements, information warehouses, software used to deliver information, and the machine in which information and software are located are called "Servers". For the software that resides on the remote machine, they need to communicate with the server, retrieve the information, do the appropriate processing, and then display it on the remote machine, which is called the "customer" (client).
Transaction processing: One of the main issues to note is that a single server needs to provide services to multiple customers at the same time. In this mechanism, there is usually a set of database management system, so that designers can encapsulate the data layout in the table for optimal use. In addition, the system often allows customers to insert new information into a server. This means that it is important to ensure that the customer's new data does not conflict with new data from other customers, or that the data is not lost when it joins the database (in terms of the database
, this is called "Transaction processing").
Middleware: Support for multiple types of computers and operating systems is also a big problem. Finally, the issue of performance is particularly important: there are likely to be hundreds of clients that make requests to the server at the same time. So any minor delay can not be ignored. To mitigate the potential problems, programmers need to be careful to distract from the task's processing burden. It is generally possible to consider having a client load some of the processing tasks, but sometimes it can also be assigned to other machines where the server is located, which is also known as "middleware" (middleware is also used to improve system maintenance). Pluginswhen it comes to client programming, one of the most important issues is the plug-in design. With plugins, programmers can easily add new features to the browser, and users simply need to download some code and "insert" them in the appropriate location in the browser. The purpose of this code is to tell the browser "You can do these new activities from now on" (just download these inserts once). Some quick and powerful behaviors are added to the browser via plugins. But the writing of plugins is not a simple task. When we build a specific site, we may not want to work on this. For client-side programming, the value of a plugin is that it allows a professional programmer to design a new language and add that language to the browser without the permission of the browser creator. As you can see, the plugin is actually a "backdoor" to the browser, allowing the creation of new client-side programming languages (although not all languages are implemented as plug-ins). ActivexTo some extent, a strong competitor of Java should be Microsoft's ActiveX, although it uses a completely different set of implementation mechanisms. ActiveX was originally a pure Windows-only scenario. With the efforts of an independent professional association, ActiveX now has the ability to use across platforms. In fact, ActiveX means "If your program is connected to its working environment, it can go to the Web page and run in an ActiveX-enabled browser" (IE solidifies support for ActiveX, and Netscape needs a plugin). So, ActiveX does not restrict our use of a particular language. For example, let's say we're already an experienced Windows programmer who can skillfully use languages like C + +, Visual Basic, or Borlanddelphi to create ActiveX almost without any learning.
Component. In fact, ActiveX is the best way to use "legacy" code in our Web pages. The basic process of writing a program1, plan out2, clear what is to be made3, how to build4. Start building your own program5, to improve their own proceduresthis blog reference from: "Java programming thought Fourth Edition"

Java Programming Ideas Learning (1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.