Cat in the room: the non-parametric method of class and Javadoc annotation

Source: Internet
Author: User
Tags class definition variable scope

I. Method of non-parameter of class
1. Overview:
(1) A class is abstracted from a set of entities with the same attributes and common behavior.
(2) The actions performed by the object are implemented by writing the method of the class.
(3) Each method of the class implements a function
2. Methods for defining classes
How to write:
(1) Define method name and return value type
(2) write the body part of the method in {}
Attention:
(1) The method body is placed in a pair of curly braces (the method body is a piece of program code, to do certain work)
(2) method names are primarily used when calling this method (camel-named notation is commonly used in Java)
(3) A result may be returned after the method is executed, and the type of the result is called the return value type (return value using the return statement)
Grammar:

return expression;


Note:
(1) Return statement is a jump statement
(2) If the method does not return a value, the return value type is void
(3) When writing a program, be sure to note that the type of the return value in the method declaration and the type of the true return value in the method body match (if not, the compiler will error)
The function of the return jump statement:
(1) Method of jumping out
(2) Give the result
Note: The method that defines a class must include the following three parts:
(1) Name of the method
(2) Type of method return value
(3) The body of the method
3. Method invocation
Grammar:

The name of the object. Method Name ();


    Note:
     (1) Classes in Java are the basic unit of a program
     (2) Each object needs to complete a specific application function
     (3) When an object is required to perform a specific action, it is implemented by invoking the method of the object
     (4) In a class, you can also call the
   method call form between different member methods of a class:
    (1) methods in the same class, calling the method directly using the method name
     (2) for different classes of methods, first create the object, using "Object name. Method Name ()" To call
 4. Variable scope
   member variable and local variable
    java in a class to organize programs, classes can define variables and methods, in the method of the class, you can also define variables
   define variables:
    (1) member variables:
      can use this class to define member variables directly, and if the methods of other classes want to access it, you must first create an object of that class before you can pass the operator "." To refer to the
    (2) local variable:
     Its scope is only within the method that defines the variable, so
 5 can be used only in this method. The difference between a member variable and a local variable:

 Public class Aini {    String house;     int Cats;         // member variable, Java automatically assigns the initial value     Public void Show () {        int a = 0;         NULL ;                 // local variables, to declare and assign values themselves     }}


   (1) Different scopes: the scope of the
    local variable is limited to the method that defines it, not accessible outside of the method
    The scope of the member variable is visible throughout the class, all member methods can be used, and if access permission is allowed, you can also use member variables
   (2) Unlike the initial value of the class:
    for member variables, If it is not assigned an initial value in the class definition, Java gives it a default value of 0, the value of the reference type is NULL
     (the initial value of the assignment, see the previous article I sent in detail "classes and objects > Everything objects ")
    but Java does not assign an initial value to a local variable, so the local variable must be defined and then used
   Note: Local variables with the same name are not allowed in the same method:
    in different methods, you can have local variables with the same name
    Local variables can have the same name as member variables, and local variables have a higher priority
 6 when they are used. Object-oriented Programming:
   Background:
    Object-oriented programming (oriented programming, OOP) is a computer programming architecture It is a kind of software programming thought that was popular in the the 1990s. One of the basic principles of OOP is that a computer is composed of a single unit or object that can act as a subroutine, and that this framework is used primarily for reusability, flexibility, and extensibility.
   Syntax:
   

Main () {  // show Total score call method; / / show average call method;}


Benefits:
(1) A method of a class can implement a specific function, and other classes do not need to be implemented as long as it is
(2) If you know the class that implements this function and its method name, you can call it directly without repeating the encoding

Case:

  

 Public classobjects_009 {String pp;    String CPU;    String ZB;    String xsq;    String YP;        String NC; //declaring member variables     PublicString Show () {System.out.println ("Brand:" + pp + "\NCPU:" + CPU + "\ n motherboard:" +ZB+ "\ n Monitor:" + xsq + "\ n HDD:" + YP + "\ n Memory:" +NC); //Create a method, write out the output format        return"The program is over!" "; //String type method, which writes out the return value for the string type (last output of the program)    }     Public Static voidMain (string[] args) {//invoking the output in the Main method//Create a scannerScanner BDQN =NewScanner (system.in); //invoking a class with the New keywordobjects_009 A =Newobjects_009 (); //Assigning a value to a member variableSystem.out.print ("Please enter Brand:"); A.PP=Bdqn.next (); System.out.print ("Please enter CPU:"); A.cpu=Bdqn.next (); System.out.print ("Please enter the motherboard:"); A.ZB=Bdqn.next (); System.out.print ("Please enter the display:"); A.XSQ=Bdqn.next (); System.out.print ("Please enter the hard drive:"); A.yp=Bdqn.next (); System.out.print ("Please enter Memory:"); A.NC=Bdqn.next (); //receives the return value of the Show method and outputs the contents of the method (the value that the last item of the output is the return value)String A1 =a.show ();    SYSTEM.OUT.PRINTLN (A1); }}


7.JavaDoc notes:

// This is a comment

/* * This is a demo program */



/**  *@ This is the Javadoc comment. */

Syntax rules:
(1) Javadoc note begins with "/**" and ends with "*/"
(2) Each note contains a description of the text and several Javadoc tags
(3) Javadoc tags are usually prefixed with "@"
Common Javadoc Tags:

Label Meaning
@author Author name
@parameter Parameters and their significance
@return return value
@version Version ID
@since The first JDK version to use this method/class/interface
@throws Exception classes and throwing conditions


Generating Javadoc Documents
(1) using the command line method to generate
(2) using the MyEclipse tool to generate
"File"--"export" Pop-up dialog box, select "Java" menu "JavaDoc" option, submit to


The way you use the command line is basically the same principle

Cat in the room: the non-parametric method of class and Javadoc annotation

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.