This article has made a relatively comprehensive summary of the basic knowledge of the Java programming language, and I would like to share it with you here. Friends in need can refer to it.
Basic knowledge of Java
1. Advantages of Java language:
1) Java is Pure object-oriented language
2) Platform-independent, compile once and run everywhere
3)Java provides many built-in class libraries
4) Provides support for web applications
5) Has good security (array boundary detection, Bytecode detection) and robustness (enforcement mechanism, garbage collector, exception handling )
6) Remove some features that are difficult to understand in c++ (header file pointer operator overloading multiple inheritance)
2. Similarities and differences between java and c++:
1) Java is an interpreted language, and C++ is a compiled language. Java will be slow but cross-platform
2) Java is purely object-oriented, and C++ is both object-oriented and Objects can also be process-oriented. Java has no global variables and global functions
3)Java has no pointers, which is safer
4)Java does not support multiple inheritance but has the concept of interface
5) Java does not require manual allocation and management of memory (application for release), and provides automatic recycling by the garbage collector. When there are no references to the object on the stack or static storage, it will be recycled. There is no destructor, but there is a finalize() method.
6) Java has no operator overloading and no preprocessing function.
3. public static void main(String [] args) is the entry point of the program.
4. Java can have multiple main() files, but only the main() of a class decorated with public that has the same name as the file can be used as a program. Entrance. Note: There is and is only one class that is modified by public and has the same name as the file.
5. The static block is executed before the main function . Initialization execution sequence: parent static variable parent static code block child static code variable child static code block parent non-static variable parent non-static code block parent class constructor child non-static variable child non-static code block child class constructor
6. Constructor:
1) The same name as the class, no return value
2) There can be multiple, according to Parameters are different
3) Always called with new operation
4) Mainly used to initialize objects
5) Cannot be inherited
6) Super can be used to explicitly call the parent class constructor
7. Shallow copy only copies the object under consideration, not the object it refers to. Deep copy both copy
8. What is the difference between object-oriented and process-oriented:
1) Oriented The object is to deal with the problems of the objective world in a way that is consistent with conventional thinking, while the process-oriented is event-centered and modular.
2) Object-oriented is to bring the computer world closer to the objective world and make problem processing clearer. Process-oriented is a module that clearly and accurately expresses processes, abstracting problems in the objective world into processes that can be processed by computers.
9. Object-oriented features and advantages: Abstraction, inheritance, encapsulation, polymorphism has higher development efficiency, and code can be reused. Higher maintainability and clearer code.
10. Java only supports single root inheritance, extendsInheritance is an is a relationship, and combination is a has a relationship.
If you can use combination in Java language, try not to use inheritance.
11. Polymorphism:
Overloading (there are multiple methods with the same name in the same class) Horizontal relationship
Rewriting (subclass rewrites parent class, method name and parameter list are the same) Vertical relationship
12. Similarities and differences between abstract classes and interfaces:
1) As long as it contains an abstract method, it is an abstract class. All the methods of the interface are abstract methods, which is called a pure abstract class.
2) Subclasses of abstract classes need to implement the abstract methods of the parent class.
3) The variables in the interface default to: static final and must be assigned an initial value.
4) The interface is implemented using implements. A class can implement multiple interfaces to achieve a relationship similar to multiple inheritance.
5) The interface is used for commonly used functions, such as adding and deleting. Abstract classes are used for the role of public classes in daily life and are not suitable for frequent code modifications
13. The difference between this and super:
This is used to point to the current instance object
Super is used to access the methods and member variables of the parent class
When a subclass inherits the parent class, super(in the subclass constructor) ) must be placed as the first sentence.
14. The difference between break continue return:
Break is used to forcefully jump out of the current loop without executing the remaining code
Continue is used to stop the current cycle and return to the starting point for the next cycle.
Return jump is used to indicate returning from a method.
Break out to jump out of multiple loops
15. The role of static:
a Allocate a single value to the object Storage space has nothing to do with the number of objects created
b Implement a method or attribute and class rather than associate it with the object
C Variables can achieve global effects , there is only one copy in the memory
16. Implementation of immutable classes:
All member variables in the class are modified by private
No set method is written
Class definition final
##17 , the difference between passing by value and passing by reference:
18. There are eight basic data types. The priority of type conversion: byte cannot be interchanged with booleam.
20. String s1="abc" is an object stored in the constant area
21. "==" and "equals"
22. Arrays are also objects. Arrays provide the length attribute to get the length of the array, and String is calculated through length().
23. Exception handling
Java IO: Byte stream (8 bits) does not use cache Character stream (16 bits) uses cache
25. Socket is called a socket. Used to implement communication between different virtual machines or different computers.
There are JVM and java API.
, Garbage collection GC: Recycle memory that will no longer be used. Three tasks: allocate memory; ensure that referenced memory is not incorrectly reclaimed; and reclaim memory for objects that are no longer referenced.
28. Memory leak problem in java:
29. The difference between heap and stack in java:
30. Container: java Collections framework: list, Queue, set, stack, maplist, Queue, set, and stack all inherit the Collection interface.
1) List is an ordered Collection. Objects are saved in the order in which they are entered, and duplicate objects can be saved.
2) Set is the concept of a set, and there cannot be duplicate elements in the set.
3) Map is a data structure that maps keys to values. Values can be repeated, but keys are unique and cannot be repeated.
31. Iterator: It is an object, a method of accessing each element of a container object without exposing the internal details of the object.
1) Use the iterator() method of the container to return an Iterator, and then return an element through the Iterator's next() method.
2) Use Iterator's hasNext() method to determine whether there are any elements in the container. If so, you can use next() to get the next element.
3) Use remove() to delete the elements returned by the iterator.
32. The difference between collection and collections:
Collection: is a collection interface that provides maximum unified operations for each specific collection.
Collections: It is a wrapper class for collection classes. It cannot be instantiated and is equivalent to a tool class that serves the Collection framework.
33. Multi-threading:
Thread: an execution unit that executes code.
Process: an executing program
Each thread shares the memory space (code segment, data, heap space) of the program and has an independent stack space.
Advantages of threads:
1) Reduce the response time of the program
2) Compared with the process, the cost of creating a switch is small
3) Multiple CPUs and multi-cores inherently have multi-threading capabilities
4) Simplify the program structure for easy understanding and maintenance.
34. How to implement java multi-threading:
1) Inherit the Thread class and override the run() method
2) Implement the Runnable interface and implement the run() method of the interface.
3) Implement the Callable interface and rewrite the call() method.
35. Synchronization
#To achieve synchronization operation, you must obtain the lock of each thread object. Obtaining it can ensure that there is only one thread object at the same time. The thread can enter the critical section, and before the lock is released, other threads can enter the critical section again. If there are other threads that want to obtain the lock of the object, they can only enter the waiting queue and wait.
36. Implementation method of multi-process synchronization:
1) synchronized keyword
2) Wait () method and notify () method
3) Lock
37. Methods to terminate threads: stop() method and suspend() method.
Java provides two types of threads: daemon thread (service process) and user process.
38. How to access the database through JDBC:
1) Load the JDBC driver and copy the JDBC driver jar package to lib
2) Load the JDBC driver
3) Create a database connection
4) Create a Statement object or PrepareStatement object. Used for database operations
5) Execute SQL statements
6) Access the result set ReaultSet object
7) Close the ReaultSet Statement in sequence Connection.
39. The function of the Class.forName() method is to load the class into the JVM.
Before using JDBC to connect to the database, the Class.forName ("com.mysql.jdbc.Driver") method is generally called to load the driver.
Statement is used to execute a simple SQL statement without parameters and return the object of the result it generates. Every time SQL is executed, the database compiles the SQL statement.
PrepareStatement is executable with parameters. Higher efficiency, higher readability, maintainability, and better security
40. JDBC provides getString(), getInt(), getIData() and other methods to obtain data from ResultSet .
41. The number of connection pools is limited when connecting to JDBC, so be sure to release connections that are no longer used.
createStatement and prepareStatement are best placed outside the loop, and they need to be closed in time after using the statement. It is best to close the statement immediately after executing executeQuery once.
42. Hibernate is the encapsulation of JDBC. The database connection parameters are written into XML in the form of a configuration file, but
the final access to the database must be completed through JDBC.
43, Hibernate is a persistence layer framework, which maps the information in the table to XML, and then maps the XML file to the corresponding persistence class.
Java Web
1. The role of the browser:
1), complete the interaction with the server.
2) Complete the parsing of HTML and display the content that users need to see in intuitive information.
2. HTTP request methods are: GET POST HEAD TRACE OPTIONS
GET: is the simplest request method, obtained from the server side The resource required by the user and returned to the client as a response. Get server-side information (query). If you need to upload data, add it to the end of the URL. Data exposure is not secure enough and is limited in quantity.
POST: In addition to obtaining resources from the server, you can also upload data to the server. The uploaded data is not displayed in plain text in the URL, and a large amount of data can be uploaded, which is invisible to the user
3. Servlet:
is written in Java language The server program runs in the Servlet container in the Web server. Its main function is to provide a request and response service model and can generate dynamic Web content.
When the Web server obtains a request for a servlet, it will hand it over to the Tomcat container for processing, and the container will respond to the request by calling the Servlet method (doGet() doPost()).
Steps:
Initiate a servlet request——>The Web server is handed over to the container for processing——>The container creates two objects HttpServletResponse HttpServletRequire——>Create a separate Thread, and pass the two objects into the thread in the form of parameters -> The thread container calls doGet() or doPost() in the Servlet's service() method to complete the response -> The container returns the response message in the form of HTML to client.
4. Servlet life cycle:
Loading——>Creation——> Initialization——> Processing customer request—— —> Uninstall
5. Advantages of JSP:
JSP: HTML file with embedded java code. Mainly solves the separation of servlet and HTML. Separate business logic and views.
6. Similarities and differences between JSP and servlet:
Same:
are essentially Servlet files, as long as The work that JSP can complete can be completed using Servlet. JSP will eventually be converted into a servlet to run.
Different:
Servlet is in the control layer, mainly for process control and business processing. JSP is in the view layer and is mainly used for display.
Servlet does not have built-in objects. The built-in objects in JSP are mainly obtained through the HttpServletResponse object and the HttpServletRequire object.
7. MVC model:
Model layer (M): implements system business logic. JavaBean or EJB
View layer (V): realizes user interaction. JSP
Control layer (C): Realizes the logical control of views and models. servlet
8. Control layer:
The controller receives user input and calls the model and view to complete.
The controller itself does not output anything or perform any processing.
Just receive the request and decide which model to use to process the request, and decide which view to use to display the model processing return data
9. Advantages of MVC:
1) Low coupling to achieve separation of the view layer and the logic layer.
2) High reusability and applicability
3) Rapid deployment
4) Easy maintenance
10. What is the difference between forward and redirect in Servlet:
Forward is a redirect within the server. The server directly accesses the URL of the target address, and the address remains unchanged.
Redirect: Client redirection, complete jump, address change.
11. JSP built-in objects:
1) require (request object)
2) Response (Response object)
3) pageContext (page context object)
4) Session (session object)
5) Application ( Application object)
6) Out (output object)
7) Config (configuration object)
8) Page (page Object)
9) Exception (Exception object)
12. Method of request object:
1 ) setAttribute (String name, Object) sets the attribute value of name
2) getAttribute (String name) gets the attribute value of name
3) getParameter (String name) Get the data submitted by the user, the name corresponds to the name of the form
4) getSession() is used to obtain the session related to the request
13, JSP Actions in:
1) JSP: include is used to introduce a file when the page is requested
2) Jsp: useBean is used to instantiate a javabean
3) Jsp:setProperty is used to set the properties of the instantiated bean object
4) Jsp:getProperty is used to obtain the properties of the instantiated bean object
5) Jsp:foward is used to jump the request to another page
14. Include instructions and include actions in JSP
Command: <% @include file =”test.jsp “%>
Action:
15. Session tracking Technology:
Monitor the same user's continuous requests to the server and receive responses.
1) page a page
2) Request a request
3) Session a user experience
4) Application The entire Web application
16. String encoding: GBK, UTF-8
17. What It's Ajar
Asynchronous js and XML.
Combines java technology, js technology, and xml technology. Client technology
Function: Improve the interactivity of the page by interacting with a small amount of data with the server without refreshing the page, reduce the response time, and improve the user experience
18, cookies and The difference between session:
Session: refers to the solution and storage structure used to maintain state between the client and the server.
Cookie: A small file saved on the user's browser by the web server.
19. Web server: receives the request from the client, and then feeds the processing result of the request back to the client
Two major web Server: IIS Apache.
20. Web container: TomcatJBoss
is responsible for providing http request and response objects to the servlet, calling doGet() through the doPost() method Handle user requests.
21. Category of EJB:
1) Session Bean implements server-side business logic and coordinates the interaction between beans
2) Entity Bean (Entity Bean) data component represents the record in the database
3) Message Bean (Message-driven Bean) processes asynchronous messages, generally not by the user To call
22. Similarities and differences between EJB and Javabean:
1) EJB: mainly used for server-side development, Javabean is mainly used in Client development.
2) EJB components can be deployed in the EJB container. The components are not accessed directly, but through the container. Javabeans cannot be deployed
3) EJB is a distributed object , can be called remotely, javabean is not, and can only be accessed internally
23. The role of EJB:
1) Enterprise Bean Provider (Enterprise component developer)
2) Application Assembler (application composer)
3) EJB Deployer (EJB deployer)
4) EJB Sever Provider (EJB server provider)
5) EJB Container Provider (EJV container provider)
6) System Administrator (system administrator )
24. Working mechanism of database connection pool:
Reason:
1) Establishing a database is Very time-consuming operation
2) The number of database connections is limited
The database connection pool is responsible for allocating, managing and releasing database connections. When a client needs to access the database, it can directly obtain the database connection from the pool without creating a connection and mark it as busy.
25. Tuning methods for JAVAEE development:
1) Optimize design
2) Try as much as possible Use database connection
3) Use framework
4) Optimize I/O
5) Optimize query
26. Advantages of struts framework:
1) Realize the separation of performance and logic
2) Provide page navigation function
3) Provide form validation
4) Provide database connection pool
5) Provide exception handling mechanism
6) Support internationalization
27. Data verification is divided into:
1) Form verification
2)Business logic verification
28. Internationalization:
The program will display corresponding information according to different regions without modifying the internal code. The interface
29. What is inversion of control:
Also known as dependency injection, a design idea that reduces the coupling relationship between objects .
So that the upper layer does not depend on the interface of the lower layer, the caller (child) determines the callee (parent). Decoupling and purpose are achieved by injecting an instantiated object.
30. Spring framework
provides good support for lightweight loc and also provides a very good encapsulation of AOP technology.
31. Hibernate framework, persistence layer framework
Realizes the mapping of Java objects and relational database records, simplifying the process for developers to access the database. Improve the efficiency of software development
Anyone who uses JDBC can use Hibernata
Methods to improve performance:
1) Lazy loading
2) Caching technology
3) Optimizing query statements
32. Implement paging:
1)Hibernate’s own paging mechanism
2)Use SQL statement to implement, use the limit keyword
33, SSH:
struts implementation view part
Hibernate implementation model part
Spring implementation business part
Using the SSH framework can not only achieve complete separation of views, controllers and models, but also achieve separation of business logic and data persistence layer
Summary
The above is the detailed content of Summary analysis of Java basic knowledge. For more information, please follow other related articles on the PHP Chinese website!