Lesson:Java Programming class: 1353
Name: Wusi No.:20135332
Score: Instructor: Lou Jia Peng experimental Date:2015.04.15
Experiment level: Preview degree: experiment time:13:00~15:00
Instrument Group: compulsory / elective: Elective Experiment number:1
Lab Name: familiarity with the Java development environment
Experimental purposes and requirements:
Edit, compile, run, and debug simple Java programs under the command line and Eclipse
Experimental instrument:
Name |
Model |
Number |
Pc |
|
1 |
Virtual machines |
Laboratory Building |
1 |
First, the contents of the experiment:
1, the command line under the Java program development
2. Java program development and debugging under Eclipse
Second, the experimental process:
(i) Java Program Development under command line
1. Open the terminal
2. Enter the CD Code command to enter the code(note C to capitalize) directory
3. Enter the mkdir 20135208 command to create the experimental directory, note that the directory name is its own number, you can use the LS command or the dir command to view the established directory situation
4. Enter the CD 20135208 command into the experimental directory, and then enter a similar mkdir exp1 to create the first experimental directory, and then enter the CD EXP1 into the experimental directory, you can enter PWD command to view the current working path
5. Enter gedit hello.java(note Save the code in the EXP1 directory)
6. Enter javac-d. Hello.java command to compile the code, enter the Java Linke.hello command to run the program.
Note: The code has packagejavac When compiling the code, you must add -d" parameter, Be sure to add Note the second line of code, we use java &N Bsp /span>
(ii) Development and commissioning of Java programs under Eclipse
1. enter eclipse in the Terminal windowand enter the Eclipse interface;
2. Open "File--new--java project", and in the popup dialog box, in project name , fill in hellojdk, click " Finish ";
3. Open "File--new--class" in turn,in the popup dialog box,enter the package name in the packag column:wwy, fill in the Name field in the class name HELLOJDK , note the check in.
3. Enter the code according to the title:
Package wxy;
public class Hellojdk {public static void main (string[] args) {int i=5; int j=6; int sum=add (I,J); SYSTEM.OUT.PRINTLN (sum); sum=0; for (i=0;i<100;i++) sum+=i; SYSTEM.OUT.PRINTLN (sum); } public static int add (int augend, int addend) {
int sum = augend + addend;
return sum;
} }
4. Click the Run button (or use the CTRL+F11 shortcut key) to see the results of the run in the console.
5. Practice the debugger, first we open the Debug view by clicking Window->open perspective->debug.
6. The debugger first sets breakpoints and one- step operation .
7. 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'll set the breakpoint on line 11th and then click the Resume icon (shortcut F8).
8. 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.
To set a conditional breakpoint, we right-click on the left side of line 11th and select Breakpoint Properties ...
The final result is as follows:
(c) Realization of the Fibonacci sequence function, and test.
public class fibonacci{public static void Main (String args[]) {int sum = Fibonacci (8); SYSTEM.OUT.PRINTLN (sum); } static int Fibonacci (int n) {if (n<=1) return 1; Return Fibonacci (n-1) +fibonacci (n-2); } }
Iv. Harvest of Experiments
Through this experiment, I had a rough idea of how to write and run Java programs using Eclipse. Before the experiment through the teacher in the classroom explanation, I basically understand the usefulness of the break point. But in the actual operation, I am not very familiar with how to set breakpoints. Overall this experiment I have a lot of harvest, understand the use of eclipse, the better to write Java code in the future is still a great help. In the experiment three, I was somewhat unfamiliar with the procedure for the Fibonacci sequence, so it was a little hard to write. However, after consulting the relevant information and exchange with the students, I still have some more understanding of it.
20135332 First Java Lab report