Beijing Institute of Electronic Technology (BESTI)
Real Inspection report
Course: Java Programming Class: 1351 name: Li Yu yu Number: 20135129
Score: Instructor: Lou Jia Peng Experimental Date: 2015.4.15
Experiment level: Preview degree: Experiment time:
Instrument Group: Compulsory/elective: experimental serial number:
Lab name: Familiarity with the Java development environment
Experimental purposes and requirements: experimental content 1. Compile and run a simple Java program using JDK;
2. Edit, compile, run, and debug Java programs using Eclipse. Experimental requirements 1. Students who do not have a Linux base are advised to start with the Linux Basic Primer (new version), Vim Editor course; 2. Complete the experiment, write the experiment Report, the experiment Report template see QQ Group, pay attention to the experiment report focus is the running result, encountered problems (tool find, installation, use, program editing , commissioning, operation, etc.), solutions (empty methods such as "Check the network", "Ask classmates", "reading books" and so on all get 0 points) and analysis (from which can get what revelation, what harvest, lessons, etc.); 3. Test report of your PSP
Experimental instrument:
Experiment contents, steps and experiences (attached paper):
"Experimental Steps"
(i) under the command line Java Program Development
- First double-click the Xface terminal icon on the desktop, as shown in:
- Open the terminal (like cmd under Windows) and then run the shell program automatically, as shown in:
- Enter the CD code command into the code (note C to capitalize) directory, as shown in:
- Enter mkdir 20135100 command to set up the experimental directory, note that the directory name must be its own school number (study number to be reflected in the experimental report), you can use the LS command or the dir command to view the established directory situation. As shown in the following:
- Enter the CD 20135100 command into the experiment directory, enter a similar mkdir EXP1 to create the first experiment directory, and then enter the CD EXP1 into the experiment directory, you can enter the PWD command to view the current working path, as shown in:
- Enter Gedit Hello.java ( note Save the code in the exp1 directory ) or Vim Hello.java (it is recommended that you take some time to learn vim) edit Hello.java, and enter the following code:
Notice the first line of the code, which affects how we compile the code using javac .
Note in the second line of code, when we use the class in the Java class Library to import the related classes with import (you can temporarily understand the features of the Include in C), the import path can view the JDK Help documentation, for example, we used the scanner class
"Experimental Results"
(ii) Eclipse under Java program development, commissioning
- Enter the eclipse command on the command line and enter or click the Eclipse EE icon on the desktop to open eclipse
- In Eclipse, click File->new-> Java Project to create new Java projects, as shown in:
- Enter the project name Hellojdb (you can do it yourself) and click the Finish button to complete the new project
- In Eclipse, click File->new->class to create a new Java class
- According to the Java Code specification, enter the package name LJP (lowercase, can be customized), the class name Hellojdb (the first letter of the word), and tick the Automatically generate main function option, and then click the Finish button
- Enter the following code:
```
1 package LJP;
2 public class Hellojdb {
3 public static void main (string[] args) {
4 int i = 5;
5 int j = 6;
6 int sum = Add (i, j);
7 System.out.println (sum);
8
9 sum = 0;
Ten for (i=0; i<; i++)
sum + = i;
12
SYSTEM.OUT.PRINTLN (sum);
14}
15
public static int Add (int augend, int addend) {
sum int = augend + addend;
return sum;
19}
20}
- Click the Run button (or use the CTRL+F11 shortcut key) to see the results of the run in the console
- Here we practice the debugger, first we open the Debug view by clicking Window->open perspective->debug
- The debugger first sets breakpoints and runs in one step . Setting a breakpoint is simple, and then clicking the Debug button (or using the F11 shortcut) to start debugging the Java program, we can see that the program stays on line 4th note that at this point the 4th line of code is not executed, we can put the mouse on the variable name to see the value of the variable, The value of I is not 5, and we run the program to line 5th with one-step operation: Step Into( quick F5) and stepover(Fast F5 ), there is no difference between the two single-step run functions, when executing a function call statement, the step into will jump into the function implementation, step over will directly execute the function, in practice we prefer to use Step over, only function execution error, Explain the program problem in the called function, and then come back through the step into enter the function to debug. We click the Step over icon (or F6) and the program stops at line 5th, when I see the value of the variable i, I see I equals 5.
10.1 Step execution efficiency is slow, if we feel that the 6th line to the 10th line of code is no problem, want to let the program run directly to line 11th, what to do? First we set a breakpoint on line 11th and then click the Resume icon (shortcut F8) and the program runs to line 11th
11. One-Step execution efficiency is slow also leads to another problem, such as a cycle in the middle of a problem? You can then resolve the issue through conditional breakpoints. When debugging the loop code, there is a value that we pay particular attention to when we look at the value of the variable in the Variable tag , for example, we pay more attention to sum at this time, and each step can see the sum change, set the conditional breakpoint, We right-click on the left of line 11th and select Breakpoint Properties ...
"Experimental Results"
(iii) exercise (via command line and Eclipse two ways to achieve, the number of their own after the two and the total number of questions to take the results of the remainder plus 1 is the number of the problem you want to complete, Eclipse the next exercise to debug the program)
5. realize the function of all prime numbers between the 1-n integers and test them.
"Experimental Code"
import Java.util.Scanner;
Public class Test_5
{
Public Static void Main (string[] args)
{
Scanner sole = new Scanner (System. in);
int n1=0;
int n2 = 0;
System. out. println ("Please enter a 1th integer.");
N1 = Sole.nextint ();
System. out. println ("Please enter a 2nd integer.");
N2 = Sole.nextint ();
if (N1>N2)
{
N1=N1^N2;
N2=N1^N2;
N1=N1^N2;
}
int sum = 0;
for (int i = n1; i<=n2; i++)
{
if (f(i)!=0)
{
System. out. println (i);
sum = sum+1;
}
}
System. out. println ("sum=" +sum);
}
Public Final Static int f (int N)
{
if (n<1)
{
return 0;
}
int temp = (int) Math. sqrt (n);
int i=2;
for (; i<=temp;i++)
{
if (n%i==0)
{
break;
}
}
if (i-1==temp)
{
return N;
}
return 0;
}
}
"Experimental Results"
Psp
steps |
time-consuming |
percent |
Demand analysis |
|
10% |
Design |
|
40% |
Code implementation |
|
40% |
Test |
|
10% |
Analysis Summary |
|
|
"Problems and analyses encountered"
Code completion the first run-time compilation error, and then through the error prompt and the code repeatedly checked, found that the file name is different from the class name, the other is a spelling error, corrected after the code can function.
Java Programming Experiment one report