Experimental Requirements:
1. Compiling and running a simple Java program using the JDK
2. Edit, compile, run, and debug Java programs using Eclipse
Experimental content:
1. Java program Development under command line
2.Eclipse Java program Development, debugging
3. Practice (implemented via command line and Eclipse two, practice debugging under Eclipse)
4. Implement the Arithmetic and test
Experimental process:
Experiment One: Java program development under command line
Open the command line through the Xface software by running the window, via the command line, by gedit the file name. java, or vim file name. Java, into the Java program's codec interface.
After writing the code saved, pass the javac-d. File name. java compiler program. Enter Java Scn.hello to run the compiled program.
Package LJP;
Import Java.util.Scanner;
public class Hello
{
public static void Main (string[] args)
{
System.out.println ("Input your first name, please:");
Scanner s = new Scanner (system.in);
String name = S.next ();
System.out.println ("Hello" + name + "!");
}
}
Experiment Two: Java Program development and debugging under Eclipse
Programming with Eclipse. Note To save the established class to the package folder. Write the development process. Focus on debugging the program, click Window->Open Perspective->Debug
Open Debug View.
Set breakpoints, and in front of where you want to set breakpoints, double-click the section that precedes the number of rows to set breakpoints quickly.
debugging shortcut keys are F11, single-step debugging, enter the function shortcut key is F5, do not enter the function shortcut key F6, general debugging do not enter the function, when the function problem, then enter the function.
To debug at a specified location, use the Resume function of the shortcut key for F8.
You can view the value of a variable at this time by moving the mouse over the variable.
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;
}
}
Experiment three: Implement arithmetic, and test.
Import java.util.*;
public class size
{
public static void Main (string[] args)
{
Size T = new size ();
T.HJ ();
}
Scanner Scan;
public void HJ ()
{
while (true)
{
Scan = new Scanner (system.in);
System.out.print ("Please enter the first value of the operation:");
Double A = scan.nextdouble ();
System.out.print ("Please enter an operator:");
Char B = scan.next (). charAt (0);
System.out.print ("Please enter a second value for the operation:");
Double c = scan.nextdouble ();
Double sum=0;
Switch (b)
{
Case ' + ':
Sum=a+c;
Break
Case '-':
Sum=a-c;
Break
Case ' * ':
Sum=a*c;
Break
Case '/':
SUM=A/C;
Break
Default
System.out.println ("Please enter the correct operator!") ");
Break
}
SYSTEM.OUT.PRINTLN (sum);
}
}
}
Operation diagram:
Steps |
Take |
Percentage |
Demand analysis |
10min |
8.33% |
Design |
20min |
16.66% |
Code implementation |
60min |
50% |
Test |
10min |
8.33% |
Analysis Summary |
20min |
16.66% |
The problems and solutions encountered in the experiment.
1, the experiment once the code is written, display a large string of code and do not have the correct format for me to enter the next step of the code.
WORKAROUND: Re-open the Xface interface and go directly to the folder to run the file as well.
2. Copy the code problem.
WORKAROUND: You need to copy and paste through the Clipboard at the top of the interface.
Experimental Harvest
Through this experiment, I learned a lot of Java knowledge has not yet learned, and in looking at all kinds of examples on the Internet and constantly modifying the practice of the general learned how to use. At the same time also found that programming is really a very advanced knowledge, even some of the basic problems to our current level can also make us very headache, from this experiment I feel the fun of learning Java, and hope to learn better later, I will pay the effort, I hope to make more interesting things!
Java Lab report One: Familiarity with the Java development environment