In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use the construction method of Java". In the daily operation, I believe that many people have doubts about how to use the construction method of Java. The editor has consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the construction method of Java". Next, please follow the editor to study!
object-oriented
Class and object: a class is a template for an object, and an object is an instance of a class.
Method and statement block
The definition modifier of a method returns the value of the method name (parameter name) {return return value;}
Method call 1, class name. Method name 2, object. Method
Method overloading (overload) has the same name, but different parameter lists, such as System.out.println ()
Command line parameter transfer-- JVM tuning
Variable length parameter. Must be placed on the last parameter
Recursion
Packet mechanism
Domain name backwards
Import
JavaDoc
Help documentation
Javadoc
@ author @ Version @ Since
@ param @ return @ throws
Where the cmd command:
Javadoc-encoding utf-8-charset utf-8 HelloWorld.java
Construction method
When it comes to constructor overloading, the new Car () parameter is different, so are the constructed objects.
The default is no parameter constructor. If you manually define a parameter constructor, you must define another parameter free constructor manually.
Singleton mode, the constructor must be privatized
Class Singleton {/ / 1. Privatize constructor private Singleton () {} / / 2. The object that creates the class internally private static Singleton instance = new Singleton (); / / 3. Provide a public static method to get an instance of the class public static Singleton getInstance () {return instance;}}
The stack stores references and the heap stores specific objects
The memory of Java virtual machine can be divided into three areas: stack Stack, heap Heap, and method area Method area.
The stack is private to threads and cannot be shared between threads! The stack describes the memory model of method execution; each method is called to create a stack frame (storing local variables, operands, method exits, etc.) JVM creates a stack for each thread, the stack is used to store the information of the thread's execution method (actual parameters, local variables, etc.) the stack is automatically allocated by the system, fast, and the stack is a continuous memory space
JVM has only one heap, which is shared by all threads to store created objects and arrays (arrays are also objects); heap is a discontiguous memory space with flexible allocation and slow speed
JVM has only one method area, which is actually a heap shared by all threads, and is only used to store class and constant-related information! Used to store the content that is always the same or the only one in the program. (class information [class object], static variables, string constants, etc.)
Three feature packages of Java
Property is private, and corresponding get and set methods are provided
Inherit
Extends keyword
Object is the parent of all classes
The subclass has all the features of the parent class (including method overrides of the subclass)
The relationship between this and super
Polymorphisms
The reference to the parent class points to the object of the child class (provided that inheritance and overrides of the parent-child class methods are required)
The use of the instance of keyword, if matched, can be converted to a type
Modifier
Public 、 protected 、 private 、 default 、 static 、 final 、 abstract
The first four of them are the provisions on the access scope of methods and attributes.
Static static
Final
Modifier variable: once a variable is assigned, it can no longer be assigned
Decorating methods: methods cannot be overridden (appear in inheritance)
Modifier class: this class cannot be inherited, such as Math, String, etc.
Abstract
Modifier method: only the method name, no method body
Decorating class: a class that contains an abstract method must be an abstract class. By abstracting the class, the inherited subclass must define the concrete implementation of the method (a bit "interface").
So what are abstract classes for?
It is only used for inheritance, and the method must be implemented by a subclass; it cannot be instantiated, that is, it cannot new ()
?? Interface interface
Interfaces are more abstract than abstract classes (abstract classes can also have concrete implementations, interfaces cannot have implementations at all)
Is a constraint that can only define the method name
The subclass implements the interface, and the methods in it must be specifically implemented.
The interface of only one method is called functional interface, which can be simplified by using lambda expressions.
Interfaces can implement multiple inheritance, but classes can only inherit only
Inner class
Local inner class
Static inner class
Anonymous inner class (no need to create a new object)
Abnormal
Master interface: Throwable
Exception
"Runtime exception" includes NullPointer, subscript out-of-bounds exception, ClassNotFound
Error
JVM error, including StackOverflow, OutOfMemory
Five keywords
Try 、 catch 、 finally 、 throw 、 throws
At this point, the study on "how to use the construction method of 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.