Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic points for attention in Java

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what are the basic attention points of Java". In the daily operation, I believe that many people have doubts about the basic attention points of Java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "what are the basic attention points of Java?" Next, please follow the editor to study!

Variables (attributes and local variables) attributes

Defined in curly braces of the class

Local variable

Defined in the class's methods (formal parameters, method body), constructors (formal parameters, inside the constructor), code blocks

The difference between the two before

1. The difference in the location of the declaration

two。 Permission modifier:

Properties can be modified with private, default, protected, public

Local variables cannot be modified by permission modifiers

3. The default initialization is different:

Property does not have to show assignments when it is defined, because it is initialized by default (see Note Summary 1, default initialization of array elements)

Local variables are not initialized by default, and assignments must be displayed when declared (parameters can be assigned when called)

4. Different locations in memory

Property (not static): in the static domain of the static in the method area in the heap space

Local variables: in stack space

2. Methods

If a method does not return a value, then the role of return is to end the method.

Overloading of method

Different formal parameters with the same name (only see method name and formal parameter list)

Deformable parameter

1. The method of changing several parameters is the same as the normal name in this class, and there is no overloading between arrays with the same parameter type. In other words, the two cannot coexist. That is, it cannot be overloaded (can be rewritten)

two。 The variable number of parameters in the parameter of the method must be declared at the end

3. Variable number of parameters in a method, you can declare at most one variable parameter.

4. When calling the method of variable parameters, the number of parameters passed in can be: 0, 1, 2.

III. Encapsulation what is encapsulation

To put it simply, four kinds of permission modifiers are used to modify classes, properties and methods to achieve the effect of hiding what should be hidden and exposing what should be exposed.

The embodiment of encapsulation

1. Private the property xxx of the class, while providing a public method to getXxx and setXxx the value of this property

two。 Private methods that are not exposed to the public

3. Singleton mode (privatize constructors)

4. If you do not want the class to be called outside the package, you can set the class to the default

Scope type same class, same package, different packages under the same project, pirvate can be defaulted (default) can be protected can be explained by public

All four permissions can be used to modify the internal structure of a class: properties, methods, constructors, inner classes.

If you modify a class, you can only use: default, public

Fourth, the function of constructor (construction method)

1. Create an object (new an object entity)

two。 Initialize the information of the object

Description

1. If the constructor of the class is not explicitly defined, the system provides a constructor with null parameters by default

two。 Multiple constructors defined in a class are overloaded with each other

3. Once we have explicitly defined the constructor of the class, the system no longer provides the default empty parameter constructor (no empty parameter constructor).

4. In a class, there will be at least one constructor

5. This keyword

Callable structures: properties, methods, constructors

Understanding: current object or currently being created

This calls the constructor

Format: this (parameter); to call the constructor in the current object

1. In the constructor of a class, we can explicitly use the "this" method to call other constructors specified in this class.

two。 The constructor cannot call itself through the "this" method.

3. If there are n constructors in a class, at most "this" is used in n-1 constructors, because one must be super () to load the structure of the parent species.

4. Must declare the first line in the constructor body

5. Within the constructor, at most one "this" can be declared to call other constructors

VI. The use of Import

1. Explicitly import the classes and interfaces under the specified package using the import structure in the source file

two。 Declared between the declaration of the package and the declaration of the class

3. If you need to import multiple structures, you can write them side by side.

4. You can use "xxx.*" to indicate that you can import all structures under the xxx package.

5. If you are using a class or interface defined under the java.lang package, you can omit the import structure

6. If you are using a class or interface defined under this package, you can omit the import structure

7. If a class with the same name under different packages is used in the source file, at least one class must be displayed as a full class name.

8. Using the "xxx.*" method indicates that the structure under the xxx package can be called. However, if you are using the structure under the xxx subpackage, you still need to explicitly import

9. Import static: imports a static structure: property or method in a specified class or interface.

At this point, the study of "what are the basic points for attention in Java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report