A hard-pressed programmer's thinking in java path

Source: Internet
Author: User

 

This article is a summary of the first chapter of thinking in java, hoping to help some people.

First of all, it is necessary to explain my background. I am a non-computer professional. I have been in the computer industry for two years, and I am a vulnerable group?

Thinking in java I never thought about reading this book at all, Nana? It's too thick... I don't know how I flipped through that day, so I Accidentally flipped through a chapter.

After reading this, I want to write something as much as possible. It is easy to understand and saves time. I forgot a lot of things and can find something to see. Why don't I go through the books? Answer: the syntax of a foreigner is not flattering! (It may be about translation. I suggest reading the English version ).

Let's go!

In chapter 1, it is recommended that you stop looking at it. Of course, the author also suggests this (you should also write it in chapter 1 ). however, let's take a look at the last summary in Chapter 1. I feel very honest about the words in it. the general meaning is "choosing your own path (think carefully), then choosing a language, there is no need to learn java", an old Chinese saying "Seek and then" is the truth.

Remember to think carefully. I am working on java for a year, and I am working on the frontend for a year on the right, which leads to a stuck salary.

------ Text portal -----

1. abstract process

In a sense, abstraction is "Imagination" (of course, it must be reasonable). From "abstraction" <----> "concrete", an object language is generated. For example:

'A & V female U' <---> 'Mr Cang '(this is an abstract concept .)

What is an object? Of course, it's not your female/boyfriend, 'Mr Cang 'is the object, it's the so-called 'docker '.

What is a class? It must be 'a & V female U '....

Therefore, what we like for male compatriots is 'class' (including many objects. How nice it is to have more objects! You know .);

Class is the manifestation of encapsulation, and the object is the specific implementation of encapsulation!

2. Have a chat about Class, that is, Class!

I used to have a problem. Why is the class a data type?

I used to think that classes and classes have many attributes, many methods, and attributes include the int, string, and Boolean types. So many types, how can we still use the class or data type? Now I understand that all these are scammers. If you want to get a class, don't think about anything. I will ask you, int B = 1, indicating that B is of the int type. boolean flag = false, indicating that the flag is of the boolean type. so class Cl, doesn't it mean Cl is of the class type. the class is not a data type. never be disturbed by the mess in the class.

3. Each object provides services

I feel that this problem cannot be understood. instructor Cang doesn't provide services for the majority of Otaku comrades, so the object must serve us. Therefore, what kind of service you need is what kind of object to create, of course, first, make sure that you have found the correct class (you cannot find 'programmers class' ---> 'Mr Cang !)

4. Let's talk about the visible range.

Public (accessible)> propected (accessible by inheritance)> default (accessible by this package)> private (no one can access it ).

Usually new users like to use public, so compilation is not prone to errors! But remember to use it according to your specific needs. You can modify the compilation errors to avoid any problems during the runtime.

5. encapsulation inheritance Polymorphism

The above mentioned Encapsulation has been mentioned, so I will not mention it here. Inheritance and polymorphism are common issues, because I dare not say that I fully understand inheritance and polymorphism, so I will analyze and analyze them from the perspective of newcomers.

Once I had an interview, let me talk about the difference between classes and interfaces? At that time, my answer was messy and attracted strong BS from the interviewer!

Let me talk about my thoughts at this time! Let's talk about abstract things first!

(1) class provides services (objects! Remember not !) Interfaces provide a set of standards (a group is related, of course)

(2) A class can inherit only one class, but multiple interfaces are implemented.

(3) services (methods) in the class are implemented (of course, they can not be implemented. The class in this case is called an abstract class ), methods In the interface must not be implemented (of course, if you use Eclipse IDE, a compilation error will be prompted ).

Of course, the above are all written in books. I don't know why the interviewer loves to ask these things.

Let's talk about the experience at work. inheritance is generally used for "modeling". What is modeling?

Modeling is to establish the relationship between classes, that is, the inheritance relationship between several classes. modeling directly affects your coding level. Sometimes I feel that modeling is more like designing. it's not because you wrote extends. If you have extended something, it's okay. sometimes we need some experience. to be honest, I currently use little inheritance. One of them is that the system modeling architects of the company have basically been built up. You only need to add the logic. On the other hand, you may not be able to do it yourself!

 

 

It is just a set up of models, layer by layer. how clear it looks.

 

It may be a little serious. In fact, I am not afraid of it. I cannot use it at work. I can't do it by myself. I can use it as I inherit it. I will know how to design it better when I use it more. however, the multi-purpose method is not to say that it is useless without a brain. You need to think about and summarize it. Otherwise, it will always be just an ape.

Let's talk about inheritance. Of course, polymorphism is also based on inheritance.

During programming, we often want to treat an object as a base class object rather than a specific type of the object to which it belongs.

What do you mean? Let me write a piece of code to explain it!

Public class polymorphismtest {public static void main (string [] ARGs) {bird = new springcuckoo (); callfly (BIRD );} public static void callfly (bird whickbird/* is written as bird is the so-called base class */) {whickbird. fly () ;}/ *** springcuckoo spring Juan, A **/class springcuckoo extends cuckoo {public void fly () {system. out. println ("*** spring cuckoo *** is flying .... ") ;}}/*** cuckoo is cuckoo or Cuckoo **/class cuckoo extends bird {public void fly () {system. out. println ("22222222222") ;}}/*** bird is a bird **/class bird {public void fly () {system. out. println ("111111111111111 ");}}

First, let's take a look at the hierarchical relationship between them! For example.

This is how I use polymorphism... the parameter is directly written as the parent class. then, when new is used as a subclass, you can call the subclass method. it may be hard to understand. I hope you can give me some advice.

 

 

6. Memory embodiment of the created object

In Java, the new object is dynamic. What is dynamic? That is, objects are created only when they are running the program, and then the corresponding memory space is opened to store these objects (these are all completed in the heap in the memory, heap ), c ++ knows the classes to be created during program compilation, it may be that something similar to a table is recorded in the memory (stored in the memory stack), and the corresponding space is opened during running. I personally understand this.

C ++: 1. Record the object table (during compilation) 2. Open up space (during runtime)

Java: 1. Record the object table and open up space (runtime)

From the above, we can see that Java is doing more than C ++ In the runtime, so it is slower than C ++ (of course for computers ). however, I don't know how big the difference is for more and more memory.

 

I hope you can write something that will inspire you and point out my mistakes.

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.