Beginner Java is a few important concepts, the sample program imported Acm.jar package (has been uploaded to the Download Center, if necessary, you can also enter the http://jtf.acm.org/to download), do not want to guide the package can be run using the main function.
Basic concepts:
class: class is the encapsulation of some program behavior
Build class:
public class name (extends superclass)--optional {...};
Name=classname.java
Parameters:
The parameter passed in the method is a copy
An object is passed as a parameter, which is the object itself (reference)
Parametric occlusion: public MyCounter (int counter) {
Counter = counter;//of parametric occlusion (both sides are counter)
}
Workaround:
1, this
Public MyCounter (int counter) {
Counter = counter;//in the presence of a parametric masking phenomenon
This.counter = counter;//The first counter (instance variable) that points to the calling object, and the second is the argument
}
2. Different names-suggested use
Public MyCounter (int startvalue) {
counter = Startvalue;
}
method: The method is like a bread machine, composed of many parts, people do not see the internal structure of the bread machine, but can use it to make bread (information hiding)
How to create a method in Java:
Visibility type name (parameters) {
..... body ...
}
Visibility (visibility): private or public
The type of the implicit return value of the method: void return value, return expression;
Method Name (name)
Parameters (parameter):
Method body of the constituent method (body)
Variable:
1. Instance variable (instance Variable--ivar)--declares in class that the entire object is visible--variables that need to be saved during a method call
Private double A;
2. Local variable--declare in method-scope only in method
Double A;
3, class variables (class variable)--variables shared by all objects of the class-static variables
Private final static Double A = 50;
Comments:
//
Javadoc--java Document
-start with:/**
-end with: */
Special "Tags" (@param, @result, etc.) --Convert annotations to HTML
[email protected] Parameter name explanation
Example: Finding factorial
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/9F/wKioL1Xpeb3BsesHAAKBpPVnc7w805.jpg "title=" 01.png "alt=" Wkiol1xpeb3bseshaakbppvnc7w805.jpg "/>
This article from "Not Daze" blog, please make sure to keep this source http://tobeys.blog.51cto.com/10620284/1691377
Review of the basic concept of "Java" (How to create a class)