Experiment with familiarity with a Java development environment
Experimental content
1. Compiling and running a simple Java program using the 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 basics (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, encounter problem (tool find, install, use, program edit, Debug, run, etc.), solution (empty method such as "Check Network", "Ask classmate", "read book" 0 points) as well as analysis (what can be learned from it, what gains, lessons, etc.).
3. Report the time of your PSP (Personal software Process)
Steps |
Take |
Percentage |
Demand analysis |
|
|
Design |
|
|
Code implementation |
|
|
Test |
|
|
Analysis Summary |
|
|
4. Copying is strictly prohibited.
Experimental knowledge points
1. Installation location and difference of JVM, JRE, JDK;
2. command line run JAVAC,JAVA;JAVAC-CP; JAVA-CP;
3. Path,classpath,sourcepath setting method and application;
4. Package management: package;import;javac-d;
5. Eclipse (Netbeans) manages Java projects, debugging: breakpoints, stepping, etc.;
6. Java basic syntax: type and type conversion; variables; operators; Process control, etc.;
7. Use of JDK help documentation;
Experimental steps under Java Program development under the command line Java program development, debugging 1, input on the command line
eclipse
command and enter or click on the desktop
Eclipse EEicon to open Eclipse2, click in Eclipse
File->New-> Java Project
New Java Project 3, enter the project name
HelloJDB
(You can name it yourself) and click
Finish
button to complete new Project 4, click in Eclipse
File->New->Class
New Java Class 5, enter the package name according to the Java Code specification
czw
, class name
HelloJDB
(Capitalize the first letter of the word) and tick the Automatically generate main function option, and then click
Finish
Button 6, 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 Sy STEM.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) {n int sum = augend + addend;18 return sum; 19} 20}
7. Click the Run button (or use the Ctrl+F11
shortcut key) to see the results of the run in the console. As shown in: 8. Below we practice the debugger, first we open the Window->Open Perspective->Debug
debug view by clicking, as shown in:
9. The debugger first sets breakpoints and one- step operation . Setting breakpoints is simple, as shown in:
Then click the Debug button (or use the F11
shortcut key) to start debugging the Java program, and we can see that the program stays on line 4th, as shown in:
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, we run the program through a single run To line 5th, single-step operation there are two: Step Into( shortcut F5) and stepover(shortcut F5), these two single-step operation function in the run statement, there is no difference in the execution of the function call statement, Step Into
will jump into the function implementation, Step Over
will directly execute the function, in practice we prefer to use Step Over
, only the function execution error, stating that the program problem in the called function, then come back by Step Into
entering the function to debug. We click Step Over
on the icon (or F6
), the program stops at line 5th, then look at the value of the variable I, you will see I equals 5.
10. 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 the breakpoint on line 11th and then click the Resume
icon (shortcut F8
), and the program runs to line 11th, as shown in:
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 are more concerned at this time, sum
each step can see sum
the change of the situation,
To set a conditional breakpoint, we right-click on the left side of line 11th and select Breakpoint Properties...
as shown: we set the condition "i==50" as shown in: Click F8, we can see that I is 50. As shown in the following:
Mastering the basic skills of these debugs can solve most of the problems you normally encounter, and other debugging methods can be found in resources.
Iii. Exercises (through
command LineAnd
EclipseImplemented in two ways,
the results of the two and the total number of questions after their own study number plus 1Is the number you want to complete, practice debugging under Eclipse 1. Implement the Caesar password and test it. Code:
Import java.io.*;
Import Java.util.Scanner;
public class Kaiser {
Public staticvoid Main (string[] args) {
System.out.println (" Please enter key:");
scanners = new Scanner (system.in);
int a =s.nextint ();
C (a); }
publicstatic void C (int n) {
try{
Charb[];
BufferedReader Br2 = new BufferedReader (Newinputstreamreader (system.in));
System.out.println (" Please enter a clear text:");
Stringstr2=br2.readline ();
B=str2.tochararray ();
System.out.println (" ciphertext:");
int k=n;
For (Inti=0;i<str2.length (); i++) {
Char ch= (char) ((b[i]-' a ' +k)%26+ ' a ');
System.out.print (CH);
}
System.out.println ("\ n key k=" +k);
}
catch (IOException e) {
System.out.println (E.getmessage ());
}
}
}
Iv. problems encountered and solutions
Not very skilled at setting breakpoints, not familiar with some words in English. There is programming Caesar password when not very skilled, ask the other students.
Five, the experimental harvest
Because the school speed is too slag ... Then is directly in the window environment to make the experiment, this experiment let me to the Java code debugging has a further understanding, Eclipse on the error detection and debugging is clear and easy to understand, hope that the future of the experiment can be completed smoothly, in the mistakes of continuous learning, gain more knowledge
Experiment with familiarity with a Java development environment