JavaEE learning record 2 (JavaOO knowledge Review), javaeejavaoo

Source: Internet
Author: User

JavaEE learning record 2 (JavaOO knowledge Review), javaeejavaoo

1. Differences between super () and this:

This (): the object of the current class, the object of the super parent class.
Super (): When a subclass accesses members and behaviors of the parent class, it must be subject to the class inheritance rules.

This indicates the current object. Of course, all resources can be accessed.
In the constructor, if super () is not written in the first line, the compiler inserts it automatically. However, if the parent class does not have a constructor without parameters, or the function is private (modified using private ). In this case, you must add the instantiation structure of the parent class. This does not have this requirement, because it itself carries out the construction of Instantiation. In the method, the super () and this () methods are similar. Only super needs to consider whether it can access the resources of its parent class.

 

2. What are the differences between the public, protected, and private scopes and when no data is written?

Public: can be used and accessed in different packages, classes, or the same package.
Protected: protected members can be accessed by classes in the same package, or by subclass of the class, regardless of the package in which the subclass is located. Private: can only be used and accessed in the same class
When not written: it can only be used in the same package and class.

 

3. Java event delegation and garbage collection:

(1) concept of java event delegation mechanism-a source generates an event and sends it to one or more listeners. In this solution, the listener simply waits until it receives an event. Once the event is accepted, the listener will process the event and then return it.
(2). Garbage collection mechanism-garbage collection is the process of recycling or releasing memory allocated to objects but no longer used. If an object does not point to its reference or its value is null, this object is suitable for garbage collection.

 

4. What is java serialization? How to Implement java serialization?

(1). serialization:
Serialization refers to the mechanism for processing objects. The so-called object stream is to stream the object content. You can perform read and write operations on Streaming objects, or transfer streaming objects between networks. Serialization aims to solve the problems caused by read/write operations on Object streams.

(2). serialization implementation:
The Serializable interface is implemented for the class to be serialized. There is no method to implement this interface. implements Serializable is only used to mark that the object can be serialized, and then an output stream (such: fileOutputStream) to construct an ObjectOutputStream (Object stream) Object. Then, you can use the writeObject (Object obj) method of the ObjectOutputStream Object to write the Object whose parameter is obj (that is, to save its status ), the output stream is used for recovery.


---------------------------------------------------------
5. Can a ". java" source file contain multiple classes (not internal classes )? What are the restrictions?

(1). It can contain multiple classes.
(2). The restriction is that if the modifier of this class is public, its class name must be the same as the file name.

 

6. What are the features of the final class?

1. Attribute Constants
2. Method overriding (overwritten)
3. The class cannot be inherited.

 

The sorting methods include:

1. Insert sorting method (direct insert sorting and Hill sorting)
2. Exchange sorting method (Bubble sorting and quick sorting)
3. Select sorting method (directly select sorting and heap sorting method)
4. Merge Sorting
5. Sort allocation (Box sorting and base sorting)


The java code is as follows:

Bubble sorting method:

Import java. util .*;
Public class Test02 {
Public static void main (String [] args ){
Int [] arr = {, 12 };
System. out. pringtln (Arrays. toString (arr ));
For (int I = 0; I <arr. length; I ++ ){
For (int j = 0; j <arr. length-1-i; j ++ ){
If (arr [j] <arr [j + 1]) {
Int temp = arr [j];
Arr [j] = arr [j + 1];
Arr [j + 1] = temp;
}
}
}
}
System. out. println (Arrays. to. String (arr ));
}

========================================================== ====================
Select sorting method:

Import java. util .*;
Public class Test03 {
Public static void main (String [] args ){

Int [] arr = {, 12 };
System. out. pringtln (Arrays. toString (arr ));
For (int I = 0; I <arr. length-1; I ++ ){
For (int j = I + 1; j <arr. length; j ++ ){
If (arr [I]> arr [j]) {
Int temp = arr [I];
Arr [I] = arr [j];
Arr [j] = temp;
}
}
}
System. out. pringtln (Arrays. toString (arr ));
}
}

========================================================== ==========
Insert a data sorting method: (insert one to the data sorting method .)

Import java. util .*;
Public class Test04 {
Public static void main (String [] args ){
Int [] arr = {, 19 };
Int [] arr1 = new int [arr. length + 1];
For (int I = 0; I <arr. length; I ++ ){
Arr1 [I] = arr [I];
}
Running in = new Processing (System. in );
System. out. println ("enter a number :");
Int num = in. nextInt ();
Int index = arr1.length-1;
For (int I = 0; I <arr1.length; I ++ ){
If (arr1 [I]> num ){
Index = I;
Break;
}
}
For (int I = arr1.length-1; index; I --){
Arr1 [I] = arr1 [I-1];
}
Arr1 [index] = num;
System. out. println (Arrays. toString (arr ));
}

}
========================================================== ============================

 

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.