Java Lab Report-20135111 Li Guangji

Source: Internet
Author: User

Experiment with familiarity with a Java development environment

20135111 Li Guangji

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)

Implement the arithmetic and test.

Experiment Code:

Import Java.util.Scanner;

public class Math {

public static void Main (string[] args)

{Scanner reader = new Scanner (system.in);

SYSTEM.OUT.PRINTLN ("Please input two data to be calculated");

int x = Reader.nextint ();

int y = Reader.nextint ();

System.out.println ("Please enter the symbol for the operation performed");

String C = Reader.next ();

char a = C.charat (0);

Switch (a)

{

Case ' + ':

System.out.println (X+y);

Break

Case '-':

System.out.println (x-y);

Break

Case ' * ':

System.out.println (X*y);

Break

Case '/':

if (y!=0)

{System.out.println (x/y);}

Else

{System.out.println ("Invalid input data"); }

Break

Default

{System.out.println ("the input symbol is not valid"); } break; }  }

}

Iv. Exercises Code and:

Experimental Content 1:

Experimental Content 2:

The code runs smoothly:

To run the result after inserting a breakpoint:

Experimental three results:

V. Problems encountered and Solutions

Problems encountered:

This experiment was my first exposure to eclipse programming software and was not adapted to its automatic popup function. Char type data cannot be received when writing keyboard revenue for the arithmetic symbol

Workaround:

The scanner is queried first, but there is no direct acceptance of the Char type function in scanner,

Later through the Internet query can only use string character strong method, the problem is resolved

Six, the experimental harvest

Through this experiment, I first contacted the Eclipse programming software, and learned how to use some of its basic functions, but the debugging program is still not skilled, and should be more practice in the future.

This test has been arithmetic writing exercises, although the topic is very elementary, the program has been successfully written out, but the heart is still left with regret, because the operation always requires two data and a symbol, I think you can through the class of automatic filtering function, to complete the switch work, Also greatly simplifies the complexity of the main function to improve the ductility of the program, I hope that in the future can write out the ideal program in mind.

Java Lab Report-20135111 Li Guangji

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.