20135208 First Java Lab report

Source: Internet
Author: User

Lesson:Java programming class: 1352

Name: He Bong No.:20135208

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 dir command to view established directory conditions

4. Enter the CD 20135208 command into the experiment directory, enter a similar mkdir exp1 Create the first experiment directory, and then enter CD EXP1 into the experiment directory, you can enter the 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 also: The code has package When compiling code, be sure to add the   Note the second line of code, we use the java                       &N Bsp                   

(ii) development and commissioning of Java programs underEclipse

1. enter eclipse in the terminal window and enter the Eclipse interface;

2. Open "File--new--java project" and fill in the dialog box that appears in project name HELLOJDK , click "Finish" ;

3. Open "File--new--class"in turn, in the popup dialog box, enter thepackage name in thepackag column:wwy, in name column fill in the class name hellojdk, note the check in.

3. Enter the code according to the title:

Package Wwy;

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.

20135208 First Java Lab report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.