1. Template mode
(a) Needs: to solve the dictation of things have a fixed mode, but sometimes internal changes, you need to apply template mode to write this process
The process of resolving things can still be done, which is the benefit of template mode (similar to our CV template)
(ii) Steps:
A. First write a solution to a problem
B. Extract the code that will change, because there will be changes that need to be made by the caller some of the code here is used in the abstract retouching
C. Using the final decoration template method to prevent others from rewriting
(c) Example: The explanation is good.
/*template mode requirements: To solve the dictation of things have a fixed mode, but sometimes internal changes, you need to apply template mode to write this process steps: A. First write a solution to a problem B. Extract the code that will change, because it will need to be called by some of the code that is used in the abstract modifier C. Use the final decoration template method to prevent others from rewriting*/Abstract classmyruntime{ PublicFianlvoidGetRuntime () {LongStarttime=System.currenttimemillis (); /*Here the code will change for (int i=0;i<100;i++) {System.out.println (i); } */code (); System.out.print ("\ n"); System.out.print (System.currenttimemillis ()-startTime); } //extracting code that will change Public Abstract voidcode (); }classMobantestextendsmyruntime{ Public Static voidMain (string[] args) {mobantest MBT=Newmobantest (); Mbt.getruntime (); } //here is the code to rewrite the changes Public voidcode () {inti = 0; while(i<100) {System.out.println ("I=" +i); I++; } }}View Code
2.eclipse Steps to use
(i) Select the working directory. All of the code written later on Eclipse is on the working directory.
(b) Create a project on the Project Exploer window, and we will write the code in the future as an engineering unit.
Steps to create a new project:
Project Exploer window Right-click----------> New---------> Java Project
(iii) Right-click on the SRC directory of the project and create a class from new class.
Catalog description of the project:
Settings:elcipse automatically generated configuration files. Don't touch it.
Bin: For storing all the class files.
SRC: Used to store all Java source files.
(d) Run the Java file.
Mode one: Java source right-click-------->run as-----------> Java application
Way two: Green Arrow--------->run as-----------> Java application
Mode three: Shortcut key operation: Ctrl + F11
(v) Import Project:
Get started with Java 05