14_java oo _ 6th day (Eclipse Advanced, class, and interface as parameter return value) __java

Source: Internet
Author: User
Tags documentation modifier modifiers
day 14th Object-oriented

today's content introduction

U Eclipse common shortcut key operations

U Eclipse document Annotation Export help document

Jar package export and use jar package for the U Eclipse Project

U mixed use details with different modifiers

U discriminate when to define variables as member variables

U class, abstract class, interface as method parameter

U class, abstract class, interface as method return value 1th Chapter Eclipse Application 1.1 Common shortcut Operations

L Ctrl+t: View the inheritance tree for the selected class

For example, in the following code, the teacher class name is selected, and then the ctrl+t is displayed, showing the inheritance relationship of the teacher class

Employees

Abstract class employee{

Public Abstract void work ();

}

Lecturer

class Teacher extends Employee {

Public void work () {

System. out. println ("explaining Java");

}

}

L View the source code for the selected class

CTRL + Slide the mouse click the class name, or select the class name, press F3 to view the source code for the selected class.

L View the source code for the selected method

CTRL + Slide The mouse click the method name, or select the method name, press F3 to view the source code of the selected method.

L The JRE System Library in Eclipse is the default class library in the eclipse-dependent JRE. In this location you can find the usual string, random, math, and so on.

1.2 Documentation Comments Export help document

When eclipse is used, you can work with documentation annotations to export a description of the class to allow others to read and use it.

Annotate a class or method by using a document annotation to simply annotate the basic information with @. such as @author author, @version code version, @param method parameter, @return method return value, and so on.

package Cn.itcast;

/**

* My Tool class

* @author Li

* @version version 1.0

*/

Public class Tool {

/**

* Returns the cumulative sum of two integers

* @param NUM1 First Number

* @param num2 Second number

* @return returns additive and

*/

Public Static int getsum ( int num1, int num2) {

return num1 + num2;

}

}

You can use Eclipse to export Javadoc documentation, as shown in the following steps:

jar Package Import and export for 1.3 project

A jar package is a compressed file that can contain many. class files. We can add a jar package to the project's dependencies so that the project can use all the classes under that jar, or you can package all the classes in the project to a specified jar package for use by other projects.

L Export the jar package: that is, to package all the classes in the project into the specified jar package, as shown in the following steps:

L Import jar packages: that is, add the specified jar package to the project and provide it to the project for use.

The process of importing a jar package is to add the jar package to the project's. classpath file to identify the project, and you can use all the. class file classes in the jar package. Here are the steps to join:

1: Create Lib folder under the project root folder for the same management of all jar files

2: Copy the jar file to the Lib folder

3: Right click on the jar file, click Build Path, select Add to build path, view the. classpath file under the project root folder, and discover that the newly added jar package path is configured in the file. Description You can use all the classes in the jar package.

L Note:

After the jar package is joined, you must add to build path in order to use

After the jar package is joined, the class that is added must also guide the package, which is considered under the same package if its package name is the same as the existing class package name. (not common) 2nd Chapter Object-oriented 2.1 different modifiers using details

Modifiers that are commonly used to decorate classes, methods, and variables are as follows:

L Public permission modifiers, common access

L protected permission modifiers, protected Access

L default to write nothing is also a privilege modifier, default access

L private privilege modifier, privacy access

L Static modifier

L Final End modifier

L Abstract modifier

When we write a program, the permission modifiers are generally placed before all modifiers, and different permission modifiers cannot be used at the same time;

At the same time, abstract and private can not be used at the same time;

At the same time, abstract and static can not be used at the same time;

At the same time, abstract and final cannot be used at the same time.

Modifiers that the modifier class can use:

Cosmetic classes can only use public, default, final, abstract keywords

The most used is the Public keyword

Public class Demo {}//the most common way

class demo2{}

Public Final class demo3{}

Public Abstract class demo4{}

L modifies the modifiers that a member variable can use:

Public: Common

Protected: Protected

: The default

Private: Personal

Final: The Ultimate

Static: Statically

The most used is private

Public int count = 100;

protected int count2 = 100;

int count3 = 100;

Private int count4 = 100; The most common way

Public Final int count5 = 100;

Public Static int count6 = 100;

Modifiers that can be used by the modified construction method :

Public: Common

Protected: Protected

: The default

Private: Personal

The most used is public

Public Demo () {}//the most common way

protected Demo () {}

Demo () {}

Private Demo () {}

Modifiers that can be used by the cosmetic member method :

Public: Common

Protected: Protected

: The default

Private: Personal

Final: The Ultimate

Static: Statically

Abstract: Abstraction of

The most used is public

Public void method1 () {}

protected void method2 () {}

void method3 () {}

Private void method4 () {}

Public Final void method5 () {}

Public Static void Method6 () {}

Public Abstract void method7 (); Chapter 3rd Customization, use of data types 3.1 Analysis of the design definition of member variables and method parameters

L Define rectangular classes, including methods for calculating circumference and area

L defines a mathematical tool class that contains twice times the number of two digits and a method of finding a two-digit product

Thinking: These two classes of calculation methods need two number to participate in the calculation, I would like to ask two number of definitions in the member position or formal parameter position better, why.

If the variable is part of the class, it is defined as a member variable.

If the variable should not be part of a class, but only the number of functions that need to participate in the calculation, it is defined as a parameter variable.

L Mathematics Tool Class

Public class Mathtool {

Ask for twice times the number of two

Public double sum2times (int number,int number2) {

return (Number+number2) *2;

}

Find the product of two numbers

Public Double area (int number,int number2) {

return number*number2;

}

}

L Rectangular Class

Public class CFX {

Because it is long and wide, it is part of the thing in the real thing, so define the member variable

Private int Chang;

Private int Kuan;

Public CFX (int chang, int Kuan) {

this. Chang = Chang;

this. Kuan = Kuan;

}

Length and width of circumference

Public double Zhouchang () {

return (Chang+kuan) *2;

}

The area of long and wide

Public double Mianji () {

return chang*

Related Article

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.