Java FAQ Notes

Source: Internet
Author: User

CMD prompt "could not find or load main class?"

1. Environment variable is not configured correctly

Check for corrections

2. Inconsistent program name and function entry

Check for corrections

3. Package used in the program: packages

Compile by using command: javac-d. ? Test.java (. Represents the current directory) instead of Javac Test.java

Runtime use command: Java packagename. Test instead of Java test

The string class is immutable, and once a string object is created, it cannot be changed!

Column: String s= "java"

s= "Python"

The first statement creates a string object with the content "Java" and assigns its reference to S.

The second statement creates a new string object with the content "Python" and assigns its reference to S.

But the "Java" string object still exists, but it can no longer be accessed because the variable s now points to the new object. S is just a reference to the object string.

After two statements are executed, there are two string objects in memory, a reference to the string object S.

Garbage collection mechanism and Finalize () method

1, Java provides the Finalize () method, the garbage collector is ready to release memory, the first call to finalize ().

(1). Objects are not necessarily recycled.

(2). Garbage collection is not a destructor.

(3). Garbage collection is only related to memory.

(4). Garbage collection and Finalize () are unreliable, as long as the JVM is not running out of memory to the point where it will not waste time on garbage collection.

2. Garbage collector:

(1). In Java, when you create an object, the Java Virtual Machine (JVM) allocates memory for the object, calls the constructor, and starts tracking the object you are using. When you stop using an object (that is, when there is no valid reference to the object), the JVM marks the object as disposed by the garbage collector.

(2) When the garbage collector is about to release the memory of an object, it invokes the Finalize () method of the object, if the object defines this method. The garbage collector runs as a stand-alone, low-priority party , and it only starts to run the freed object's memory when other threads are suspended waiting for the memory to be released. (In fact, you can call the System.GC () method to force the garbage collector to release memory for these objects.) )

(3) In the above description, there are some important things to be aware of. First, Finalize () is performed only when the garbage collector frees the object's memory. If the garbage collector does not free memory before the Applet or application exits, the garbage collector will not call Finalize ().

3. The advantages and disadvantages of the Finalize () method:

(1) According to the Java documentation, finalize () is a method for releasing non-Java resources. However, the JVM has a large likelihood of not invoking the Finalize () method of the object, so it is difficult to justify the use of this method to release resources.

(2) Java 1.1 solves this problem in part by providing a system.runfinalizersonexit () method. (Do not confuse this method with the System.runfinalizations () method in java1.0. Unlike the System.GC () method, the System.runfinalizersonexit () method does not immediately attempt to start the garbage collector. Instead, when an application or Applet exits, it invokes the Finalize () method for each object.

Java FAQ Notes

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.