Java Programming Experiment One

Source: Internet
Author: User

Beijing Institute of Electronic Technology (BESTI)

Real Inspection report

Course: Java Programming Class: 1353 Name: Li Haiyin No.: 20135329

Score: Instructor: Lou Jia Peng Experimental Date: 2015.4.14

Experiment level: Preview degree: Experiment time:

Instrument Group: Compulsory/elective: experimental serial number:

Lab Name: familiarity with the Java development environment

Experimental purposes and requirements: experimental content 1. Use JDK compile, run simple Java procedures;

2.UseEclipseedit, compile, run, debugJavaprogram. Experimental requirements1.NoLinuxThe basic students recommend that you first learn theLinuxBasic Primer (New edition) "VimEditor "courses;2.complete the experiment, write the experiment Report, the Experiment report template seeQQGroup, note that the experimental report focuses on the results of the operation, problems encountered(tool Finder, installation, use, program editing, commissioning, running, etc.), solutions (empty methods such as "Check the network", "Ask classmates", "reading" and so on are0) and analysis (from which you can get what revelation, what harvest, lessons, etc.);3.the report of the experiment to count their ownPSP

Experimental instrument:

Name

Model

Number

Pc

1

Experiment contents, steps and experiences (attached paper):

"Experimental Steps"

(i) under the command line Java Program Development

    1. First double-click the Xface terminal icon on the desktop, as shown in:
    2. Open the terminal (like cmd under Windows) and then run the shell program automatically, as shown in:
    3. Enter the CD code command into the code (note C to capitalize) directory, as shown in:
    4. Enter mkdir 20135100 command to set up 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. As shown in the following:
    5. Enter the CD 20135100 command into the experiment directory, enter a similar mkdir EXP1 to create the first experiment directory, and then enter the CD EXP1 into the experiment directory, you can enter the PWD command to view the current working path, as shown in:
    6. Enter Gedit Hello.java ( note Save the code in the exp1 directory ) or Vim Hello.java (it is recommended that you take some time to learn vim) edit Hello.java, and enter the following code:

Notice the first line of the code, which affects how we compile the code using javac .
Note in the second line of code, when we use the class in the Java class Library to import the related classes with import (you can temporarily understand the features of the Include in C), the import path can view the JDK Help documentation, for example, we used the scanner class

"Experimental Results"

(ii) Eclipse under Java program development, commissioning

  1. Enter the eclipse command on the command line and enter 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, as shown in:
  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. According to the Java Code specification, enter the package name LJP (lowercase, can be customized), the class name Hellojdb (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:
    ```
    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 System.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) {
    sum int = augend + addend;
    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
  8. Here we practice the debugger, first we open the Debug view by clicking Window->open perspective->debug
  9. The debugger first sets breakpoints and runs in one step . Setting a breakpoint is simple, and then clicking the Debug button (or using the F11 shortcut) to start debugging the Java program, we can see that the program stays on line 4th 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, and we run the program to line 5th with one-step operation: Step Into( quick F5) and stepover(Fast F5 ), there is no difference between the two single-step run functions, when executing a function call statement, the step into will jump into the function implementation, step over will directly execute the function, in practice we prefer to use Step over, only function execution error, Explain the program problem in the called function, and then come back through the step into enter the function to debug. We click the Step over icon (or F6) and the program stops at line 5th, when I see the value of the variable i, I see I equals 5.

10.1 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 a breakpoint on line 11th and then click the Resume icon (shortcut F8) and the program runs to line 11th

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, set the conditional breakpoint, We right-click on the left of line 11th and select Breakpoint Properties ...

"Experimental Results"

(iii) exercise (via command line and Eclipse two ways to achieve, the number of their own after the two and the total number of questions to take the results of the remainder plus 1 is the number of the problem you want to complete, Eclipse the next exercise to debug the program)

5. realize the function of all prime numbers between the 1-n integers and test them.

"Experimental Code"

import Java.util.Scanner;

Public class Test_1_3

{

Public Static void Main (string[] args)

{

Scanner Sole = new Scanner (System. in);

int n1=0;

int n2 = 0;

System. out. println ("Please enter a 1th integer.");

N1 = Sole.nextint ();

System. out. println ("Please enter a 2nd integer.");

N2 = Sole.nextint ();

if (N1>N2)

{

N1=N1^N2;

N2=N1^N2;

N1=N1^N2;

}

int sum = 0;

for (int i = n1; i<=n2; i++)

{

if (f(i)!=0)

{

System. out. println (i);

sum = sum+1;

}

}

System. out. println ("sum=" +sum);

}

Public Final Static int f (int N)

{

if (n<1)

{

return 0;

}

int temp = (int) Math. sqrt (n);

int i=2;

for (; i<=temp;i++)

{

if (n%i==0)

{

break;

}

}

if (i-1==temp)

{

return N;

}

return 0;

}

}

"Experimental Results"

Psp

Steps

Take

Percentage

Demand analysis

20%

Design

30%

Code implementation

60g

Test

10%

Analysis Summary

Analysis Summary: The above code is not completely independent of the completion, draw on some network code, on the basis of reading code, the code made some changes. For example, the output format is more beautiful, adding the function of statistical number of numbers.

"Problems and analyses encountered"

In the second part of the experiment, there was a "unreachable code" error at compile time, and after searching the web, I learned that the statement was not executed, according to debug, because the condition in the For loop was written incorrectly. You know, this is a common error in a looping statement.

Java Programming Experiment One

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.