Six java novice entrance questions every day the road to freedom

  • 2021-10-13 07:48:57
  • OfStack

Directory 1. Interview Step 1: Introduce yourself. 2. Would you please briefly describe your understanding of object-oriented and the difference between object-oriented and process-oriented? 1. Personal understanding: 2. Object-oriented 3. Process-oriented 3. Then what are the characteristics of object-oriented 4. Excuse me: Can we inherit String class? 5. What's the difference between final, finally and finalize? 6. What is the difference between String, StringBuilder and StringBuffer? Summarize

1. Interview Step 1: Introduce yourself.

This self-introduction can be said to be the first step in the whole interview. If you can say the key points you want to say and bring the interviewer to the technical points you have prepared, it can be said that you have successfully introduced yourself this time!

Then say what self-introduction needs to include: basic information, educational background, work experience, project experience, personal growth and so on.

It can be said that templates are basically similar, but each technical point, work experience and project experience are quite different. Therefore, highlight the points you grasp and catch the interviewer's eye.

Templates:

For example: Hello, interviewer, my name is xxx. I graduated from xx School in 18 years, majoring in xx. I have worked in x for years since graduation, and worked in x companies during the development of Java.
The first company is xxx, which is engaged in xxx. In java, I am mainly responsible for/participated in xxx project, and in this project, I am mainly responsible for xxx functional module. In this company, I gained the biggest growth is xxx (technical and work aspects), and I left this company because of xxx (I can explain what I did without saying the reason for leaving my job).

The second company is xxx, my last company. This company is doing xxx. I am mainly responsible for xxx in this company. My gain in this company is xxx. I left this company because of xxx (I can explain what I did without saying the reason for leaving my job).

Usually, I will often learn technology, or write some technical blogs, such as my WeChat official account, and CSDN blog has Prince Nezha (you can also add one of your usual hobbies, and even write any blog or GitHub address, which can give yourself extra points!)

Therefore, this is relatively extensive and can be played freely. Play the first step well, and the following information is relatively sufficient. When I interview personally, I am often very nervous, but once I introduce myself, the interviewer asks me about the technical points mentioned in my self-introduction, and I will be relatively confident personally. I will talk with the interviewer for a long time and have a good time. In fact, interviews are two-way, he is choosing you, and you are choosing him, so don't worry, don't be too nervous. Just say what you are prepared!

2. Would you please briefly describe your understanding of object-oriented and the difference between object-oriented and process-oriented?

1. Personal understanding:

The idea of software development is process-oriented first, and then object-oriented. In large software systems, the process-oriented approach is insufficient, so object-oriented is introduced. They are all ways of thinking to solve practical problems. The two complement each other, and grasp the relationship between complex things in macroscopic object-oriented; Microscopically, process-oriented processing. Process-oriented function development is the main way to realize functions; Object-oriented first abstracts classes, attributes and their methods, and then completes the function by instantiating classes and executing methods. Process-oriented is encapsulation is function; Object-oriented encapsulates data and functions. Object-oriented has inheritance and polymorphism; Process-oriented does not.

2. Object-oriented

Advantages: Easy to maintain, easy to reuse, easy to expand, because of the object-oriented encapsulation, inheritance, polymorphism characteristics, can design a low-coupling system, so that the system is more flexible and easier to maintain. Disadvantages: Performance is lower than process-oriented.

3. Process-oriented

Advantages: The performance is higher than object-oriented, because the class needs instantiation when calling, which costs more and consumes resources; For example, single chip microcomputer, embedded development, Linux/Unix and so on adopt process-oriented development, and performance is the most important factor. Disadvantages: No object-oriented easy to maintain, easy to reuse, easy to expand.

Hmm? That's a good talk! It seems that there is a corresponding understanding in it! Not bad, I'll test you one more question.

3. Then what are the following aspects of object-oriented features

Object-oriented features have four specific aspects: encapsulation, inheritance, abstraction and polymorphism.

Encapsulation: Encapsulation privatizes the properties of an object and provides access to an object that can be accessed by the outside world. Inheritance: Inheritance is the process of creating a new class by obtaining inheritance information from an existing class. The class that provides inheritance information is called a parent class, and the class that obtains inheritance information is called a subclass. By using inheritance, we can easily reuse the previous code. Abstraction: Abstraction is the process of summarizing the common characteristics of class 1 objects and constructing classes, including data abstraction and behavior abstraction. Polymorphism: The so-called polymorphism means that the specific type pointed to by the reference variable defined in the program and the method call issued by the reference variable are uncertain when programming, It is determined during the running of the program, that is, the instance object of which class a reference variable will point at, and the method call issued by the reference variable is the method implemented in which class, which must be determined during the running of the program. In fact, calling the same method with the same object will react differently.

4. Excuse me: Can we inherit the String class?

No, when we look at the source code of String, we can find that the String class is modified by final and cannot be inherited.


public final class String
    implements java.io.Serializable, Comparable<String>, CharSequence {
    .....
}

And what is the role of final?

When decorating a class: It means that the class cannot be inherited. When decorating a method: The representation method cannot be overridden. When modifying a variable: It means that the variable cannot be assigned once and can no longer be modified.

Therefore, the advantages of String modified by final are: safety and high efficiency. And when only the string is immutable, we can realize the string constant pool, which can cache the string for us and improve the running efficiency of the program.

5. What's the difference between final, finally and finalize?

final: Modifiers (keywords) are used in three ways: If a class is declared as final, it means that it cannot derive new subclasses, that is, it cannot be inherited, so it is the opposite of abstract. Declaring variables as final ensures that they will not be changed in use. Variables declared as final must be given initial values at the time of declaration, and can only be read and unmodified in future references. Methods declared as final are also usable only and cannot be overridden in subclasses. finally: Usually placed in try … catch … handling exceptions, it means that the code here will execute whether the program executes normally or an exception occurs. 1 is to put the code for releasing resources in finally block. finalize: Is a method defined in the Object class, where the finalize () method is allowed to do the necessary cleanup before the garbage collector removes the object from memory. This method is called by the garbage collector when destroying the object.

6. What is the difference between String and StringBuilder and StringBuffer?

First, String and StringBuilder, StringBuffer are all capable of storing and manipulating strings.

String It uses the final keyword character array to hold strings, so the String object is immutable. Both StringBuilder and StringBuffer are inherited from the AbstractStringBuilder class, which also uses character arrays to hold strings, but is not modified by final, so it is mutable. However, the method in StringBuilder is not modified by synchronized, so its efficiency is higher than that in StringBuffer. In terms of safety: The object of String is immutable, so it is thread safe. StringBuffer is also thread-safe because it has a synchronization lock on the method, but StringBuilder does not have a synchronization lock, so the thread is not safe. In terms of performance: Each time the String type is changed, a new String object is generated and the pointer is pointed to the new String object. Each time StringBuffer and StringBuilder are modified, the object itself can be operationally modified instead of generating a new object and changing it into an object reference. Usage scenario: Use String if you want to manipulate a small amount of data. StringBuilder is used to operate a large amount of data under a single thread operation string buffer. Multithreaded operation string buffer under the operation of a large amount of data using StringBuffer.

Summarize

That's all for this article. If this article is helpful to you, I hope you can pay more attention to more contents of this site!


Related articles: