Java First Experiment

Source: Internet
Author: User

Beijing Institute of Electronic Technology (BESTI)

Real Inspection report

Course: Java Programming Class: 1353 Name: Chen Shi No.: 20135224

Score: Instructor: Lou Jia Peng Experimental Date: 2015.4.16

Experiment level: Preview degree: Experiment time:

Instrument Group: Compulsory/elective: experimental serial number:

Lab Name: familiarity with the Java development environment

Experimental objectives and requirements: experimental content

1. Compile and run a simple Java program using the JDK;

2. Edit, compile, run, and debug Java programs using Eclipse. Experimental requirements 1. Students who do not have a Linux base are advised to start with the Linux basics (new version) Vim Editor course;

3. 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, encounter problem (tool find, install, use, program edit, Debug, run, etc.), solution (empty method such as "Check Network", "Ask classmate", "read book" Equal to 0 points) and analysis (from which can get what revelation, what harvest, lessons, etc.);

4. The report of the experiment to count their own PSP;

Experimental instrument:

Name

Model

Number

Pc

Sony

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 Sy STEM.OUT.PRINTLN (sum); 8 9 sum = 0; Ten for (i=0; i<; i++) sum + = i; SYSTEM.OUT.PRINTLN (sum); + public static int Add (int augend, int addend) {n int sum = 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"

Package shiyan1;

Import Java.util.Scanner;

public class Shiyan1

{

public static void Main (string[] args)

{

Scanner input=new Scanner (system.in);

SYSTEM.OUT.PRINTLN ("Input data:");

int N=input.nextint ();

System.out.print ("2");

for (int i=2;i<n;i++)

{

for (int j=2;j<=i/2;j++)

{

if (i%j==0) break;

else if (I%J!=0&&J==I/2) System.out.print (i+ "");

else continue;

}

}

}

}

"Experimental Results"

Psp

Steps

Take

Percentage

Demand analysis

10%

Design

20%

Code implementation

60g

Test

30%

Analysis Summary

This problem is relatively simple, can be done through a nested loop, the structure and design of the basic no problem, but some statements, such as input statements, the keyboard scanning class, such as the establishment of the Internet CA

"Problems and analyses encountered"

Basically there is not too much problem, the problem is mainly from the take over the loop, such as the previous

Java First Experiment

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.