Java Experiment 1 Experimental report (20135232 Wangyue)

Source: Internet
Author: User

Experiment with familiarity with a Java development environment

First, the contents of the experiment

1. Compiling and running a simple Java program using the JDK

2. Edit, compile, run, and debug Java programs using Eclipse

Second, the 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 , encountered the problem (tool find, install, use, program editing, debugging, running, etc.), solution (empty method such as " Check network "," Ask classmates "," reading "and so on all get 0 points) and analysis (from which can get what revelation, what harvest, lessons, etc.).

3. Report the time of your PSP (Personal software Process)

Steps

Take

Percentage

Demand analysis

40min 20%

Design

40min 20%

Code implementation

60min 30%

Test

30min 15%

Analysis Summary

30min 15%

4. Copying is strictly prohibited.

Third, the experimental steps

(i) Java program Development under command line

1. First double-click the Xface terminal icon on the desktop.

2. Open the terminal (similar to CMD in Windows) and then run the shell program automatically.

3. Enter the CD Code command to enter the code (note C to capitalize) directory.

4. Enter the mkdir 20135100 command to establish 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.

5. Enter the CD 20135100 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 the PWD command to view the current working path.

6. Enter Gedit Hello.java ( note Save the code in the EXP1 directory ) or vim Hello.java edit Hello.java.

7. Enter javac-d. Hello.java command to compile the code, enter the Java LJP. The Hello command runs the program.

(ii) Development and commissioning of Java programs under Eclipse

1. Enter Eclipse command on the command line and return or click the Eclipse EE icon on the desktop to open eclipse.

2. In eclipse, click File->new-> Java Project to create new Java projects.

3. Enter the project name Hellojdb (you can do it yourself) and click the Finish button to complete the new project.

4. In eclipse, click File->new->class to create a new Java class.

5. Enter the package name LJP (lowercase, can be customized) according to the Java code specification, the class name Hellojdb (capitalize the first letter of the word), and tick the Automatically generate main function option, and then click the Finish button.

6. Enter the following code: Package LJP;

public class Hellojdb

{

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<; i++)

sum + = i

SYSTEM.OUT.PRINTLN (sum);

}

public static int Add (int augend, int addend)

{

int sum = augend + addend;

return sum;

}

}

7. Click the Run button (or use the CTRL+F11 shortcut key) to see the results of the run in the console.

8. Practice the debugger, first we open the Debug view by clicking Window->open perspective->debug.

9. The debugger first sets breakpoints and one- step operation .

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'll set the breakpoint on line 11th and then click the Resume icon (shortcut F8).

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.

To set a conditional breakpoint, we right-click on the left side of line 11th and select Breakpoint Properties ...

(iii) exercises (implemented via command line and Eclipse Two, practice debugging under Eclipse)

Title: Implement the Fibonacci sequence function and test.

Iv. Exercises Code and:

Import Java.util.Scanner;

/*
Fibonacci

*/
public class Fibonacci {

public static void Main (string[] args) {
Scanner Scanner = new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Please input this Fibonacci n:");
int n = scanner.nextint ();

System.out.println (Fibonacci (6) + ":" + fibonaccinormal (6));

int sum = 0;
for (int i = 1; I <= n; i++) {
Sum + = Fibonacci (i);
}
SYSTEM.OUT.PRINTLN (sum);
}


public static int Fibonacci (int n) {
if (n <= 2) {
return 1;
}else{
Return Fibonacci (n-1) + Fibonacci (n-2);
}
}


public static int Fibonaccinormal (int n) {
if (n <= 2) {
return 1;
}
int n1 = 1, N2 = 1, sn = 0;
for (int i = 0; i < n-2; i + +) {
sn = n1 + n2;
N1 = n2;
N2 = SN;
}
return SN;
}
}

Experimental Content 1:

Experimental Content 2:

V. Problems encountered and Solutions

Problems encountered:

At first, I want to use recursive method to write code, realize the function of Fibonacci series, but because the program is not clear in the way of writing, so the compilation failed, after several modifications without fruit.

Workaround:

Later thought can use the recursive method to write code, instead of the recursive method of writing code, the last many times after the success of the modification.

Six, the experimental harvest

Through this experiment I learned how to use Eclipse to run Java programs and how to debug the program, but the process of debugging the program is generally understood but does not know how to operate, where to set breakpoints or some do not understand. In general, the experiment is still relatively successful, the use of C language Fibonacci knowledge points to write Java program code, relatively simple. Is some forgotten the definition of Fibonacci, after the access to the information learned. There are still some problems in writing code, such as the design of the program is more chaotic, there is not a clearer idea. Further corrections are needed in the future.

Java Experiment 1 Experimental report (20135232 Wangyue)

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.