The Java programming language notes

Source: Internet
Author: User
Tags net thread

 

1, static member

You can use the null reference of this class object to reference this class static member.
Someclass OBJ = NULL;
OBJ. staticmethod ();
OBJ. staticdata = 1;

It is not recommended to reference static members with objects, but why is it not as prohibited as C?

2. Multi-Inheritance

In the face of the same signature method inherited from multiple interfaces, the subclass seems to provide only one implementation. How can we ensure the correctness of semantics? C # You can provide an implementation for each method that inherits the same signature from multiple interfaces in the subclass.

3. Local class, Anonymous class, and interface internal class

The only problem with innovative syntax facilities provided by languages in design is that they should not be abused.

4. Chaotic Array

It seems that the phrase "the apple basket is not a fruit basket" is violated, and the subclass array can be transferred where the base class array is required, thus losing the type security during compilation, avoid errors by running exceptions

5. Order of Value

Clearly defines from left to right.

6. Scope

Partial variables and parameters can block member variables.
The local variable cannot have the same name as the parameter.
A more local variable cannot have the same name as a peripheral local variable.
Shanmo Dayu

7. Comma expression

There is no comma expression. The one in for is not

8, break label

Powerful functions, replacing flag and goto

9. Exception

Compared with the returned error code, exceptions are at that level of AOP.

10. Different treatment of exception declaration and Return Value

The same one cannot be used as the basis for overload. The difference is that when override is used, the exception declaration can be relaxed as a subclass, but the return value cannot be relaxed as a subclass for the same reason, that is, covariant.

11. Class locks and instance locks

Irrelevant

12. synchronization between the server and the client

The former protects internal data, and the latter ensures the call sequence.

13, main

Everything has a begin, has an end ------- matrix revolution
I guessed the beginning, but I couldn't guess the ending.

Java programs start with main, but may not end with main until the last user thread exits ;? If the main thread starts a user thread, and the thread starts another thread, even though I am dead, there are sub-databases; the sub-databases are born again, and the sun has children; the child has the child, and the child has the sun. Son, sun, and sun

First chicken or egg? What is the origin of human beings? One day, people may trace to the extreme, but find that the JVM only started the main, but the JVM crashed when the world was destroyed.

The. NET thread is similar to this.

14. j2se 1.5 regressing

Static Import
Formatted output formatted output
Formatted input
Variable Parameter varargs

I can't believe it. I 'd rather learn C than C ++.

15. Proxy

In those years, templates were introduced in C ++ to generic programming, but they accidentally discovered the powerful functions of Generative programming. They did not know what the original intention of the proxy in Java was, but it caused another form of Generative programming-the trend of AOP

16. classloader

Open a backdoor in the program. The bytecode of a class is downloaded from my personal website. Don't be found by the customer. Change it later.

17. Language, database, platform, and fuzzy boundary

Is the String concatenation operator "+" a part of the language or a part of the database?
During serialization/deserialization, is the private method that can be called by virtual machines part of the language or part of the database?
Softrefrence, weakrefrence, and other classes used by virtual machines to process core language features such as object references are part of the language or a part of the library?

Java is not platform-independent. It is a platform itself. It is not good, but different from traditional languages.

18, @ deprecated

Compared with XDoclet and other tools, the. NET attributes and other features touch Java's nerves earlier: Annotations actually affect compiler behavior! Finally developed Java with Annotation

19. Different override concepts

Java/C #: as long as the access permission permits, you can call the override method, regardless of whether the subclass object is constructed
C ++: If the subclass object is constructed, you can call the override method regardless of the access permission.

The consequence is:

Java/C #: Call a method in the base class constructor. As long as the subclass has the permission to overwrite, it will be adjusted to the implementation of the subclass.
C ++: The methods called in the base class constructor/destructor will always be the implementation of the base class and will not be adjusted to the subclass; in other methods, it will always be adjusted to the override Implementation of the subclass, whether it is private or not.

20, Io

Byte is non-semantic, so it is called Stream
The characters are semantic, so they are called reader and writer.

You need to adapt non-semantic to semantic, such as inputstreamreader and outputstreamwriter.
Practical, called dataxxx, object serialized, called objectxxx

21. java. Io. File

Put the wrong place. It is actually the abstraction of the file system. It has nothing to do with IO. It should be placed in the system package and tied with thread and so on.

22, Collections

The general design principle is that the precondition of the subclass rewriting method should be weaker than that of the parent class method, but collection and its subclass do not comply with this principle in a timely manner, which proves that any principle has a applicability; collection is designed to be as generic as possible, rather than Runtime polymorphism. You still need to select an appropriate data structure, although it is sometimes referenced only through the collection Interface

23, iterator

Unlike STL, iterator provides internal secure remove () and add (). However, traversal is not secure, and it is different from STL again, iterator can detect external changes and throw exceptions from my protection instead of generating undefined behaviors.

24, timer (), timer (true)

The most common but not the most convenient one, you have to remember the parameters; you can use two creation methods, you can use two subclasses, even if you use parameters, you should also use enumeration instead of Boolean, oh, forget that there is no enumeration before 1.5, so the static constant, new timer (timer. deamon) and new timer (true), which one is clearer?

25. fragile private

Except that the access permission is compromised by the platform during serialization/deserialization, the default security settings include class. newinstance () can also be used to construct instances of classes declared as private by the ctor. The effect is that developers who want to force the customer code to use IOC principles can, you can safely declare bean ctor as private.

(The C # Programming Language notes)
(Corner of j2se 5.0)

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.