Java Learning Notes (i)

Source: Internet
Author: User

1.1.an algorithm for number inversion

A take the reverse,~a=-(a+1). As

~5=-6,~(-8)=7

1.2. access control characters for classes in Java

(the modifier for a class has public,default,abstract,final, The modifiers for the method are public,default,protected, Private)

Public: This class can be accessed by an external package

Default(Default): This class can only be accessed by this package

Protected: This class can only be accessed by the quilt class

Private: This class cannot be accessed by any class

1.3.the difference between static and non-static methods

static methods do not need to create an instance of the class to be used, and a non-static method must create an instance of the class to be used, that is , the new object, and the method is called through the object

1.4.Static Variables

Static variables are static storage and must be defined outside the function, and after being called by a dynamic function, the static variable is the value after the change. Does not return to the initialized value because the function call ends. Such as:

Package Hello;

public class hello{

static int a=1;

int fun (int n) {

A=a*n;

Returm A;

}

public static void Main (string[] args) {

Hello h=new hello ();

for (int i=1;i<4;i++)

System.out.println (H2.fun (i));

}

}

}

1.1.Interfaces and Classes

multiple inheritance properties are forbidden in the Java programming language, but can be used to help extend the method through an interface. A large number of solid and methods can be defined in the interface. But the method is only a declaration, there is no specific implementation, the use of the interface classes themselves have implemented these methods. The difference between an interface and a = class is that:

(1) There is no declaration of variables, but can be defined as solid;

Only the declaration of the method, there is no implementation of the method.

Java Learning Notes (i)

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.