First Java Lab report

Source: Internet
Author: User

Beijing Institute of Electronic Technology (besti)

Actual Inspection report

Course:Java Programming class:1353 name: Bérénice Angremy No.:5338

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 Course;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 your classmates","Reading"and so on.0) 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) Java program Development under command line

  1. First, double-click the Xface terminal icon on the desktop, as shown in:// I'm using cmd here.
  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 experiment directory , Note that the directory name must be their 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 Create the first experiment directory, and then enter the CD EXP1 Enter The experiment directory and you can enter pwd command to view the current working path as shown in:
  6. Enter gedit hello.java ( Note Save the code to exp1 ) or vim hello.java vim ) Edit hello.java,

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

(ii) development and commissioning of Java programs underEclipse

  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. Enter the package name according to the Java Code specification LJP(lowercase, can be customized), class name hellojdb (capitalize the first letter of the word) , and tick the automatically generated Main function Options, and then click 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;
    10 for (i=0; i< 100; i++)
    11 sum += i;

    13 system.out.println (sum);
    14 }

    16 public static int add (int augend, int addend) {
    17  int sum = augend + addend;
    18 return sum;
    19 }
    }
  7. Click the Run button(or use the ctrl+f11 shortcut key)to see theresults 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. It is easier to set breakpoints, and then click the Debug button (or useF11shortcut keys) Start DebuggingJavaProgram , we can see that the program stays in the first4Note that at this point4The line code is not executed and we canPut the mouse on the variable name to see the value of the variable, at which pointIThe value is not5, we let the program run through a single-step operation to5Yes, there are two ways to run a single step:Step into (QuickF5)and step Over(Fast CzechF5), these two single-step runs have no difference when running statements, and when executing a function call statement,Step intowill jump into the function implementation,Step overwill execute the function directly, in actual use we prefer to useStep over, only the function execution error, stating that the program problem in the called function, then back throughStep intoEnter the function to debug. Let's clickStep overicons(orF6), the program stops at the first5line, then look at the variableIthe value that you seeIequals5.

10. 1 stepping efficiency is slower if we feel the first 6 line to section 10 There's no problem with the code, you want the program to run directly to section . 11 > Okay, what do you do? First we want to 11 line set breakpoints, and then click Span style= "Font-family:verdana;" >resume icon ( accelerator f8) 11 line

One step execution efficiency is slow also lead to another problem, such as a cycle in the middle of a problem? You can then resolve the issue through conditional breakpoints. When debugging a 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 are paying attention to sum at this time , and each step can see the sum and set the conditional breakpoint, we One Right-click on the left side of the line and select Breakpoint Properties ...

"Experimental Results"

Steps

Take

Percentage

Demand analysis

20%

Design

30%

Code implementation

40%

Test

10%

Analysis Summary

3.JAVA experiment one implements arithmetic and tests the code:

Import Java.text.DecimalFormat;
Import Java.util.Scanner;

public class Zhidao {

public static void Main (string[] args) {
String condition = "";
Zhidao Zhidao = new Zhidao ();
do{
Scanner Scanner = new Scanner (system.in);
try{
System.out.print ("Please enter the first number:");
Double x = scanner.nextdouble ();
System.out.print ("Please enter a second number:");
Double y = scanner.nextdouble ();
System.out.print ("Please enter operator:");
String s = scanner.next ();
Char z = s.charat (0);
Zhidao.yunsuan (x, y, z);
}catch (Exception e) {
System.out.println ("Please enter the correct data!") ");
}
System.out.print ("Do you want to continue?" Continue: Continue, any character: End ");
Condition = Scanner.next ();

}while ("Continue". Equals (condition));
}

public static void Yunsuan (double x,double y,character z) {
DecimalFormat r=new DecimalFormat ();
R.applypattern ("#0.00");
if (z.equals (' + ')) {
System.out.println (x+ "+" +y+ "=" + R.format ((x+y)));
} else if (Z.equals ('-')}) {
System.out.println (x+ "-" +y+ "=" + R.format (x-y));
} else if (z.equals (' * ')) {
SYSTEM.OUT.PRINTLN (x+ "*" +y+ "=" + R.format ((x*y)));
} else if (z.equals ('/')) {
if (y==0) {
SYSTEM.OUT.PRINTLN ("Dividend cannot be 0");
} else{
System.out.println (x+ "/" +y+ "=" + R.format (x/y));
}

}else{
System.out.println ("Unrecognized modifier operator");
}
}

}

Five Run Tests

Six Experiment Experience

There was no way to get into the lab building, so I used Windows to do it. The experimental content is not difficult, but it takes a step-by-step. The final experiment three is also relatively simple.

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.