I. Contents and steps of the experiment (i) compiling and running a simple Java program using the JDK
Set up a catalogue of "self-study number EXP1"
mkdir 20165202exp1
Go to Catalog
cd 20165202exp1
Set up Src,bin and other directories under "EXP1"
mkdir binmkdir src
Vim Edit Code
vi Hello.java
Javac,java's execution in the "self-study number EXP1" directory
javac -d bin src/Hello.java
Run the program
java Hello
Run
Code Cloud Link
(ii) Use idea to edit, compile, run, and debug Java programs
To set a breakpoint, simply click on the line number where you want to set the breakpoint to use it. Alt+Shift+F9Debugging Java programs with shortcut keys
- Single-step operation there are two:
Step Into (Fast F7) and Step Over (Fast F8) in the actual use of our priority Step Over , only method execution error, indicating that the program problem in the called method, then come back by Step Into entering the method to debug.
Temporary breakpoints: The simplest way is to move the cursor to the line where you want to add a breakpoint, use the menu "run"->"toggle temporary the lines breakpoint", or use the shortcut keyCtrl+Alt+Shift+F8
Conditional breakpoint: Right-click at the left breakpoint on line 9th, pop-up the breakpoint property box, we set the condition "i==50"
Method Breakpoint: Moves the cursor to any line in the method, using the menu "run"->"toggle method breakpoint
(iii) exercises (implemented via command line and idea two, and debugged using idea)
Implement Fibonacci sequence function and test (normal, abnormal, boundary condition)
1 import java.util.Scanner; 2 3 public class fibonacci { 4 5 public static void main(String[] args) { 6 7 Scanner scanner = new Scanner(System.in); 8 9 System.out.println("请输入一个整数:"); 10 11 int n = scanner.nextInt(); 12 13 System.out.println("fibonacci数列为:"); 14 if(n<=0) { 15 System.out.println("非法输入"); 16 } 17 else { 18 for (int j = 1; j <= n; j++) { 19 20 System.out.println(" a["+j+"] = "+fibonacci(j)); 21 22 } 23 } 24 scanner.close(); 25 26 } 27 28 private static int fibonacci(int i) { 29 30 if (i == 1 || i == 2){ 31 32 return 1; 33 34 }else{ 35 36 return fibonacci(i - 1) + fibonacci(i - 2); 37 38 } 39 40 } 41 42 }
(1) Normal condition
(2) Abnormal situation
(3) Boundary conditions
Code Cloud Link
(1) Normal condition
(2) Abnormal situation
(3) Boundary conditions
方法断点:在第4、23行设置断点
Ii. problems encountered in the course of the experiment
Start writing Exercise Code Fibonacci Implementation Error Understanding test instructions, output value is the corresponding number of f function
Then only the first n items (for example, 20) can be output, combined with the use of previously learned scanner
Scanner scanner = new Scanner(System.in); System.out.println("请输入一个整数:"); int n = scanner.nextInt();
The call resolved an issue where n could not be changed by the input
Third, the experiment experience and summary
Statistics PSP (Personal software Process) Time:
| step |
time-consuming |
Hundred Division |
| demand analysis |
2min | TD align= "Center" >2.5%
| design |
8min | TD align= "Center" >10%
| code implementation |
25min |
31.25% |
| test |
5min |
6.25% |
| Analysis summary |
40min |
50% |
Personal Summary
This experiment content is more basic, mainly examines the Java development environment familiar and some basic operation. Programming has a complete set of processes: analysis requirements, design, code implementation, testing, summary, this is our future programming a basic framework. Learning to master the relevant usage of idea in the course of the experiment is really more useful than the VIM command line, and the debugging process is displayed more clearly. Typing the textbook code on a weekly basis is just one of the most basic tasks, and in practical applications I find it necessary to combine more thinking and understanding to really "learn to apply" and not mechanically "knock on the code".
20165202 experiment a familiarity with the Java development environment