Summary of Java programming ideas and methods
I always felt that the book was too wordy. After reading the summary, it would be easier to recall later. I wanted to be lazy and look for other people's summaries online, but I couldn't find a good one, so I had to do my best to summarize it as best as possible.
Introduction to Objects
I feel like this after seeing Introduction to Objects This book
Contents:
1.1 Abstraction process
1.2 Each object There is an interface
1.3 Each object provides services
1.4 Hidden concrete implementation
1.5 Reusing concrete implementation
1.6 Inheritance
1.7 Interchangeable objects with polymorphism
1.8 Single root inheritance structure
1.9 Container
1.10 Creation and lifetime of objects
1.11 Exception handling: handling errors
1.12 Concurrent programming
1.13 Java and the Internet
1.14 Summary
I feel like I will finally become proficient in Java after reading this. However, this chapter only introduces the basic concepts of OOP including an overview of development methods, and understands the importance of objects.
1.1 Abstraction process
Explain the orientation through the shortcomings of other languages Object language is good.
Assembly language is a slight abstraction of the underlying machine. Imperative languages (such as C and BASIC) are an abstraction of assembly language. Assembly language directly controls the computer's hardware. Imperative languages Languages are based on computer structures to solve problems. OOP languages solve problems based on the structure of the problem and are not restricted to any specific type of problem.
1.2 Each object has an interface
Interface: determines what can be issued to a specific object Request Object: Type name
Looking at the text description, it has risen to a philosophical issue. It is easy to understand from the following example.
Light lt = new Light(); //对象lt.on;//接口向对象发出请求
1.3 Each object provides services
Benefits: 1. Helps improve the cohesion of software 2. Each object can complete a task well, but it does not try to do more things.
Understanding: Design a music player that has lyrics display, playback, pause, and background display (service). At this time, don’t just provide an object (it doesn’t try to do more Things), can provide three objects to complete three services, and three objects provide three services to complete a music player (Cohesion).
1.4 Hidden specific implementation
Download a framework from Github, my goal is to achieve For rapid application development, the framework only needs to provide me with method calls, and hiding the others will not affect my calls.
Access permissions: public > protected (package + base class) > package access permissions (default when there is no keyword) > private
1.5 Specific implementation of reuse
Reuse refers to using inheritance or combination in a class.
- Inheritance----is the relationship of a Lychee is a fruit
- combination- ---Has a relationship There is a way to sleep on your stomach
Derive a subclass from the parent class. The subclass can absorb the data attributes and behaviors of the parent class, and can expand new capabilities.
1.7 Interchangeable objects with polymorphism
class Shape{ draw(); erase(); move(); getColor(); setColor(); }
void doSomething(Shape shape){ shape.erase();//...shape.draw(); } Circle circle = new Circle(); //父类为ShapeTriangle triangle = new Triangle(); //父类为ShapeLine line = new Triangle(); //父类为ShapedoSomething(circle); doSomething(triangle); doSomething(line);
对doSomething的调用会自动地正确处理,而不管对象的确切类型(可互换对象)。
doSomething(Shape shape)的执行是指你是Shape类或者父类为Shape,而不是你是Circle类就执行这样,你是Triangle 类就执行那样。理解了可以去看设计模式之策略模式。
这里还涉及到向上转型,如下图:
1.8 单根继承结构
1、所有类都继承自单一的基类
public class JianCheng extends Object { }
public class JianCheng { public static void main(String[] args) { JianCheng jiancheng= new JianCheng(); System.out.println(JianCheng instanceof Object); } }
Output: true //ExplanationJianCheng class inherits by defaultObject
2. Ensure that all objects have certain functions
Object methods will be inherited by subclasses, such as: clone(), equals( Object obj), toString() and other methods.
3. Garbage collection becomes easy
The object is guaranteed to have its (Object) Type information, so you don't get stuck in an inability to determine the type of an object. This is important for system-level operations (such as exception handling).
1.9 Container
holds access to other objects References are called containers (collections), such as List (used to store sequences), Map (also known as associative array, used to establish associations between objects), Set (only one of each object type is held), and such as Queues, trees, stacks and more.
Comparison between ArrayList and LinkedList, the former is the shape of an array, randomly accessing elements has a small overhead, but insertion and deletion operations have a high overhead. The latter is in the shape of a linked list, insertion and deletion operations are easy to operate.
1.10 Object Creation and Lifetime
Understanding The difference between objects placed on the stack and the heap
Allocation and release between stack-- are given priority Position,sacrifice flexibility, becausemust know the exact number, lifetime and type of objects.
##Heap--dynamically created objects in the memory pool at runtime Know the number, lifetime and type of objects. Dynamic management requires a lot of time to allocate storage space in the heap, but creating storage space and releasing storage space is very convenient.
#Java adopts By using the new keyword to create an object using dynamic memory allocation, the compiler can determine how long the object will survive and automatically destroy it through the "garbage collector mechanism".
##1.11 Exception handling: handling errors
Exception is an object that is thrown from the error location and is caught by a specific type of error exception handler, through try--catch or throw. Exception handling is like another path that is executed when an error occurs, parallel to the normal execution path of the program.If the Java code does not write the correct exception handling code, you will get a compile-time error message. For example: IOException, ClassCastException (class conversion exception), NullPointerException (null pointer exception), etc.
1.12 Concurrent ProgrammingProcess multiple processes at the same time The idea of tasks is to run in multiple threads.
There is a hidden danger in synchronous multi-threaded operation, shared resources. A originally wanted to use a=Love You, but a certain thread led to a=hate you and then A used it, so A's confession will definitely fail.
1.14 Summary
##The first chapter is all theoretical knowledge, and many knowledge points are obviously easy However, the long explanation makes it difficult to understand. There is some practical information but it is mixed with too much fluff.
The above is the detailed content of Summary of Java programming ideas and methods. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

Spring Boot simplifies the creation of robust, scalable, and production-ready Java applications, revolutionizing Java development. Its "convention over configuration" approach, inherent to the Spring ecosystem, minimizes manual setup, allo
