"Java Basics Summary"-for beginners who learn Java for 0 basics

Source: Internet
Author: User

Java Fundamentals Summary, for most people who want to learn the Java programming language, or for those who are already on the road to the novice, master the following Java fundamentals, perhaps will be more conducive to you grasp the language quickly. The following is my basic knowledge of Java to do a brief summary, if there is a mistake, but also hope that everyone's generous enlighten.

1. Initialization of Objects

(1) initialization of non-static objects

When an object is created, all data members of the class in which the object resides are initialized first.

Base type: typeint , initialized to 0.

If object: These objects are initialized sequentially.

※ The constructor method of this class is called to create the object after all class member initialization is complete.

The function of the construction method is initialization.

(2) initialization of static objects

The static variables of the main class in the program are initialized before the main method executes.

When you create an object for the first time, all static variables in the class are initialized, and when you first access a static object of a class (note that no such object is created at this time), all static variables are initialized in the order in which they are in the class.

2.when inheriting, the initialization process of the object

(1) the superclass of the main class is high to low, initializing static members sequentially, regardless of whether static members are Private .

(2) initialization of the main class static member.

(3) The superclass of the main class is called from high to low for the default constructor method. Note that the initialization of non-static objects for this superclass is preceded by the invocation of the default constructor method for each superclass.

(4) initialization of non-static members of the main class.

(5) invokes the construction method of the main class.

3, about the construction method

(1) A class can have no constructor method, but if there are multiple constructors, you should have a default constructor, or, if you inherit this class, you need to explicitly invoke one of the non-default constructor methods of the parent class in the subclass.

(2) In a constructed method, you can call only one other construction method, and the statement that calls the constructor method must be the first statement.

4. About public,private and protected

(1) No Public A modified class that can be accessed by another class is: A. two classes in the same file, B. two classes in the same folder, c. two classes are in the same package.

(2) Protected: Classes that inherit classes and the same package can be accessed.

(3) if the construction method is Private , you cannot create objects of that class in other classes.

5. Abstract class

(1) Abstract classes cannot create objects.

(2) if a method in a class is an abstract method, the class must be Abstract abstract class.

(3) classes that inherit abstract classes must implement abstract methods in the abstract class in the class.

(4) Abstract classes can have abstract methods, or there can be non-abstract methods. The abstract method cannot be private.

(5) classes that indirectly inherit abstract classes may not give the definition of an abstract method.

6.final keyword

(1) An object is a constant that does not represent a member of an object that cannot be transformed and can still operate on its members.

(2) constants must be assigned before they are used, but in addition to being initialized at the same time as declarations, they can only be initialized in the constructor method.

(3) the final modified method cannot be reset (a method with the same name cannot appear in the subclass).

(4) If you declare a class to be a Final , then all of the methods are Final , whether or not it was Final decorated, but the data members can be Final it's not.

7, Interface interface(with implements to implement the interface)

(1) all data in the interface is Static and the Final that is, a static constant. Although these two keyword modifiers can be used, the Chang must be given an initial value.

(2) the methods in the interface are Public , in implementing an interface class, the implementation method must be Public key word.

(3) If you use Public to modify the interface, the interface must be the same as the file name.

8. Multiple Inheritance

(1) A class inherits a class and interface, the class must be written in front, the interface is written, and the interfaces are separated by commas.

(2) multiple inheritance between interfaces, note using keywords extends .

(3) A class that implements only one interface, but not only implements all the methods of this interface, but also implements the method of the interface inherited by the interface, all the methods in the interface must be implemented in the class.

9, the interface embedded

(1) interface in an embedded class, you can use the Private decoration. At this point, the interface can only be implemented in the class in which the other classes cannot access.

(2) the interface in the embedded interface must be Public .

the embedding of ten and class

(1) A class can be embedded in another class, but cannot be embedded in an interface.

(2) In static or other methods, it is not possible to create an inner class object directly, which must be obtained by means of the method.

There are two kinds of means:

Class A {

Class B {}

B Getb () {

b b = new B ();

return b;

}

}

static void M () {

A = new A ();

a.b ab = A.getb ();  or a.b ab = A.new B ();

}

(3) One class inherits the inner class of another class, because the superclass is an inner class, and the construction method of the inner class cannot be called automatically, so it is necessary to explicitly call the superclass's construction method in the subclass's constructor. Next Example:

Class C extends A.b {

C () {

New A (). super ();  This sentence implements a call to the inner class construction method.

}

}

The construction method can also be written like this:

C (a A) {

A.super ();

}// Use this construction method to create an object that is written as c c = new C (a) and a is an object of a.

One, exception class

In addition to the RuntimeException class in JAVA , other exceptions must be caught or thrown.

Java Basic knowledge points, many and miscellaneous, those who want to learn The new Java to have a plan, have to prepare the system of learning, can not use a jumping way to learn java, towering high-rise ground, The foundation is not strong, even if you finally become a java Daniel. The building of knowledge you build, is also a castle in the sky, means that the day will collapse. Therefore, step by step is the best choice .


Ps:java AC Group: 457036818


This article is from the Java Learning Video tutorial blog, so be sure to keep this source http://10239772.blog.51cto.com/10229772/1653658

"Java Basics Summary"-for beginners who learn Java for 0 basics

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.