Java key words and functions

Source: Internet
Author: User
Tags modifier modifiers

Overview and role of the package keyword
A: Why should I have a bag
Classify byte code (. Class)
The package is actually a folder
Package Definition and Precautions
A: Define the format of the package
Package name;
Multi-stage ladle. Separate
B: Considerations for defining packages
The A:package statement must be the first executable code of the program
The B:package statement can have only one in a Java file
C: If there is no package, default means no packages name
Overview and use of the Import keyword
A: Case Demo
Why should I have an import
In fact, the class that has the package is visible to the caller without having to write the full class name.
B: Guide Package format
Import package name;
Attention:
This way the import is to the name of the class.
Although it can be written last *, but not recommended.
C:package,import,class there is no sequential relationship (interview question)
Common modifiers used by the class and its composition
A: modifier:
Permission modifiers: Private, default, Protected,public
Status modifier: static,final
Abstraction modifier: Abstract
B: Class:
Permission modifiers: default modifier, public
Status modifier: Final
Abstraction modifier: Abstract

The most used is: public

C: Member Variable:
Permission modifiers: Private, default, Protected,public
Status modifier: static,final

The most used is: private

D: Construction Method:
Permission modifiers: Private, default, Protected,public

The most used is: public

E: Member Method:
Permission modifiers: Private, default, Protected,public
Status modifier: static,final
Abstraction modifier: Abstract

The most used is: public

F: In addition to the combination of rules:
Member variable: public static final
Member Methods:
public static
public abstract
Public final

Internal class overview and accessibility features
A: Internal class overview
B: Internal class Access features
A: The inner class can access the members of the external class directly, including the private.
B: The external class must create an object to access the members of the inner class.
The external class name. Internal class Name Object name = External Class object. Inner class object;
Static member Inner class
Static
: A member's inner class is accessed statically after being modified by:
The external class name. Internal class Name Object name = External class name. Inner class object;

Problems with local internal classes accessing local variables
A: Case Demo
Local internal class access local variables must be final decorated
Local inner class in accessing the local variables in his method must be final decorated, why?
Because when this method is called, if the local variable is not final decorated, his life cycle and method life cycle is the same, when the method of the stack, the local variable will disappear, then if the local inner class object has not disappeared immediately want to use this local variable, there is no, If the final decoration will enter the constant pool when the class loads, even if the method is stacked, the constant pool constant is still there, you can continue to use

But jdk1.8 canceled this thing, so I think it's a bug.

Java key words and functions

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.