# 20165315 Experiment a Java development environment familiarity one, experimental content and steps (i) compiling and running a simple Java program using the JDK
- Run Java under macOS command line
- Open Terminal
- Enter
mkdir 20165315exp1 to create a name for your own study number
- Enter
cd 20165315exp1 into directory
- Enter
mkdir src bin build src and bin Catalog
- Enter
vi src/Hello.java Create and open file in Vim editor Hello.java
- Writing programs in the Vim editor
- Enter the
javac -d bin src/Hello.java compiled file to the bin directory
- Enter
java -cp bin ljp.Hello Run file
- Experiment
# # # (ii) Edit, compile, run, and debug Java programs using idea
1. New HelloJDB project and HelloJDB.java file
2. Writing code in a file
3. Click on the left side of the line where you want to set a breakpoint, a red dot appears, use the shortcut key shift + control + to R enter single-step debugging
4. Use the shortcut key fn + F8 to step over operate, outputsum
5. If you want to determine whether there is a problem in the loop, such as we want to enter the for loop, set a breakpoint in line tenth, right-click the dialog box, fill in the inside of the value you want to test, such as i==50 , and then use the shortcut key + to get the results of the fn F9 operation
Summarize:
Frequently used debugging shortcut icon function:
Step over (F8): The program executes a line down (if the current line has a method call, this method will be executed and returned to the next line)
Step into (F7): The program executes one line down. If the row has a custom method, run into a custom method (a method that does not enter the official class library)
Force Step into: Enter any method
- Step out (SHIFT+F8): If you enter a method during debugging and feel that the method is not a problem, you can use StepOut to jump out of the method and return to the next line of statements where the method is being used. It is important to note that the method has been executed
Run to Cursor: Runs the program to the cursor
(iii) Practice (implemented by command line and idea two, and debug with idea) to achieve two numbers of greatest common divisor and least common multiple functions, input from the command line, and test (normal, abnormal, boundary condition)
The topic requires implementation of the command line input and calculation of least common multiple and greatest common divisor functions, I first think of the Integer.parseInt() implementation of the command line input, followed by the need to write two methods to achieve the function of computing greatest common divisor and least common multiple, so I first wrote two methods of code, after the completion of writing, Then complete its connection to the main function.
- Implemented through the command line
(1) Normal condition
(2) Boundary conditions
(3) Abnormal situation
(1) Normal condition
(2) Boundary conditions
(3) Abnormal situation
1. Set breakpoints in line fifth and step through
2. If you want to enter the greatest common divisor method, you can use the shortcut key fn + F7 execute Step Into command
3. If you want to go directly to the "least common multiple method", you can set a breakpoint on line 19th before executing the Resume command
Ii. problems encountered in the course of the experiment
- I mistakenly programmed the greatest common divisor method and the least common multiple method into the main method, resulting in a compilation problem when I wrote the code to "greatest common divisor and least common multiple of two numbers, and number of inputs from the command line".
Third, the experiment experience and summary
This experiment is relatively simple and basic, but still embodies the basic steps to write code: Before writing code in the mind to build a good program framework, and then step by step with the code to achieve their own ideas, and finally the force can also optimize the program. At ordinary times, the process of copying the code is not enough, or the need to write their own program, the textbook theory into practice.
| Steps |
Time Consuming |
percentage |
| Demand analysis |
3min |
7% |
| Design |
5min |
12% |
| Code implementation |
20min |
50% |
| Test |
3min |
7% |
| Analysis Summary |
10min |
24% |
20165315 experiment a familiarity with the Java development environment