Java EE Learning record 2 (Javaoo knowledge Review)

Source: Internet
Author: User

The difference between 1.super () and this ():

This (): Object of the current class, Super parent class.
Super (): Access to the members and behaviors of the parent class in the subclass must be constrained by the class inheritance rule.

And this represents the current object, and of course all resources can be accessed.
In the constructor, if the first line does not write super (), the compiler will insert it automatically. But if the parent does not have a constructor that does not have a parameter, or if the function is privatized (decorated with private). At this point you must join the instantiation construct of the parent class. This does not have this requirement, because it is an instantiation of the structure itself. In the method, super () and this () use the same method. Only Super wants to consider whether it can access the resources of its parent class.

2. What are the differences between scope public, protected, private, and when not written?

Public: can be used and accessed in different packages, classes, or in the same package
Protected: A protected member can be accessed by a class in the same package, and can also be accessed by subclasses of the class, regardless of which package the subclass is in. Private: Can only be used and accessed in the same class
When not written: can only be used in the same package and in the class.

3.Java Event delegation mechanism and garbage collection mechanism:

(1). The concept of the Java event delegation mechanism-a source that generates an event and sends it to one or more listeners. In this scenario, the listener simply waits until it receives an event. Once the event is accepted, the listener handles the event and then returns.
(2). Garbage collection mechanism-the process of collecting or releasing memory that is assigned to an object but is no longer used. If an object does not have a reference to it or its assignment is null, this object is appropriate for garbage collection.

4. What is Java serialization? How do I implement Java serialization?

(1). Serialization:
Serialization refers to the mechanism by which objects are processed, so-called object flow, which is the flow of the object's contents. You can read and write to a Fluidized object, or you can transfer the streamed object between the networks. Serialization is a problem that is raised when reading and writing to an object stream.

(2). Serialization implementation:
The class that needs to be serialized implements the Serializable interface, which has no method to implement, implements Serializable just to annotate that the object can be serialized. A ObjectOutputStream (object flow) object is then constructed using an output stream (for example, FileOutputStream), followed by the writeobject of the ObjectOutputStream object obj) method to write out (that is, save its state) the object with the parameter obj, and the output stream to restore.


---------------------------------------------------------
5. Can a ". Java" source file contain more than one class (not an inner class)? What are the restrictions?

(1). Is can contain more than one class.
(2). The restriction is: if the modifier of this class is public, its class name must be the same as the file name.

What are the characteristics of the 6.final class?

1. Property constants
2. Methods cannot be overriding (rewritten)
3. Classes can not inherit

The sorting methods are:

1. Insert Sort method (Direct insert sort, hill Sort)
2. Exchange sorting method (bubble sort, quick sort)
3. Select the sorting method (direct selection of sorting, heap order method)
4. Merge sort
5. Allocation Sorting (box sorting, base sorting)


The Java code is as follows:

Bubble Sort Method:

Import java.util.*;
public class test02{
public static void Main (String [] args) {
Int[] arr={1,8,9,3,2,5,6,4,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 the sorting method:

Import java.util.*;
public class test03{
public static void Main (String [] args) {

Int[] arr={1,8,9,3,2,5,6,4,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));
}
}

================================================
Inserts a number Sort method: (Inserts a number sort of one.) )

Import java.util.*;
public class test04{
public static void Main (String [] args) {
int [] arr={1,5,8,10,15,19,34,60};
int [] arr1=new int[arr.length+1];
for (int i=0;i<arr.length;i++) {
Arr1[i] =arr[i];
}
Scanner in = new Scanner (system.in);
System.out.println ("Please 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));
}

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

Java EE Learning record 2 (Javaoo knowledge Review)

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.